/** Returns true if d1 is a subclass of d2. */ public boolean isSubClassOf(OWLDescription d1, OWLDescription d2) throws OWLException { checkStatus(); StringWriter sw = new StringWriter(); sw.write( "<asks xmlns=\"http://dl.kr.org/dig/lang\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://dl.kr.org/dig/lang dig.xsd\">"); sw.write("<subsumes id=\"q\">"); /* Add the rendered description here */ renderer.reset(); d2.accept(renderer); sw.write(renderer.result()); renderer.reset(); d1.accept(renderer); sw.write(renderer.result()); sw.write("</subsumes>"); sw.write("</asks>"); StringWriter response = new StringWriter(); try { digReasoner.request(new StringReader(sw.toString()), response); } catch (Exception e) { throw new OWLException(e.getMessage()); } uk.ac.man.cs.img.dig.helper.Response serverResponse = new uk.ac.man.cs.img.dig.helper.Response(response.toString()); org.w3c.dom.Element r = serverResponse.extractResponse("q"); return (r.getTagName().equals("true")); }
public void rebuild(OWLEquivalentClassesAxiom axiom) { for (OWLDescription desc : axiom.getDescriptions()) { desc.accept(this); } Set<OWLDescription> equivClasses = this.getRelevantDescriptionsAsSet(0); this.rebuiltAxioms.add(this.factory.getOWLEquivalentClassesAxiom(equivClasses)); }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { try { // managing colors if (isSelected) { this.setBackground(table.getSelectionBackground()); this.setForeground(table.getSelectionForeground()); } else { this.setBackground(table.getSelectionForeground()); this.setForeground(Color.BLACK); } OWLDescription desc = (OWLDescription) value; desc.accept(myVisitor); String str = myVisitor.result(); myVisitor.reset(); this.setText(str); // System.out.println( this.getText() ); } catch (Exception e) { e.printStackTrace(); } return this; }
private void renderClass(OWLOntology ontology, OWLClass clazz) throws OWLException { if (!definedURIs.contains(clazz.getURI())) { pw.println(" (defprimconcept " + shortForm(clazz) + ")"); definedURIs.add(clazz.getURI()); } /* This is a bit of a hack... */ if (shortForm(clazz).equals("|owl:Thing|") && !doneThing) { pw.println(" ;; Thing == TOP "); pw.println(" (equal_c " + shortForm(clazz) + " :top)"); doneThing = true; } if (shortForm(clazz).equals("|owl:Nothing|")) { pw.println(" ;; Nothing == BOTTOM "); pw.println(" (equal_c " + shortForm(clazz) + " :bottom)"); } for (Iterator it = clazz.getEquivalentClasses(ontology).iterator(); it.hasNext(); ) { OWLDescription eq = (OWLDescription) it.next(); pw.print(" (equal_c " + shortForm(clazz)); visitor.reset(); eq.accept(visitor); pw.print(" " + visitor.result()); pw.println(" )"); } for (Iterator it = clazz.getSuperClasses(ontology).iterator(); it.hasNext(); ) { OWLDescription eq = (OWLDescription) it.next(); pw.print(" (implies_c " + shortForm(clazz)); visitor.reset(); eq.accept(visitor); pw.print(" " + visitor.result()); pw.println(" )"); } for (Iterator it = clazz.getEnumerations(ontology).iterator(); it.hasNext(); ) { OWLDescription eq = (OWLDescription) it.next(); pw.print(" (equal_c " + shortForm(clazz)); visitor.reset(); eq.accept(visitor); pw.print(" " + visitor.result()); pw.println(" )"); } pw.println(); }
public void rebuild(OWLDisjointUnionAxiom axiom) { axiom.getOWLClass().accept(this); OWLClass equivClass = (OWLClass) this.getRelevantDescription(); for (OWLDescription desc : axiom.getDescriptions()) { desc.accept(this); } Set<OWLDescription> disjointUnionClasses = this.getRelevantDescriptionsAsSet(0); this.rebuiltAxioms.add(this.factory.getOWLDisjointUnionAxiom(equivClass, disjointUnionClasses)); }
// DONE @Override public void visit(OWLObjectUnionOf desc) { int reduceTo = this.rebuiltObjects.size(); for (OWLDescription operand : desc.getOperands()) { operand.accept(this); } HashSet<OWLDescription> ds = this.getRelevantDescriptionsAsSet(reduceTo); this.rebuiltObjects.add(this.factory.getOWLObjectUnionOf(ds)); }
public ClassExpTable( AxiomIndexer indexer, ConcisePlainVisitor visitor, HashedCounts classExpCounts, Hashtable classExpDepths) { this.myIndexer = indexer; String[] colNames = {"Class Expression", "#Occurences", "Depth", "Score"}; Object[][] data = new Object[classExpCounts.keySet().size()][4]; int i = 0; for (Iterator it = classExpCounts.keySet().iterator(); it.hasNext(); ) { OWLDescription desc = (OWLDescription) it.next(); if (desc == null) System.out.println("description is null at " + i); Integer count = new Integer(classExpCounts.getCount(desc)); Integer depth = (Integer) classExpDepths.get(desc); try { if (depth == null) { System.out.println(" depth is null at " + i); desc.accept(visitor); String str = visitor.result(); System.out.println(" [" + str + "]"); visitor.reset(); } } catch (Exception e) { e.printStackTrace(); } data[i][0] = desc; data[i][1] = count; data[i][2] = depth; data[i][3] = new Double(Math.pow(count.intValue(), (depth.intValue() + 1))); i++; } myDataModel = new ClassExpTableModel(colNames, data); myManipModel = new TableSorter(myDataModel); myTable = new JTable(myManipModel); myManipModel.setTableHeader(myTable.getTableHeader()); /* for ( int vColIndex = 0; vColIndex < 3; vColIndex++ ) { TableColumn col = myTable.getColumnModel().getColumn(vColIndex); col.setHeaderRenderer(new RichHeaderRenderer()); } */ myTable.setDefaultRenderer(OWLObjectImpl.class, new ClassExpRenderer(visitor)); setupUI(); this.addWindowListener(this); this.addComponentListener(this); myTable.addMouseListener(this); this.setSize(300, 600); this.setVisible(true); }
/** Returns all the instances of the given class. */ public Set instancesOf(OWLDescription d1) throws OWLException { Set result = new HashSet(); try { checkStatus(); StringWriter sw = new StringWriter(); sw.write( "<asks xmlns=\"http://dl.kr.org/dig/lang\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://dl.kr.org/dig/lang dig.xsd\">"); sw.write("<instances id=\"q\">"); /* Add the rendered description here */ renderer.reset(); d1.accept(renderer); sw.write(renderer.result()); sw.write("</instances>"); sw.write("</asks>"); StringWriter response = new StringWriter(); try { digReasoner.request(new StringReader(sw.toString()), response); } catch (Exception e) { throw new OWLException(e.getMessage()); } uk.ac.man.cs.img.dig.helper.Response serverResponse = new uk.ac.man.cs.img.dig.helper.Response(response.toString()); org.w3c.dom.Element r = serverResponse.extractResponse("q"); List l = serverResponse.extractIndividuals(r); /* For some reason, RACER is returning duplicates */ java.util.Set seen = new java.util.HashSet(); for (int j = 0; j < l.size(); j++) { String name = (String) l.get(j); if (!seen.contains(name)) { /* As with the class, this is a little tricky. The * reasoner may return individuals that aren't * *in* the ontology it's working with, but are * defined elsewhere.*/ OWLIndividual i = ontology.getOWLDataFactory().getOWLIndividual(new URI(name)); // OWLIndividual i = ontology.getIndividual( new URI( name ) ); result.add(i); seen.add(name); } } } catch (ExpressivenessOutOfScopeException ex) { throw new OWLException(ex.getMessage()); } catch (Exception ex) { // System.out.println( ex.getMessage() ); throw new OWLException(ex.getMessage()); } return result; }
@Override public void visit(OWLSubClassAxiom owlSubClassAxiom) { // get the complex description out of the axiom List<OWLDescription> descriptions = new ArrayList<OWLDescription>(owlSubClassAxiom.getDescriptions()); for (OWLDescription description : descriptions) { // visit the description and record replacment description.accept(descriptionVisitor); } // construct new Axiom OWLDescription subReplace = descriptionVisitor.getReplacements().get(owlSubClassAxiom.getSubClass()); OWLDescription superReplace = descriptionVisitor.getReplacements().get(owlSubClassAxiom.getSuperClass()); if (subReplace == null) { subReplace = owlSubClassAxiom.getSubClass(); } if (superReplace == null) { superReplace = owlSubClassAxiom.getSuperClass(); } OWLSubClassAxiom replacementAxiom = owlDataFactory.getOWLSubClassAxiom(subReplace, superReplace); // create the changeevents that have to be performed on the ontology try { List<OWLAxiomChange> replaceEvent = OWLUtils.createReplaceAxiomEvents(owlOntology, owlSubClassAxiom, replacementAxiom); axiomChanges.addAll(replaceEvent); } catch (OWLOntologyChangeException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } // clear the description visitor descriptionVisitor.clear(); super.visit(owlSubClassAxiom); }
public void visit(OWLObjectUnionOf owlOr) { try { // We can't do "nested" arg lists, so translate all operands // and put the pointers into a set first, then create the intersection Set<ClassPointer> operandPointers = new HashSet<ClassPointer>(); for (OWLDescription desc : owlOr.getOperands()) { desc.accept(this); operandPointers.add(getLastClassPointer()); } faCTPlusPlus.initArgList(); for (ClassPointer operandPointer : operandPointers) { faCTPlusPlus.addArg(operandPointer); } faCTPlusPlus.closeArgList(); lastClassPointer = faCTPlusPlus.getConceptOr(); } catch (Exception e) { throw new FaCTPlusPlusRuntimeException(e); } }
private Set getHierarchy(String queryTag, OWLDescription d) throws OWLException { StringWriter sw = new StringWriter(); Set result = new HashSet(); sw.write( "<asks xmlns=\"http://dl.kr.org/dig/lang\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://dl.kr.org/dig/lang dig.xsd\">"); sw.write("<" + queryTag + " id=\"q\">"); /* Add the rendered description here */ renderer.reset(); d.accept(renderer); sw.write(renderer.result()); sw.write("</" + queryTag + ">"); sw.write("</asks>"); StringWriter response = new StringWriter(); try { digReasoner.request(new StringReader(sw.toString()), response); } catch (Exception e) { throw new OWLException(e.getMessage()); } uk.ac.man.cs.img.dig.helper.Response serverResponse = new uk.ac.man.cs.img.dig.helper.Response(response.toString()); org.w3c.dom.Element r = serverResponse.extractResponse("q"); List syns = serverResponse.extractSynonymSets(r); for (Iterator it = syns.iterator(); it.hasNext(); ) { Set innerSet = new HashSet(); List names = (List) it.next(); for (Iterator nameIt = names.iterator(); nameIt.hasNext(); ) { uk.ac.man.cs.img.dig.helper.Response.Concept c = ((uk.ac.man.cs.img.dig.helper.Response.Concept) nameIt.next()); OWLClass clazz = conceptToClass(c); if (clazz != null) { innerSet.add(clazz); } } result.add(innerSet); } return result; }
private void renderObjectProperty(OWLOntology ontology, OWLObjectProperty prop) throws OWLException { // String key = "defprimrole"; if (!definedURIs.contains(prop.getURI())) { pw.println(" (defprimrole " + shortForm(prop) + ")"); definedURIs.add(prop.getURI()); } // if ( prop.isTransitive( ontology ) ) { // pw.print(" :transitive T"); // } /* ?? */ if (prop.isInverseFunctional(ontology)) { pw.print(" (functional"); pw.print(" (inv " + shortForm(prop) + ")"); pw.println(" )"); } if (!prop.getSuperProperties(ontology).isEmpty()) { // pw.print(" :supers ( "); for (Iterator it = prop.getSuperProperties(ontology).iterator(); it.hasNext(); ) { OWLObjectProperty sup = (OWLObjectProperty) it.next(); // pw.print(" ;; Super"); pw.print(" (implies_r "); pw.print(shortForm(prop)); pw.print(" "); pw.print(shortForm(sup)); pw.println(")"); } // pw.print(")"); } // pw.println(")"); if (prop.isFunctional(ontology)) { pw.print(" (functional"); pw.print(" " + shortForm(prop)); pw.println(" )"); } if (prop.isTransitive(ontology)) { pw.print(" (transitive"); pw.print(" " + shortForm(prop)); pw.println(" )"); } for (Iterator it = prop.getDomains(ontology).iterator(); it.hasNext(); ) { pw.println(" ;; Domain " + shortForm(prop)); pw.print(" (domain " + shortForm(prop) + " "); OWLDescription dom = (OWLDescription) it.next(); visitor.reset(); dom.accept(visitor); pw.println(visitor.result() + " )"); } for (Iterator it = prop.getRanges(ontology).iterator(); it.hasNext(); ) { pw.println(" ;; Range " + shortForm(prop)); pw.print(" (range " + shortForm(prop) + " "); OWLDescription dom = (OWLDescription) it.next(); visitor.reset(); dom.accept(visitor); pw.println(visitor.result() + " )"); } if (prop.isSymmetric(ontology)) { pw.println(" ;; Symmetry "); pw.println(" (equal_r " + " " + shortForm(prop) + " " + "(inv " + shortForm(prop) + " ))"); } for (Iterator it = prop.getInverses(ontology).iterator(); it.hasNext(); ) { pw.println(" ;;Inverse " + shortForm(prop)); pw.print(" (equal_r " + " " + shortForm(prop) + " " + "(inv "); OWLObjectProperty inv = (OWLObjectProperty) it.next(); visitor.reset(); inv.accept(visitor); pw.println(visitor.result() + " ))"); } pw.println(); }
private void renderIndividual(OWLOntology ontology, OWLIndividual ind) throws OWLException { /* If the individual is anonymous and has any incoming * properties, then we do not wish to show it here -- it will * be rendered during the rendering of the thing that points * to it. */ // if (ind.isAnonymous()) { // Map m = ind.getIncomingObjectPropertyValues(); // if ( !m.isEmpty() ) { // return; // } // } // if ( ind.isAnonymous() ) { // pw.print(" Individual(" ); // } else { if (!definedURIs.contains(ind.getURI())) { pw.println(" (defindividual " + shortForm(ind) + ")"); definedURIs.add(ind.getURI()); } // } if (ind.getTypes(ontology).isEmpty() && ind.getObjectPropertyValues(ontology).keySet().isEmpty() && ind.getDataPropertyValues(ontology).keySet().isEmpty()) { // pw.println( ")"); } else { for (Iterator it = ind.getTypes(ontology).iterator(); it.hasNext(); ) { pw.print(" (instance " + shortForm(ind)); OWLDescription eq = (OWLDescription) it.next(); visitor.reset(); eq.accept(visitor); pw.print(" " + visitor.result()); pw.println(")"); } /* Worry about this later.... */ Map propertyValues = ind.getObjectPropertyValues(ontology); // System.out.println("ZZ: " + ind); for (Iterator it = propertyValues.keySet().iterator(); it.hasNext(); ) { OWLObjectProperty prop = (OWLObjectProperty) it.next(); Set vals = (Set) propertyValues.get(prop); for (Iterator valIt = vals.iterator(); valIt.hasNext(); ) { OWLIndividual oi = (OWLIndividual) valIt.next(); visitor.reset(); oi.accept(visitor); pw.println( " (related " + shortForm(ind) + " " + shortForm(prop) + " " + visitor.result() + ")"); } } Map dataValues = ind.getDataPropertyValues(ontology); // System.out.println("ZZ: " + ind); for (Iterator it = dataValues.keySet().iterator(); it.hasNext(); ) { pw.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())); OWLDataValue dtv = (OWLDataValue) valIt.next(); visitor.reset(); dtv.accept(visitor); pw.print(";;_DataTypeValue value(" + shortForm(prop) + " " + visitor.result() + ")"); if (valIt.hasNext()) { pw.println(); } } // if (it.hasNext()) { // pw.println(); // } } } pw.println(); }
/** * A convenience method that translates an <code>OWLDescription</code> to the FaCT++ * representation of the description. * * @param description The description to be translated. * @return The corresponding FaCT++ representation of the description. */ public ClassPointer translate(OWLDescription description) throws OWLException { description.accept(this); return getLastClassPointer(); }
private void checkExpressivity() throws OWLException { try { /* * Here, we need to look at all the expressions used anywhere within * the ontology and check their level. */ /* For each ontology, we need to check everything within it */ expressivityLevel = LITE; SwoopExpressionValidatorVisitor evv = new SwoopExpressionValidatorVisitor(this, objectRenderer); for (Iterator it = allOntologies.iterator(); it.hasNext(); ) { OWLOntology onto = (OWLOntology) it.next(); for (Iterator cit = onto.getClasses().iterator(); cit.hasNext(); ) { OWLClass clazz = (OWLClass) cit.next(); if (!clazz.getEnumerations(onto).isEmpty()) { /* We're in DL. */ expressivityLevel = expressivityLevel | DL; URI uri = clazz.getURI(); explain( DL, ONEOF, "Enumeration used: " + encodeHLink(uri.toString(), myModel.shortForm(uri))); } for (Iterator superit = clazz.getSuperClasses(onto).iterator(); superit.hasNext(); ) { /* Check the expressivity of any superclasses */ /* * Tricky bit here -- if there's an intersection used at * the top level, we're still ok for LITE. This is *not* * currently catered for, so we will get some stuff * wrong. */ OWLDescription description = (OWLDescription) superit.next(); evv.reset(); evv.setTopLevelDescription(true); try { description.accept(evv); expressivityLevel = expressivityLevel | evv.getLevel(); } catch (OWLException ex) { explain(OTHER, UNKNOWN, ex.getMessage()); expressivityLevel = OTHER; } } for (Iterator superit = clazz.getEquivalentClasses(onto).iterator(); superit.hasNext(); ) { /* Check the expressivity of any equivalences */ /* * This is tricky, as these expressions *can* be * intersections, as long as they're intersections of * Lite constructs. This is the only place that it can * happen in Lite. */ OWLDescription description = (OWLDescription) superit.next(); evv.reset(); evv.setTopLevelDescription(true); try { description.accept(evv); expressivityLevel = expressivityLevel | evv.getLevel(); } catch (OWLException ex) { explain(OTHER, UNKNOWN, ex.getMessage()); expressivityLevel = OTHER; } } } for (Iterator iit = onto.getObjectProperties().iterator(); iit.hasNext(); ) { OWLObjectProperty op = (OWLObjectProperty) iit.next(); for (Iterator dit = op.getDomains(onto).iterator(); dit.hasNext(); ) { /* Check the expressivity of any equivalences */ OWLDescription description = (OWLDescription) dit.next(); evv.reset(); try { description.accept(evv); expressivityLevel = expressivityLevel | evv.getLevel(); } catch (OWLException ex) { explain(OTHER, UNKNOWN, ex.getMessage()); expressivityLevel = OTHER; } } for (Iterator dit = op.getRanges(onto).iterator(); dit.hasNext(); ) { /* Check the expressivity of any equivalences */ OWLDescription description = (OWLDescription) dit.next(); evv.reset(); try { description.accept(evv); expressivityLevel = expressivityLevel | evv.getLevel(); } catch (OWLException ex) { explain(OTHER, UNKNOWN, ex.getMessage()); expressivityLevel = OTHER; } } } for (Iterator iit = onto.getDataProperties().iterator(); iit.hasNext(); ) { OWLDataProperty dp = (OWLDataProperty) iit.next(); for (Iterator dit = dp.getDomains(onto).iterator(); dit.hasNext(); ) { /* Check the expressivity of any equivalences */ OWLDescription description = (OWLDescription) dit.next(); evv.reset(); try { description.accept(evv); expressivityLevel = expressivityLevel | evv.getLevel(); } catch (OWLException ex) { explain(OTHER, UNKNOWN, ex.getMessage()); expressivityLevel = OTHER; } } for (Iterator dit = dp.getRanges(onto).iterator(); dit.hasNext(); ) { /* Check the expressivity of any equivalences */ OWLDataRange description = (OWLDataRange) dit.next(); evv.reset(); try { description.accept(evv); expressivityLevel = expressivityLevel | evv.getLevel(); } catch (OWLException ex) { explain(OTHER, UNKNOWN, ex.getMessage()); expressivityLevel = OTHER; } } } for (Iterator iit = onto.getIndividuals().iterator(); iit.hasNext(); ) { OWLIndividual ind = (OWLIndividual) iit.next(); for (Iterator typeit = ind.getTypes(onto).iterator(); typeit.hasNext(); ) { /* Check the expressivity of any equivalences */ OWLDescription description = (OWLDescription) typeit.next(); evv.reset(); try { description.accept(evv); expressivityLevel = expressivityLevel | evv.getLevel(); } catch (OWLException ex) { explain(OTHER, UNKNOWN, ex.getMessage()); expressivityLevel = OTHER; } } } } Set complexProperties = evv.getComplexProperties(); /* * Gather all the properties that are known to be functional or * inverse functional */ for (Iterator it = allOntologies.iterator(); it.hasNext(); ) { OWLOntology onto = (OWLOntology) it.next(); for (Iterator pit = onto.getObjectProperties().iterator(); pit.hasNext(); ) { OWLObjectProperty prop = (OWLObjectProperty) pit.next(); if (prop.isFunctional(onto) || prop.isInverseFunctional(onto)) { complexProperties.add(prop); } } } /* * We aren't doing everything yet as we still need to grab those * that have complex superproperties. */ /* * Now check to see if they've been said to be transitive, in which * case we're in FULL. */ for (Iterator pit = complexProperties.iterator(); pit.hasNext(); ) { OWLObjectProperty prop = (OWLObjectProperty) pit.next(); for (Iterator it = allOntologies.iterator(); it.hasNext(); ) { OWLOntology onto = (OWLOntology) it.next(); if (prop.isTransitive(onto)) { expressivityLevel = FULL; URI uri = prop.getURI(); explain( FULL, COMPLEXTRANSITIVE, "Complex property " + encodeHLink(uri.toString(), myModel.shortForm(uri)) + " asserted to be transitive."); } } } } catch (Exception ex) { ex.printStackTrace(); throw new OWLException(ex.getMessage()); } }