public void addForwardReferences() { KnowledgeBase kb = this.getKnowledgeBase(); Collection transitions = getOwnSlotValues(kb.getSlot("transitions")); Slot fromSlot = kb.getSlot(":FROM"); Slot toSlot = kb.getSlot(":TO"); Instance from = null; Instance to = null; Slot branches = kb.getSlot("branches"); Slot followed_by = kb.getSlot("followed_by"); Slot label = kb.getSlot("label"); for (Iterator transition = transitions.iterator(); transition.hasNext(); ) { Instance inst = (Instance) transition.next(); from = (Instance) inst.getOwnSlotValue(fromSlot); if (from != null) { to = (Instance) inst.getOwnSlotValue(toSlot); if (to != null) { try { if (from.hasOwnSlot(branches)) { /*logger.debug("addForwardReferences: "+ from.getOwnSlotValue(label)+ " has branches"); */ if ((from.getOwnSlotValues(branches) == null) || (!from.getOwnSlotValues(branches).contains(to))) from.addOwnSlotValue(branches, to); } else if (from.hasOwnSlot(followed_by)) { /*logger.debug("addForwardReferences: "+ from.getOwnSlotValue(label)+ " has followed by");*/ if (!(to.equals(from.getOwnSlotValue(followed_by)))) from.setOwnSlotValue(followed_by, to); } else logger.error( "addForwardReferences: " + from.getOwnSlotValue(label) + "has no followed_by or branches slot"); } catch (Exception e) { logger.error( "Exception adding " + to.getOwnSlotValue(label) + " to " + from.getOwnSlotValue(label)); } } } } }
private void loadKB(String kbURL, String guidelineId) { System.out.println("Starting to load KB"); System.out.println("------------------------------------------------------------------"); try { PCAImp = new PCAServer_i(); PCAImp.kbManager = new KBHandler(kbURL); // Sever loads the KB // java.util.Date finishedKB = new java.util.Date(); // logger.warn("finished loading KB "+(finishedKB.getTime() - startTime.getTime())+ " // milliseconds after start."); pca = PCAImp.open_pca_session(); if ((guidelineId != null) && (guidelineId != "")) { pca.setGuideline(guidelineId); // Specifies the guideline to use } else logger.error("No GUIDELINEID specified"); } catch (Exception se) { logger.error("Exception raised during initialization " + se.toString()); System.exit(1); } pca.finishSession(); System.out.println("------------------------------------------------------------------"); System.out.println("Done loading KB"); }
public void removeForwardReferences() { KnowledgeBase kb = this.getKnowledgeBase(); Slot branches = kb.getSlot("branches"); Slot followed_by = kb.getSlot("followed_by"); // logger.debug("Slot "+branches.getName()); // logger.debug("Slot "+followed_by.getName()); Slot label = kb.getSlot("label"); Collection steps = getOwnSlotValues(kb.getSlot("steps")); for (Iterator iterater = steps.iterator(); iterater.hasNext(); ) { Instance step = (Instance) iterater.next(); // logger.debug("removeForwardReferences: node ="+step.getOwnSlotValue(label)); /*for (Iterator slots=step.getOwnSlots().iterator(); slots.hasNext();){ logger.debug("has slot "+((Slot)slots.next()).getName()); }*/ try { if (step.hasOwnSlot(branches)) { /*logger.debug("removeForwardReferences: "+ step.getOwnSlotValue(label)+ " has branches"); */ step.setOwnSlotValues(branches, new ArrayList()); } else if (step.hasOwnSlot(followed_by)) { /* logger.debug("removeForwardReferences: "+ step.getOwnSlotValue(label)+ " has followed_by value "+step.getOwnSlotValue(followed_by));*/ step.setOwnSlotValue(followed_by, null); } else logger.error( "removeForwardReferences: " + step.getOwnSlotValue(label) + "has no followed_by or branches slot"); } catch (Exception e) { logger.error( "Exception making " + step.getOwnSlotValue(label) + " null, Message: " + e.getMessage(), e); } } }
private static void processFile( String pid, File child, File outFilePath, String guidelineId, String htmlFilePath) { // Write to output directory // outFilePath should be path+pid+extension String caseData = null; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date startTime = new java.util.Date(); try { caseData = readFileAsString(child.getPath()); } catch (java.io.IOException e) { logger.error("Error reading data file ", e); System.exit(-1); } String recommendations = null; try { System.out.println("-----------------------------------------"); recommendations = pca.topLevelComputeAdvisory(pid, caseData, formatter.format(startTime), guidelineId, pid); System.out.println("-----------------------------------------"); // String fileName = outFilePath+pid+fileExtension // File outFilePath = new File(fileName);; logger.warn("Output recommenations to: " + outFilePath); if (outFilePath.exists()) { outFilePath.delete(); } try { PrintWriter out = new PrintWriter(outFilePath.getPath()); out.print(recommendations); out.flush(); // System.out.println("****READY FILE PROCESSING****"); // create Ready file // String readyFileName; // readyFileName = outFilePath.getPath(); // System.out.println("Ready File Name Is: " + readyFileName); //Remove // File readyFile = new File(readyFileName.replace(".xml","_READY.txt")); // try { // readyFile.createNewFile(); // System.out.println("****SUCCESS****"+readyFile.getPath()); // } catch (java.io.IOException e0) { // System.out.println("Error creating READY file"); // } } catch (FileNotFoundException e) { e.printStackTrace(); } } catch (PCA_Session_Exception e1) { e1.printStackTrace(); } }