abstractsyntaxentityrenderer.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,981 行 · 第 1/5 页
JAVA
1,981 行
visitor.reset(); oai.accept(visitor); // if (it.hasNext()) { // println(); // } } } } protected void renderClass(OWLClass clazz) throws OWLException { boolean done = false; String deprecation = (clazz.isDeprecated(reasoner.getOntology()) ? " Deprecated" : ""); if(!clazz.getAnnotations(reasoner.getOntology()).isEmpty()) { if (editorEnabled) { println( "Class (" + shortForm(clazz.getURI()) + deprecation + " partial"); } else { println( "<b>Class </b>(" + escape(shortForm(clazz.getURI())) + deprecation + " <i>partial</i>"); } renderAnnotations(clazz); println("\n)"); } for (Iterator it = clazz.getEquivalentClasses(reasoner.getOntologies()).iterator(); it.hasNext();) { OWLDescription eq = (OWLDescription) it.next(); if (editorEnabled) { println( "Class(" + shortForm(clazz.getURI()) + deprecation + " complete "); } else { println( "<b>Class </b>(" + escape(shortForm(clazz.getURI())) + deprecation + " <i>complete</i> "); } visitor.reset(); increaseINDENT(); eq.accept(visitor); println(visitor.result() + "\n)"); decreaseINDENT(); done = true; } if (!clazz.getSuperClasses(reasoner.getOntologies()).isEmpty()) { if (editorEnabled) { println( "Class (" + shortForm(clazz.getURI()) + deprecation + " partial "); } else { println( "<b>Class </b>(" + escape(shortForm(clazz.getURI())) + deprecation + " <i>partial</i> "); } for (Iterator it = clazz.getSuperClasses(reasoner.getOntologies()).iterator(); it.hasNext();) { OWLDescription eq = (OWLDescription) it.next(); visitor.reset(); increaseINDENT(); eq.accept(visitor); print(visitor.result()); decreaseINDENT(); if (it.hasNext()) { println(); } done = true; } println("\n)"); } /* * This has changed -- used to be simply a oneof in the class definition. We now get a * special keyword in the vocabulary */ for (Iterator it = clazz.getEnumerations(reasoner.getOntologies()).iterator(); it.hasNext();) { OWLDescription eq = (OWLDescription) it.next(); if (editorEnabled) { print("EnumeratedClass(" + shortForm(clazz.getURI()) + deprecation); } else { print( "<b>EnumeratedClass</b>(" + escape(shortForm(clazz.getURI())) + deprecation); } /* We know that the description has to be a oneof */ try { OWLEnumeration enumeration = (OWLEnumeration) eq; for (Iterator iit = enumeration.getIndividuals().iterator(); iit.hasNext();) { OWLIndividual desc = (OWLIndividual) iit.next(); visitor.reset(); desc.accept(visitor); print(" " + visitor.result()); // if (iit.hasNext()) { // print(" "); // } } println(")"); done = true; } catch (ClassCastException ex) { throw new RendererException(ex.getMessage()); } }// Added to render rules if (swoopModel.getEnableRules()) { Set rules = swoopModel.getRuleExpr().getRules(clazz); 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(")"); done = true; } } if (!done) { /* We need to give at least an empty definition */ if (editorEnabled) { println( "Class (" + shortForm(clazz.getURI()) + deprecation + " partial" + ")"); } else { println( "<b>Class </b>(" + escape(shortForm(clazz.getURI())) + deprecation + " <i>partial</i>" + ")"); } } } protected void renderTextClass(OWLClass clazz) throws OWLException { boolean done = false; String deprecation = (clazz.isDeprecated(reasoner.getOntology()) ? " Deprecated" : ""); if(!clazz.getAnnotations(reasoner.getOntology()).isEmpty()) { println( "Class (" + shortForm(clazz.getURI()) + deprecation + " partial"); renderAnnotations(clazz); println("\n)"); } for (Iterator it = clazz.getEquivalentClasses(reasoner.getOntologies()).iterator(); it.hasNext();) { OWLDescription eq = (OWLDescription) it.next(); println( "Class(" + shortForm(clazz.getURI()) + deprecation + " complete "); visitor.reset(); increaseINDENT(); eq.accept(visitor); println(visitor.result() + "\n)"); decreaseINDENT(); done = true; } if (!clazz.getSuperClasses(reasoner.getOntologies()).isEmpty()) { println( "Class (" + shortForm(clazz.getURI()) + deprecation + " partial "); for (Iterator it = clazz.getSuperClasses(reasoner.getOntologies()).iterator(); it.hasNext();) { OWLDescription eq = (OWLDescription) it.next(); visitor.reset(); increaseINDENT(); eq.accept(visitor); print(visitor.result()); decreaseINDENT(); if (it.hasNext()) { println(); } done = true; } println("\n)"); } /* * This has changed -- used to be simply a oneof in the class definition. We now get a * special keyword in the vocabulary */ for (Iterator it = clazz.getEnumerations(reasoner.getOntologies()).iterator(); it.hasNext();) { OWLDescription eq = (OWLDescription) it.next(); print( "EnumeratedClass(" + shortForm(clazz.getURI()) + deprecation); /* We know that the description has to be a oneof */ try { OWLEnumeration enumeration = (OWLEnumeration) eq; for (Iterator iit = enumeration.getIndividuals().iterator(); iit.hasNext();) { OWLIndividual desc = (OWLIndividual) iit.next(); visitor.reset(); desc.accept(visitor); print(" " + visitor.result()); // if (iit.hasNext()) { // print(" "); // } } println(")"); done = true; } catch (ClassCastException ex) { throw new RendererException(ex.getMessage()); } }// Added for rendering rules if (swoopModel.getEnableRules()) { Set rules = swoopModel.getRuleExpr().getRules(clazz); 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(")"); done = true; } } if (!done) { /* We need to give at least an empty definition */ println( "Class (" + shortForm(clazz.getURI()) + deprecation + " partial" + ")"); } } protected void renderIndividual(OWLIndividual ind) throws OWLException { if ( ind.isAnonymous() ) if (editorEnabled) print("Individual(" ); else print("<b>Individual</b>(" ); else if (editorEnabled) print("Individual(" + shortForm(ind.getURI())); else print("<b>Individual</b>(" + escape(shortForm(ind.getURI()))); if (ind.getAnnotations(reasoner.getOntology()).isEmpty() && ind.getTypes(reasoner.getOntologies()).isEmpty() && ind.getObjectPropertyValues(reasoner.getOntologies()).keySet().isEmpty() && ind.getDataPropertyValues(reasoner.getOntologies()).keySet().isEmpty()) { println(")"); } else { for (Iterator it = ind.getAnnotations(reasoner.getOntology()).iterator(); it.hasNext();) { println(); OWLAnnotationInstance oai = (OWLAnnotationInstance) it.next(); if (editorEnabled) print(TAB + "annotation(" + shortForm(oai.getProperty().getURI()) + " "); else print(TAB + "<i>annotation</i>(" + escape(shortForm(oai.getProperty().getURI())) + " "); /* Just whack out the content */ renderAnnotationContent(oai.getContent()); // print( oai.getContent() ); print(")"); visitor.reset(); oai.accept(visitor); // if (it.hasNext()) { // println(); // } } // println(); for (Iterator it = ind.getTypes(reasoner.getOntologies()).iterator(); it.hasNext();) { println(); OWLDescription eq = (OWLDescription) it.next(); visitor.reset(); eq.accept(visitor); if (editorEnabled) print(TAB + "type(" + visitor.result() + ")"); else print(TAB + "<i>type</i>(" + visitor.result() + ")"); // if (it.hasNext()) { // println(); // } } Map propertyValues = ind.getObjectPropertyValues(reasoner.getOntologies()); // System.out.println("ZZ: " + ind.getURI()); for (Iterator it = propertyValues.keySet().iterator(); it.hasNext();) { println(); OWLObjectProperty prop = (OWLObjectProperty) it.next(); Set vals = (Set) propertyValues.get(prop); for (Iterator valIt = vals.iterator(); valIt.hasNext();) { // System.out.println("QQ: " + ((OWLIndividual) valIt.next()).getURI()); OWLIndividual oi = (OWLIndividual) valIt.next(); visitor.reset(); oi.accept(visitor); //******************************************************* //changed for Econnections //******************************************************* if(!prop.isLink()){ if (editorEnabled) { print(TAB + "value(" + shortForm(prop.getURI()) + " " + visitor.result() + ")"); } else { print(TAB + "<i>value</i>(" + escape(shortForm(prop.getURI())) + " " + visitor.result() + ")"); } if (valIt.hasNext()) { println(); } } else{ if (editorEnabled) { print(TAB + "value(ForeignIndividual(foreignOntology((" + shortForm(prop.getLinkTarget()) + ")" + shortForm(prop.getURI()) + " " + visitor.result() + ")"); } else { print(TAB + "<i>value(ForeignIndividual(foreignOntology(</i>(" + escape(shortForm(prop.getLinkTarget())) + ")" + escape(shortForm(prop.getURI())) + " " + visitor.result() + ")"); } if (valIt.hasNext()) { println(); } } } } Map dataValues = ind.getDataPropertyValues(reasoner.getOntologies()); // System.out.println("ZZ: " + ind.getURI()); for (Iterator it = dataValues.keySet().iterator(); it.hasNext();) { println(); OWLDataProperty prop = (OWLDataProperty) it.next(); Set vals = (Set) dataValues.get(prop); for (Iterator valIt = vals.iterator(); valIt.hasNext();) { // System.out.println("QQ: " + ((OWLIndividual) valIt.next()).getURI()); OWLDataValue dtv = (OWLDataValue) valIt.next(); visitor.reset(); dtv.accept(visitor); if (editorEnabled) { print(TAB + "value(" + shortForm(prop.getURI()) + " " + visitor.result() + ")"); } else { print(TAB + "<i>value</i>(" + escape(shortForm(prop.getURI())) + " " + visitor.result() + ")"); } if (valIt.hasNext()) { println(); } } // if (it.hasNext()) { // println(); // } } println("\n)"); } } protected void renderTextIndividual(OWLIndividual ind) throws OWLException {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?