* 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);