Package unbbayes.io

Examples of unbbayes.io.BaseIO


    // change default locale
    Locale.setDefault(new Locale("en"));
    
    File ASIA_FILE = new File("src/test/resources/testCases/cpslTest.net");
    ProbabilisticNetwork net;
    BaseIO io = new NetIO();
      try {
        net = (ProbabilisticNetwork)io.load(ASIA_FILE);
        ProbabilisticNode n = (ProbabilisticNode)net.getNode("B");
        CPSController w = new CPSController( n );
      } catch (LoadException e) {
        e.printStackTrace();
      } catch (IOException e) {
View Full Code Here


   * It uses {@link TextModeRunner} to facilitate KB manipulation.
   */
  public final void testSaveMebnAndKB() {
   
    // To load/save a MTheory as a UBF/OWL with continuous nodes support, we must use this I/O class
    BaseIO io = ContinuousUBFIO.getInstance();
   
    File ubfFileToLoad = null;
    try {
      ubfFileToLoad = new File(this.getClass().getClassLoader().getResource("mebn/SimpleContinuousNodeSample.ubf").toURI());
    } catch (URISyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    assertNotNull(ubfFileToLoad);
   
    // load mebn
    MultiEntityBayesianNetwork mebn = null;
    try {
      // load file
      mebn = (MultiEntityBayesianNetwork) io.load(ubfFileToLoad);
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    assertNotNull(mebn);
   
    // file containing KB
    File plmFileToLoad = null;
    try {
      plmFileToLoad = new File(this.getClass().getClassLoader().getResource("mebn/SimpleContinuousNodeSample.plm").toURI());
    } catch (URISyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    assertNotNull(plmFileToLoad);
   
    // object to facilitate KB manipulation and query (but we are not going to use query)
    TextModeRunner textModeRunner = new TextModeRunner();
   
    // instantiate and setup knowledge base
    KnowledgeBase kb = textModeRunner.createKnowledgeBase(PowerLoomKB.getNewInstanceKB(), mebn);
   
    // load finding data from file and insert to KB
    try {
      // load findings from file
      kb.loadModule(plmFileToLoad, true);
      // fill mebn with findings
      textModeRunner.fillFindings(mebn, kb);
    } catch (UBIOException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
   
    // file to save KB (in the same folder of the loaded file)
    File newPLMFile = new File(plmFileToLoad.getParent(), "SavedContinuousNodeSample.plm");
   
    // save KB to new file
    textModeRunner.saveKnowledgeBase(newPLMFile, kb, mebn);
   
    // file to save MEBN (in the same folder of the loaded file)
    File newUBFFile = new File(ubfFileToLoad.getParent(), "SavedContinuousNodeSample.ubf");
   
    // save mebn to new file
    try {
      textModeRunner.saveMEBN(newUBFFile, io, mebn);
    } catch (IOException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
   
   
    // load new file (so that we can compare)
    MultiEntityBayesianNetwork mebnOfNewFile = null;
    try {
      mebnOfNewFile = (MultiEntityBayesianNetwork) io.load(newUBFFile);
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    assertNotNull(mebnOfNewFile);
View Full Code Here

TOP

Related Classes of unbbayes.io.BaseIO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.