swoopontologyinfo.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 936 行 · 第 1/3 页
JAVA
936 行
} } out.print("</td></tr"); } out.print("</table>"); } out.print("</FONT></body></html>"); return; } else { // in all other cases, print all unsatisfiable classes swoopModel.getOntStats(reasoner.getOntology()).put(SwoopStatistics.UNSATISFIABLE_CLASSES, unsat);// Iterator i = unsat.iterator();// while(i.hasNext()) {// OWLClass c = (OWLClass) i.next();// URI uri = c.getURI();// out.print("<a href=\"" + uri + "\">" + swoopModel.shortForm(uri) + "</a><br>"); // } } } } else { // inconsistent ontology out.print("<br><br>"); out.print("<font color=\"red\"><b>Inconsistent ontology</b></font><br>"); if(reasoner.supportsExplanation()) { // display explanation always Reasoner pelletDebug = new Reasoner(); pelletDebug.setOntology(swoopModel.getSelectedOntology()); pelletDebug.getKB().setDoExplanation(true); pelletDebug.getKB().doDependencyTracking = true; pelletDebug.isConsistent(); String explanation = ((PelletReasoner) reasoner).parseExplanation(swoopModel.getShortForms(), pelletDebug.getKB().getExplanation()); // display SOS if debugging option is enabled// if (swoopModel.isDebugGlass()) { ConciseFormatEntityRenderer cfRend = new ConciseFormatEntityRenderer(); cfRend.setSwoopModel(swoopModel); cfRend.setReasoner(swoopModel.getReasoner()); cfRend.visitor = cfRend.createVisitor(); List MUPS = new ArrayList(); List explStr = new ArrayList(); List firstExpl = cfRend.getTableauSOS(swoopModel.getSelectedOntology(), null); String firstExplStr = firstExpl.get(0).toString(); Set firstExplSet = (HashSet) firstExpl.get(1); MUPS.add(firstExplSet); explStr.add(firstExplStr); if (swoopModel.isFindAllMUPS()) { // use tableau method to find SOS of inconsistent ont // since black box soln is not coded yet boolean temp = swoopModel.isUseTableau(); swoopModel.useTableau = true; cfRend.HSTMUPS(firstExplSet, swoopModel.getSelectedOntology(), MUPS, explStr, new HashSet(), new HashSet()); swoopModel.useTableau = temp; } Object[] explObj = explStr.toArray(); int o = 0; HashMap explMap = new HashMap(); Set mupsSet = new HashSet(); for (Iterator iter = MUPS.iterator(); iter.hasNext();) { Set explSet = (HashSet) iter.next(); mupsSet.add(explSet); if (o<explObj.length && explObj[o]!=null) { String expl = explObj[o].toString(); explMap.put(explSet, expl); } o++; } for (Iterator iter = mupsSet.iterator(); iter.hasNext();) { Set explSet = (HashSet) iter.next(); StringWriter st = new StringWriter(); PrintWriter buffer = new PrintWriter(st); cfRend.setWriter(buffer); cfRend.printExplanationSOS(explSet, reasoner.getOntology().getOWLDataFactory().getOWLThing(), false); out.print("<font face=\"Verdana\" size=2>"); if (explMap.containsKey(explSet)) out.println(explMap.get(explSet).toString()); out.print(st.toString()); }// } } } } // show advanced stats showStatistics(ont, out);// System.out.println(statsText); } catch(OWLException ex) { System.out.println(ex.getMessage()); } out.print("</FONT></body></html>"); } protected String addTitle(String param) { String title = " (<font color=\"red\"><a href=\"<Add" + param + "\">Add</a></font>)"; return title; } public void setOptions(Map options) { } public Map getOptions() { return null; } public void setEditorEnabled(boolean mode) { this.editorEnabled = mode; } public boolean isEditableText() { return false; } /* * SwoopRenderer method * */ public Component getDisplayComponent( SwoopDisplayPanel panel ) { if (! (panel instanceof OntologyDisplay )) throw new IllegalArgumentException(); return super.getEditorPane( this.getContentType(), (OntologyDisplay)panel ); } /** * Code for rendering annotations same as in ConciseFormatEntityRenderer * @param obj * @return * @throws OWLException */ protected boolean renderAnnotations(OWLOntology obj) throws OWLException { boolean printed = false; if (!obj.getAnnotations().isEmpty()) { printed = true; out.print("<br>"); String annTitle = " <b>Annotations</b>:"; if (editorEnabled) annTitle += addTitle("O-ANN"); out.print(annTitle); out.print("<br>"); for (Iterator it = obj.getAnnotations().iterator(); it.hasNext();) { OWLAnnotationInstance oai = (OWLAnnotationInstance) it.next(); if (editorEnabled) { OntologyChange deleted = isDeleted(obj, oai.getProperty(), oai.getContent()); if (deleted!=null) { out.print("<font color=\"red\"><strike>"); out.print(" <b>" + swoopModel.shortForm(oai.getProperty().getURI()) + "</b> "); renderAnnotationContent(oai.getContent()); out.print("</strike></font>"); addUndo(deleted, "Delete"); } else { out.print(" <b>" + swoopModel.shortForm(oai.getProperty().getURI()) + "</b> "); renderAnnotationContent(oai.getContent()); addDelete(oai); } } else { out.print(" <b>" + swoopModel.shortForm(oai.getProperty().getURI()) + "</b> "); renderAnnotationContent(oai.getContent()); } out.print("<br>"); } } // print temporarily added changes if (editorEnabled) { Set added = this.getAddedAnnotations(obj); if (added.size()>0) { // print title if not printed already String annTitle = "<br> <b>Annotations</b>:"; annTitle += addTitle("O-ANN"); if (!printed) { out.print(annTitle); out.print("<br>"); printed = true; } // print added changes in green (and add undo links) for (Iterator iter = added.iterator(); iter.hasNext(); ) { AddAnnotationInstance change = (AddAnnotationInstance) iter.next(); out.print("<font color=\"green\">"); out.print(" " + swoopModel.shortForm(change.getProperty().getURI()) + " "); renderAnnotationContent(change.getContent()); out.print("</font>"); this.addUndo(change, "Add"); out.print("<br>"); } } } return printed; } private Set getAddedAnnotations(OWLObject subj) throws OWLException { Set added = new HashSet(); Iterator i = swoopModel.getUncommittedChanges().iterator(); while(i.hasNext()) { OntologyChange oc = (OntologyChange) i.next(); if (oc instanceof AddAnnotationInstance) { AddAnnotationInstance change = (AddAnnotationInstance) oc; if (change.getSubject().equals(subj)) added.add(oc); } } return added; } protected void addUndo(Object obj, String type) { String hash = String.valueOf(obj.hashCode()); OWLObjectHash.put(hash, obj); out.print(" (<font color=\"red\"><a href=\"<Undo:"+type+":"+hash+"\">Undo</a></font>)"); } protected void renderAnnotationContent(Object o) throws OWLException { if (o instanceof URI) { out.print(o.toString()); } else if (o instanceof OWLIndividual) { out.print(((OWLIndividual) o).getURI().toString()); } else { String content = o.toString(); if (o instanceof OWLDataValue) { OWLDataValue dv = (OWLDataValue) o; /* Only show it if it's not string */ URI dvdt = dv.getURI(); String dvlang = dv.getLang(); if (dvdt != null) { out.print("(Datatype " + dvdt + ") "); } else { if (dvlang != null && !dvlang.equals("")) { out.print("(" + dvlang + ") "); } } content = dv.getValue().toString(); }// print(escape(dv.getValue()));// } else { if (content.indexOf("html")>=0 && content.indexOf("body")>=0) { content = content.replaceAll("<", "<"); content = content.replaceAll(">", ">"); content = content.replaceAll("&", "&"); // remove <html><body> outer tags because it's being rendered inside a new html doc anyway int spos = content.indexOf("<body>")+6; int epos = content.indexOf("</body>"); content = content.substring(spos, epos); if (content.trim().indexOf("<p")>=0) { content = content.substring(content.indexOf(">")+1, content.length()); } content += " (**Stripped HTML tags**)"; } // System.out.println(content); out.print(" : "+content); } } /** * Check if a RemoveAnnotationInstance change is in swoopModel uncommitted changes * that matches the subj, predicate and content arguments passed * @param subj * @param prop * @param content * @return */ private OntologyChange isDeleted(OWLObject subj, OWLAnnotationProperty prop, Object content) { OntologyChange deleted = null; Iterator i = swoopModel.getUncommittedChanges().iterator(); while(i.hasNext()) { OntologyChange oc = (OntologyChange) i.next(); if(oc instanceof RemoveAnnotationInstance) { RemoveAnnotationInstance change = (RemoveAnnotationInstance) oc; if (change.getSubject().equals(subj) && change.getProperty().equals(prop) && change.getContent().equals(content)) deleted = oc; } } return deleted; } protected void addDelete(Object obj) { String hash = String.valueOf(obj.hashCode()); OWLObjectHash.put(hash, obj); out.print(" (<font color=\"red\"><a href=\"<DeleteO-ANN:"+hash+"\">Delete</a></font>)"); } protected Set unfoldSet(Set set) { Set unfold = new HashSet(); for (Iterator iter = set.iterator(); iter.hasNext();) { Object obj = iter.next(); if (obj instanceof Set) unfold.addAll(unfoldSet((Set) obj)); else if (obj instanceof OWLEntity) unfold.add(obj); else if (obj instanceof String) unfold.add(obj); } return unfold; } private String insFont() { return("<FONT FACE=\""+swoopModel.getFontFace()+"\" SIZE="+swoopModel.getFontSize()+">"); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?