abstractsyntaxentityrenderer.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,981 行 · 第 1/5 页
JAVA
1,981 行
// println(); // } } for (Iterator it = reasoner.rangesOf(prop).iterator(); it.hasNext();) { println(); OWLDataRange ran = (OWLDataRange) it.next(); visitor.reset(); ran.accept(visitor); print(TAB + "range(" + visitor.result() + ")"); } if (swoopModel.getEnableRules()) { Set rules = swoopModel.getRuleExpr().getRules(prop); for (Iterator it = rules.iterator(); it.hasNext();) { OWLRule rule = ((RuleValue) it.next()).getRule(); println("\n \t" + "Implies(" + "Antecedent("); Set antecedents = rule.getAntecedents(); for (Iterator it1 = antecedents.iterator(); it1.hasNext();) { OWLRuleAtom antAtom = (OWLRuleAtom) it1.next(); renderAtom(antAtom); // visitor.reset(); // antAtom.accept((OWLRuleAtomVisitor) visitor); // print(" "+visitor.result()); } println(")"); println("\t" + "Consequent("); OWLRuleAtom consAtom = (OWLRuleAtom) rule.getConsequents() .iterator().next(); //visitor.reset(); //consAtom.accept((OWLRuleAtomVisitor) visitor); //print(" "+visitor.result()); renderAtom(consAtom); println(")"); println(")"); } } println("\n)"); } protected void renderDataType(OWLDataType datatype) throws OWLException { if (editorEnabled) println("Datatype(" + shortForm(datatype.getURI()) + ")"); else println("<b>Datatype</b>(" + escape(shortForm(datatype.getURI())) + ")"); } //************************************************************ //Added for Econnections //************************************************************ protected void renderForeignEntity(OWLEntity ent) throws OWLException { if(ent instanceof OWLObjectProperty ){ if(!((OWLObjectProperty)ent).isLink()) println("<b>ForeignObjectProperty</b>(" + escape(shortForm(ent.getURI())) + ")"); else println("<b>ForeignLinkProperty</b>(" + escape(shortForm(ent.getURI())) + ")"); } if(ent instanceof OWLDataProperty ) println("<b>ForeignDatatypeProperty</b>(" + escape(shortForm(ent.getURI())) + ")"); if(ent instanceof OWLClass ) println("<b>ForeignClass</b>(" + escape(shortForm(ent.getURI()))+ ")"); if(ent instanceof OWLIndividual ) println("<b>ForeignIndividual</b>(" + escape(shortForm(ent.getURI())) + ")"); pw.print(" foreignOntology(" + escape(shortForm(((URI)swoopModel.getSelectedOntology().getForeignEntities().get(ent)))) + ")"); } //************************************************************* protected void println() { pw.println(); } protected void renderEntity() throws OWLException { if (!editorEnabled) { print("<html><body style='color: black; background-color: white;'>"); print("<code><pre><FONT FACE=\""+swoopModel.getFontFace()+"\" SIZE="+fontSize+">"); } // generateShortNames(); this.baseURI = swoopModel.getSelectedOntology().getURI().toString(); this.allURIs = getAllURIs(reasoner.getOntology()); StringWriter sw = new StringWriter(); PrintWriter buffer = new PrintWriter(sw); this.qnameProvider = new QNameShortFormProvider(); generateShortNames(); writeHeader(); super.renderEntity(); writeFooter(); if (!editorEnabled) print("</FONT></pre></code></body></html>"); } protected void renderAtom(OWLRuleAtom atom) throws OWLException { String result = ""; try { if (atom instanceof OWLRuleClassAtom) { OWLDescription desc = ((OWLRuleClassAtom) atom) .getDescription(); URI aux = ((OWLClass) desc).getURI(); result = result = result.concat("\t" + "<a href=\"" + aux + "\">" + shortForm(aux) + "</a>" + "("); OWLRuleIObject var = ((OWLRuleClassAtom) atom).getArgument(); if (var instanceof OWLRuleIVariable) { URI aux1 = ((OWLRuleIVariable) var).getURI(); result = result.concat(" I-variable(" + shortForm(aux1) + ")" + ")"); } else { URI aux1 = ((OWLNamedObject) ((OWLRuleIndividual) var) .getIndividual()).getURI(); result = result.concat(" <a href=\"" + aux1 + "\">" + shortForm(aux1) + "</a>" + ")"); } } if (atom instanceof OWLRuleObjectPropertyAtom) { OWLObjectProperty prop = ((OWLRuleObjectPropertyAtom) atom) .getProperty(); URI aux = prop.getURI(); result = result.concat("\t" + "<a href=\"" + aux + "\">" + shortForm(aux) + "</a>" + "("); OWLRuleIObject var = ((OWLRuleObjectPropertyAtom) atom) .getFirstArgument(); if (var instanceof OWLRuleIVariable) { URI aux1 = ((OWLRuleIVariable) var).getURI(); result = result.concat(" I-variable(" + shortForm(aux1) + ")" + ")"); } else { URI aux1 = ((OWLNamedObject) ((OWLRuleIndividual) var) .getIndividual()).getURI(); result = result.concat(" <a href=\"" + aux1 + "\">" + shortForm(aux1) + "</a>" + ")"); } OWLRuleIObject var2 = ((OWLRuleObjectPropertyAtom) atom) .getSecondArgument(); if (var2 instanceof OWLRuleIVariable) { URI aux1 = ((OWLRuleIVariable) var2).getURI(); result = result.concat(" I-variable(" + shortForm(aux1) + ")" + ")"); } else { URI aux1 = ((OWLNamedObject) ((OWLRuleIndividual) var2) .getIndividual()).getURI(); result = result.concat(" <a href=\"" + aux1 + "\">" + shortForm(aux1) + "</a>" + ")"); } } if (atom instanceof OWLRuleDataPropertyAtom) { OWLDataProperty prop = ((OWLRuleDataPropertyAtom) atom) .getProperty(); URI aux = prop.getURI(); result = result.concat("\t" + "<a href=\"" + aux + "\">" + shortForm(aux) + "</a>" + "("); OWLRuleDObject var = (OWLRuleDObject) ((OWLRuleDataPropertyAtom) atom) .getFirstArgument(); if (var instanceof OWLRuleDVariable) { URI aux1 = ((OWLRuleIVariable) var).getURI(); result = result.concat("I-variable(" + shortForm(aux1) + ")" + ")"); } else { URI aux1 = ((OWLNamedObject) ((OWLRuleIndividual) var) .getIndividual()).getURI(); result = result.concat(" <a href=\"" + aux1 + "\">" + shortForm(aux1) + "</a>" + ")"); } OWLRuleDObject var2 = ((OWLRuleDataPropertyAtom) atom) .getSecondArgument(); if (var2 instanceof OWLRuleIVariable) { URI aux1 = ((OWLRuleIVariable) var2).getURI(); result = result.concat(" D-variable(" + shortForm(aux1) + ")" + ")"); } else { String aux1 = ((OWLRuleDataValue) var).toString(); result = result.concat(" " + aux1 + ")"); } } if (atom instanceof OWLRuleEqualityAtom) { result = result.concat("\t" + "sameAs" + "("); OWLRuleIObject var = ((OWLRuleObjectPropertyAtom) atom) .getFirstArgument(); if (var instanceof OWLRuleIVariable) { URI aux1 = ((OWLRuleIVariable) var).getURI(); result = result.concat(" I-variable(" + shortForm(aux1) + ")" + ")"); } else { URI aux1 = ((OWLNamedObject) ((OWLRuleIndividual) var) .getIndividual()).getURI(); result = result.concat(" <a href=\"" + aux1 + "\">" + shortForm(aux1) + "</a>" + ")"); } OWLRuleIObject var2 = ((OWLRuleObjectPropertyAtom) atom) .getSecondArgument(); if (var2 instanceof OWLRuleIVariable) { URI aux1 = ((OWLRuleIVariable) var2).getURI(); result = result.concat(" I-variable(" + shortForm(aux1) + ")" + ")"); } else { URI aux1 = ((OWLNamedObject) ((OWLRuleIndividual) var2) .getIndividual()).getURI(); result = result.concat(" <a href=\"" + aux1 + "\">" + shortForm(aux1) + "</a>" + ")"); } } if (atom instanceof OWLRuleInequalityAtom) { result = result.concat("\t" + "differentAs" + "("); OWLRuleIObject var = ((OWLRuleObjectPropertyAtom) atom) .getFirstArgument(); if (var instanceof OWLRuleIVariable) { URI aux1 = ((OWLRuleIVariable) var).getURI(); result = result.concat(" I-variable(" + shortForm(aux1) + ")" + ")"); } else { URI aux1 = ((OWLNamedObject) ((OWLRuleIndividual) var) .getIndividual()).getURI(); result = result.concat(" <a href=\"" + aux1 + "\">" + shortForm(aux1) + "</a>" + ")"); } OWLRuleIObject var2 = ((OWLRuleObjectPropertyAtom) atom) .getSecondArgument(); if (var2 instanceof OWLRuleIVariable) { URI aux1 = ((OWLRuleIVariable) var2).getURI(); result = result.concat(" I-variable(" + shortForm(aux1) + ")" + ")"); } else { URI aux1 = ((OWLNamedObject) ((OWLRuleIndividual) var2) .getIndividual()).getURI(); result = result.concat(" <a href=\"" + aux1 + "\">" + shortForm(aux1) + "</a>" + ")"); } } print(result + "\n"); } catch (Exception e) { e.printStackTrace(); } } protected void generateShortNames() { /* Generates a list of namespaces. */ for (Iterator it = allURIs.iterator(); it.hasNext();) { URI uri = (URI) it.next(); String qname = qnameProvider.shortForm(uri, false); } } protected void writeHeader() { // System names for (Iterator it = qnameProvider.getPrefixSet().iterator(); it.hasNext();) { String prefix = (String) it.next(); String ns = qnameProvider.getURI(prefix); if (editorEnabled) pw.println("Namespace(" + prefix + " = <" + ns + ">)"); else pw.println("Namespace(" + escape(prefix) + " = <" + escape(ns) + ">)"); } pw.println(); if (editorEnabled) pw.println("Ontology( <" + baseURI + ">"); else pw.println("Ontology( <" + escape(baseURI) + ">"); } protected void writeTextHeader() { // System names for (Iterator it = qnameProvider.getPrefixSet().iterator(); it.hasNext();) { String prefix = (String) it.next(); String ns = qnameProvider.getURI(prefix); pw.println("Namespace(" + prefix + " = <" + ns + ">)"); } pw.println(); pw.println("Ontology( <" + baseURI + ">"); } /** Returns all the uris of all the entities in the ontology. */ public static Set getAllURIs( OWLOntology ontology ) throws OWLException { Set allURIs = new HashSet(); for ( Iterator cit = ontology.getClasses().iterator(); cit.hasNext(); ) { OWLNamedObject entity = (OWLNamedObject) cit.next(); allURIs.add(entity.getURI()); } for ( Iterator cit = ontology.getIndividuals().iterator(); cit.hasNext(); ) { OWLIndividual entity = (OWLIndividual) cit.next(); if ( !entity.isAnonymous() ) { allURIs.add(entity.getURI()); } } for ( Iterator cit = ontology.getObjectProperties().iterator(); cit.hasNext(); ) { OWLNamedObject entity = (OWLNamedObject) cit.next(); allURIs.add(entity.getURI()); } for ( Iterator cit = ontology.getDataProperties().iterator(); cit.hasNext(); ) { OWLNamedObject entity = (OWLNamedObject) cit.next(); allURIs.add(entity.getURI()); } for ( Iterator cit = ontology.getDatatypes().iterator(); cit.hasNext(); ) { OWLDataType entity = (OWLDataType) cit.next(); allURIs.add(entity.getURI()); } for ( Iterator cit = ontology.getAnnotationProperties().iterator(); cit.hasNext(); ) { OWLAnnotationProperty entity = (OWLAnnotationProperty) cit.next(); allURIs.add(entity.getURI()); } return allURIs; } public String shortForm(URI uri) { String qname = uri.toString(); try { qname = qnameProvider.shortForm(uri, false); } catch (Exception ex) { ex.printStackTrace(); } return qname; } protected void writeFooter() { pw.println(")"); } /* * SwoopRenderer method * */ public Component getDisplayComponent( SwoopDisplayPanel panel ) { if (!(panel instanceof TermsDisplay )) throw new IllegalArgumentException(); if (!editorEnabled) { // return standard JEditorPane return super.getEditorPane( this.getContentType(), (TermsDisplay)panel ); } else { JEditorPane editorPane = null; if(contentType.equals("text/plain")) { editorPane = new JEditorPane(); editorPane.setFont(new Font("Verdana", Font.PLAIN, 12)); } else if(contentType.equals("text/html")) { editorPane = new JEditorPane(); editorPane.addHyperlinkListener( (TermsDisplay)panel ); } else if(contentType.equals("text/xml")) editorPane = new JEditorPane(); else throw new RuntimeException("Cannot create an editor pane for content type " + contentType); editorPane.setEditable(true); editorPane.setContentType(contentType); // adding to UI listeners of TermsDisplay editorPane.getDocument().addDocumentListener((TermsDisplay)panel); editorPane.addMouseListener((TermsDisplay)panel); editorPane.addKeyListener((TermsDisplay)panel); return editorPane; } } public boolean isEditableText() { if (contentType.equals("text/html")) return true; else return false; } public void decreaseINDENT() { INDENT = INDENT.substring(0, INDENT.length() - TAB.length()); } public void increaseINDENT() { INDENT = INDENT + TAB; } public void setNoLinks(boolean noLinks) { ((AbstractSyntaxVisitor) visitor).noLinks = noLinks; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?