public static void main(String[] args) { try { SimpleRenderer renderer = new SimpleRenderer(); renderer.setShortFormProvider( new DefaultPrefixManager("http://www.mindswap.org/ontologies/tambis-full.owl#")); ToStringRenderer.getInstance().setRenderer(renderer); OWLOntologyManager man = OWLManager.createOWLOntologyManager(); OWLOntology ont = man.loadOntology( IRI.create( "http://owl.cs.manchester.ac.uk/repository/download?ontology=http://www.cs.manchester.ac.uk/owl/ontologies/tambis-patched.owl")); System.out.println("Loaded!"); OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance(); OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(ont); reasoner.getUnsatisfiableClasses(); ExplanationBasedRootClassFinder rdr = new ExplanationBasedRootClassFinder(man, reasoner, reasonerFactory); for (OWLClass cls : rdr.getRootUnsatisfiableClasses()) System.out.println("ROOT! " + cls); } catch (TimeOutException e) { e.printStackTrace(); } catch (ReasonerInterruptedException e) { e.printStackTrace(); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } }
public boolean isDomainOrRangeOfObjectProperty(OWLClass clase, OWLObjectProperty prop) { for (OWLClass owlClass1 : _reasoner.getObjectPropertyDomains(prop, false).getFlattened()) { if (owlClass1.getIRI().equals(clase.getIRI())) { Log.d( TAG, "<isDomainOrRangeOfObjectProperty> " + clase.getIRI().getRemainder().get() + " dominio o rango de " + prop.getIRI().getRemainder().get() + "? SI!"); return true; } } for (OWLClass owlClass1 : _reasoner.getObjectPropertyRanges(prop, false).getFlattened()) { if (owlClass1.getIRI().equals(clase.getIRI())) { Log.d( TAG, "<isDomainOrRangeOfObjectProperty> " + clase.getIRI().getRemainder().get() + " dominio o rango de " + prop.getIRI().getRemainder().get() + "? SI!"); return true; } } Log.d( TAG, "<isDomainOrRangeOfObjectProperty> " + clase.getIRI().getRemainder().get() + " dominio o rango de " + prop.getIRI().getRemainder().get() + "? NO"); return false; }
public void classifyOntology(OWLOntology ontology, OWLReasonerFactory factory) { ToStringRenderer.getInstance().setRenderer(new ManchesterOWLSyntaxOWLObjectRendererImpl()); OWLReasoner reasoner = factory.createNonBufferingReasoner(ontology); // reasoner.precomputeInferences(InferenceType.values()); long time = System.currentTimeMillis(); boolean isConsistent = reasoner.isConsistent(); int numOfUnsatClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size(); time = System.currentTimeMillis() - time; DLExpressivityChecker checker = new DLExpressivityChecker(Collections.singleton(ontology)); String e = checker.getDescriptionLogicName(); String name = ontology.getOntologyID().getOntologyIRI().getFragment(); logger.info( "ontology: " + name + ", reasoner: " + factory.getReasonerName() + ", expressivity: " + e + ", consistent: " + isConsistent + ", unsat classes: " + numOfUnsatClasses + ", time: " + time); }
private void classifyWithSnorocket(OWLOntology ontology) { System.out.println("\nUsing Snorocket..."); long startTime = System.nanoTime(); SnorocketReasonerFactory srf = new SnorocketReasonerFactory(); OWLReasoner snorocketReasoner = srf.createReasoner(ontology); snorocketReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); snorocketReasoner.dispose(); System.out.println("Time taken (secs): " + Util.getElapsedTimeSecs(startTime)); }
private void classifyWithJFact(OWLOntology ontology) { System.out.println("\nUsing JFact ..."); long startTime = System.nanoTime(); OWLReasonerFactory reasonerFactory = new JFactFactory(); OWLReasoner jfactReasoner = reasonerFactory.createReasoner(ontology); jfactReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); jfactReasoner.dispose(); System.out.println("Time taken (secs): " + Util.getElapsedTimeSecs(startTime)); }
private Set<String> getSuperClasses(OWLReasoner reasoner, OWLClass cl, OWLClass owlThing) { Set<String> pset = new HashSet<String>(); Set<OWLClass> reasonerSuperClasses = reasoner.getSuperClasses(cl, false).getFlattened(); // add cl itself to S(X) computed by reasoner. That is missing // in its result. reasonerSuperClasses.add(cl); reasonerSuperClasses.add(owlThing); // adding equivalent classes -- they are not considered if asked for superclasses Iterator<OWLClass> iterator = reasoner.getEquivalentClasses(cl).iterator(); while (iterator.hasNext()) reasonerSuperClasses.add(iterator.next()); for (OWLClass scl : reasonerSuperClasses) pset.add(scl.toString()); return pset; }
public Set<OWLClass> getObjectPropertyRange(OWLObjectProperty prop) { Set<OWLClass> classSet = new HashSet<OWLClass>(); for (OWLClass clase : _reasoner.getObjectPropertyRanges(prop, true).getFlattened()) { classSet.add(clase); } return classSet; }
private void rebuild() { typeNodes.clear(); if (reasoner != null) { Set<OWLOntology> importsClosure = reasoner.getRootOntology().getImportsClosure(); for (OWLOntology ont : importsClosure) { for (OWLClass cls : ont.getClassesInSignature()) { final Set<OWLNamedIndividual> inds = reasoner.getInstances(cls, showDirect).getFlattened(); if (!inds.isEmpty()) { typeNodes.put(cls, new HashSet<OWLObject>(inds)); } } } } fireHierarchyChanged(); }
@Override public void dispose() { if (reasoner != null) { reasoner.dispose(); reasoner = null; } }
public Set<OWLObjectProperty> getObjectPropertiesByDomainAndRange( OWLClass domain, OWLClass range) { Set<OWLObjectProperty> propSet = new HashSet<OWLObjectProperty>(); for (OWLObjectProperty prop : _ontology.getObjectPropertiesInSignature()) { for (OWLClass owlClass : _reasoner.getObjectPropertyDomains(prop, true).getFlattened()) { if (owlClass.equals(domain)) { for (OWLClass owlClass2 : _reasoner.getObjectPropertyRanges(prop, true).getFlattened()) { if (owlClass2.equals(range)) { propSet.add(prop); } } } } } return propSet; }
public Set<OWLNamedIndividual> getInstances(String classExpressionString, boolean direct) { if (classExpressionString.trim().length() == 0) { return Collections.emptySet(); } OWLClassExpression classExpression = parser.parseClassExpression(classExpressionString); NodeSet<OWLNamedIndividual> individuals = reasoner.getInstances(classExpression, direct); return individuals.getFlattened(); }
public Set<OWLClass> getSubClasses(String classExpressionString, boolean direct) { if (classExpressionString.trim().length() == 0) { return Collections.emptySet(); } OWLClassExpression classExpression = parser.parseClassExpression(classExpressionString); NodeSet<OWLClass> subClasses = reasoner.getSubClasses(classExpression, direct); return subClasses.getFlattened(); }
/** Release the reasoner */ public void disposeReasoner() { synchronized (reasonerMutex) { if (reasoner != null) { reasoner.dispose(); reasoner = null; } } }
public Set<OWLClass> getObjectPropertyDomain(Set<OWLObjectProperty> propSet) { Set<OWLClass> classSet = new HashSet<OWLClass>(); for (OWLObjectProperty prop : propSet) { for (OWLClass clase : _reasoner.getObjectPropertyDomains(prop, true).getFlattened()) { classSet.add(clase); } } return classSet; }
/** Only call within a {@link #moduleReasonerMutex} synchronized block!! */ private void _internalDisposeModuleReasonerAndListener() { if (moduleReasoner != null) { moduleReasoner.dispose(); moduleReasoner = null; } if (moduleListener != null) { aboxOntology.getOWLOntologyManager().removeOntologyChangeListener(moduleListener); moduleListener = null; } }
private void compareClassificationResults( OWLOntology ontology, OWLReasoner reasoner, Jedis resultStore, Jedis idReader) throws Exception { Set<OWLClass> classes = ontology.getClassesInSignature(); Pipeline resultPipeline = resultStore.pipelined(); double classCount = 0; int multiplier = 1; double totalCount = 0; for (OWLClass cl : classes) { classCount++; double classProgress = (classCount / classes.size()) * 100; Set<OWLClass> reasonerSuperclasses = reasoner.getSuperClasses(cl, false).getFlattened(); // add cl itself to S(X) computed by reasoner. That is missing // in its result. reasonerSuperclasses.add(cl); // adding equivalent classes -- they are not considered if asked for superclasses Iterator<OWLClass> iterator = reasoner.getEquivalentClasses(cl).iterator(); while (iterator.hasNext()) reasonerSuperclasses.add(iterator.next()); String classToCheckID = conceptToID(cl.toString(), idReader); List<Response<Double>> responseList = new ArrayList<Response<Double>>(); for (OWLClass scl : reasonerSuperclasses) { String key = conceptToID(scl.toString(), idReader); responseList.add(resultPipeline.zscore(key, classToCheckID)); } resultPipeline.sync(); double hitCount = 0; for (Response<Double> response : responseList) { if (response.get() != null) hitCount++; } totalCount += (hitCount / reasonerSuperclasses.size()); if (classProgress >= (5 * multiplier)) { System.out.println( "% of no. of classes looked at: " + classProgress + "\tProgress %: " + (totalCount / classCount) * 100); multiplier++; } } double progress = totalCount / classes.size(); System.out.println("\nProgress %: " + (progress * 100)); }
public Set<OWLDataProperty> getDataPropertiesByDomain(OWLClass domain) { Set<OWLDataProperty> propSet = new HashSet<OWLDataProperty>(); Set<OWLDataProperty> objProps = _ontology.getDataPropertiesInSignature(); for (OWLDataProperty prop : objProps) { for (OWLClass owlClass : _reasoner.getDataPropertyDomains(prop, true).getFlattened()) { if (owlClass.equals(domain)) { propSet.add(prop); } } } return propSet; }
public Set<OWLObject> getParents(OWLObject object) { if (reasoner != null && typeNodes.containsKey(object)) { return Collections.emptySet(); } else { OWLNamedIndividual ind = (OWLNamedIndividual) object; Set<OWLObject> clses = new HashSet<OWLObject>(); for (OWLClass cls : reasoner.getTypes(ind, showDirect).getFlattened()) { clses.add(cls); } return clses; } }
public Set<OWLClass> getEquivalentClasses(String classExpressionString) { if (classExpressionString.trim().length() == 0) { return Collections.emptySet(); } OWLClassExpression classExpression = parser.parseClassExpression(classExpressionString); Node<OWLClass> equivalentClasses = reasoner.getEquivalentClasses(classExpression); Set<OWLClass> result = null; if (classExpression.isAnonymous()) { result = equivalentClasses.getEntities(); } else { result = equivalentClasses.getEntitiesMinus(classExpression.asOWLClass()); } return result; }
public void getELKIncrementalRuntime(String baseOnt, String ontDir) throws Exception { GregorianCalendar start = new GregorianCalendar(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); IRI documentIRI = IRI.create(new File(baseOnt)); OWLOntology baseOntology = manager.loadOntology(documentIRI); System.out.println("Logical axioms: " + baseOntology.getLogicalAxiomCount()); // findDataHasValueAxiom(baseOntology.getAxioms(AxiomType.SUBCLASS_OF)); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(baseOntology); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); File[] files = new File(ontDir).listFiles(); int count = 0; OWLOntologyManager manager2 = OWLManager.createOWLOntologyManager(); addTripsBaseOntologies(manager2); for (File file : files) { System.out.println("File name: " + file.getName()); documentIRI = IRI.create(file); OWLOntology ontology = manager2.loadOntology(documentIRI); Set<OWLLogicalAxiom> axioms = ontology.getLogicalAxioms(); // findDataHasValueAxiom(ontology.getAxioms(AxiomType.SUBCLASS_OF)); manager.addAxioms(baseOntology, axioms); reasoner.flush(); System.out.println("Logical axioms: " + baseOntology.getLogicalAxiomCount()); // From the ELK wiki, it seems ABox reasoning will trigger TBox reasoning reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS); manager2.removeOntology(ontology); count++; System.out.println("Done with " + count); // if(count == 5) // break; } reasoner.dispose(); System.out.println("Time taken (millis): " + Util.getElapsedTime(start)); }
private static void print(Node<OWLClass> parent, OWLReasoner reasoner, int depth) { // We don't want to print out the bottom node (containing owl:Nothing and unsatisfiable classes) // because this would appear as a leaf node everywhere if (parent.isBottomNode()) { return; } // Print an indent to denote parent-child relationships printIndent(depth); // Now print the node (containing the child classes) printNode(parent); for (Node<OWLClass> child : reasoner.getSubClasses(parent.getRepresentativeElement(), true)) { // Recurse to do the children. Note that we don't have to worry about cycles as there // are non in the inferred class hierarchy graph - a cycle gets collapsed into a single // node since each class in the cycle is equivalent. print(child, reasoner, depth + 1); } }
/** * <b>Motivation</b>: OWL reasoners do not return superclass expressions If we want to find all * class expressions that may hold for a class then we must pre-coordinate all possible * expressions within the subset of OWL we care about. <br> * This class generates all satisfiable class expressions of the form r some c (for the * cross-product of R x C), as well as all class expressions that have been used (which may * include nested expressions) * * <p>The results are stored in queryClassMap * * @param precomputePropertyClassCombinations */ @Deprecated private void generateQueryOntology(boolean precomputePropertyClassCombinations) { queryClassMap = new HashMap<OWLClass, OWLClassExpression>(); getReasoner().flush(); if (precomputePropertyClassCombinations) { LOG.debug("Precomputing all OP x Class combos"); // cross-product of P x C // TODO - reflexivity and local reflexivity? for (OWLObjectProperty p : tboxOntology.getObjectPropertiesInSignature(true)) { LOG.debug(" materializing P some C for P=:" + p); for (OWLClass c : tboxOntology.getClassesInSignature(true)) { OWLObjectSomeValuesFrom r = getOWLDataFactory().getOWLObjectSomeValuesFrom(p, c); // LOG.debug(" QMAP:"+r); addClassExpressionToQueryMap(r); } } } // all expressions used in ontology for (OWLOntology ont : tboxOntology.getImportsClosure()) { LOG.debug("Finding all nested anonymous expressions"); for (OWLAxiom ax : ont.getAxioms()) { // TODO - check if this is the nest closure. ie (r some (r2 some (r3 some ...))) for (OWLClassExpression x : ax.getNestedClassExpressions()) { if (x.isAnonymous()) { // LOG.debug(" QMAP+:"+x); addClassExpressionToQueryMap(x); } } } } if (LOG.isDebugEnabled()) { for (OWLOntology ont : collectedAxioms.keySet()) { LOG.debug("TOTAL axioms in QMAP: " + collectedAxioms.get(ont).size()); } } LOG.debug("Adding collected axioms"); addCollectedAxioms(); LOG.debug("Flushing reasoner..."); reasoner.flush(); LOG.debug("Flushed reasoner"); }
public static void main(String[] args) { try { // Create our ontology manager in the usual way. OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); // Load a copy of the people+pets ontology. We'll load the ontology from the web (it's // acutally located // in the TONES ontology repository). IRI docIRI = IRI.create(DOCUMENT_IRI); // We load the ontology from a document - our IRI points to it directly OWLOntology ont = manager.loadOntologyFromOntologyDocument(docIRI); System.out.println("Loaded " + ont.getOntologyID()); // We need to create an instance of OWLReasoner. An OWLReasoner provides the basic // query functionality that we need, for example the ability obtain the subclasses // of a class etc. To do this we use a reasoner factory. // Create a reasoner factory. In this case, we will use HermiT, but we could also // use FaCT++ (http://code.google.com/p/factplusplus/) or // Pellet(http://clarkparsia.com/pellet) // Note that (as of 03 Feb 2010) FaCT++ and Pellet OWL API 3.0.0 compatible libraries are // expected to be available in the near future). // For now, we'll use HermiT // HermiT can be downloaded from http://hermit-reasoner.com // Make sure you get the HermiT library and add it to your class path. You can then // instantiate the HermiT reasoner factory: // Comment out the first line below and uncomment the second line below to instantiate // the HermiT reasoner factory. You'll also need to import the // org.semanticweb.HermiT.Reasoner // package. OWLReasonerFactory reasonerFactory = null; // OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory(); // We'll now create an instance of an OWLReasoner (the implementation being provided by HermiT // as // we're using the HermiT reasoner factory). The are two categories of reasoner, Buffering // and // NonBuffering. In our case, we'll create the buffering reasoner, which is the default kind // of reasoner. // We'll also attach a progress monitor to the reasoner. To do this we set up a configuration // that // knows about a progress monitor. // Create a console progress monitor. This will print the reasoner progress out to the // console. ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor(); // Specify the progress monitor via a configuration. We could also specify other setup // parameters in // the configuration, and different reasoners may accept their own defined parameters this // way. OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor); // Create a reasoner that will reason over our ontology and its imports closure. Pass in the // configuration. OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config); // Ask the reasoner to do all the necessary work now reasoner.precomputeInferences(); // We can determine if the ontology is actually consistent (in this case, it should be). boolean consistent = reasoner.isConsistent(); System.out.println("Consistent: " + consistent); System.out.println("\n"); // We can easily get a list of unsatisfiable classes. (A class is unsatisfiable if it // can't possibly have any instances). Note that the getUnsatisfiableClasses method // is really just a convenience method for obtaining the classes that are equivalent // to owl:Nothing. In our case there should be just one unsatisfiable class - "mad_cow" // We ask the reasoner for the unsatisfiable classes, which returns the bottom node // in the class hierarchy (an unsatisfiable class is a subclass of every class). Node<OWLClass> bottomNode = reasoner.getUnsatisfiableClasses(); // This node contains owl:Nothing and all the classes that are equivalent to owl:Nothing - // i.e. the unsatisfiable classes. // We just want to print out the unsatisfiable classes excluding owl:Nothing, and we can // used a convenience method on the node to get these Set<OWLClass> unsatisfiable = bottomNode.getEntitiesMinusBottom(); if (!unsatisfiable.isEmpty()) { System.out.println("The following classes are unsatisfiable: "); for (OWLClass cls : unsatisfiable) { System.out.println(" " + cls); } } else { System.out.println("There are no unsatisfiable classes"); } System.out.println("\n"); // Now we want to query the reasoner for all descendants of vegetarian. Vegetarians are // defined in the // ontology to be animals that don't eat animals or parts of animals. OWLDataFactory fac = manager.getOWLDataFactory(); // Get a reference to the vegetarian class so that we can as the reasoner about it. // The full IRI of this class happens to be: // <http://owl.man.ac.uk/2005/07/sssw/people#vegetarian> OWLClass vegPizza = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2005/07/sssw/people#vegetarian")); // Now use the reasoner to obtain the subclasses of vegetarian. // We can ask for the direct subclasses of vegetarian or all of the (proper) subclasses of // vegetarian. // In this case we just want the direct ones (which we specify by the "true" flag). NodeSet<OWLClass> subClses = reasoner.getSubClasses(vegPizza, true); // The reasoner returns a NodeSet, which represents a set of Nodes. // Each node in the set represents a subclass of vegetarian pizza. A node of classes contains // classes, // where each class in the node is equivalent. For example, if we asked for the // subclasses of some class A and got back a NodeSet containing two nodes {B, C} and {D}, then // A would have // two proper subclasses. One of these subclasses would be equivalent to the class D, and the // other would // be the class that is equivalent to class B and class C. // In this case, we don't particularly care about the equivalences, so we will flatten this // set of sets and print the result Set<OWLClass> clses = subClses.getFlattened(); System.out.println("Subclasses of vegetarian: "); for (OWLClass cls : clses) { System.out.println(" " + cls); } System.out.println("\n"); // In this case, we should find that the classes, cow, sheep and giraffe are vegetarian. Note // that in this // ontology only the class cow had been stated to be a subclass of vegetarian. The fact that // sheep and // giraffe are subclasses of vegetarian was implicit in the ontology (through other things we // had said) // and this illustrates why it is important to use a reasoner for querying an ontology. // We can easily retrieve the instances of a class. In this example we'll obtain the // instances of // the class pet. This class has a full IRI of <http://owl.man.ac.uk/2005/07/sssw/people#pet> // We need to obtain a reference to this class so that we can ask the reasoner about it. OWLClass country = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2005/07/sssw/people#pet")); // Ask the reasoner for the instances of pet NodeSet<OWLNamedIndividual> individualsNodeSet = reasoner.getInstances(country, true); // The reasoner returns a NodeSet again. This time the NodeSet contains individuals. // Again, we just want the individuals, so get a flattened set. Set<OWLNamedIndividual> individuals = individualsNodeSet.getFlattened(); System.out.println("Instances of pet: "); for (OWLNamedIndividual ind : individuals) { System.out.println(" " + ind); } System.out.println("\n"); // Again, it's worth noting that not all of the individuals that are returned were explicitly // stated // to be pets. // Finally, we can ask for the property values (property assertions in OWL speak) for a given // individual // and property. // Let's get the property values for the individual Mick, the full IRI of which is // <http://owl.man.ac.uk/2005/07/sssw/people#Mick> // Get a reference to the individual Mick OWLNamedIndividual mick = fac.getOWLNamedIndividual(IRI.create("http://owl.man.ac.uk/2005/07/sssw/people#Mick")); // Let's get the pets of Mick // Get hold of the has_pet property which has a full IRI of // <http://owl.man.ac.uk/2005/07/sssw/people#has_pet> OWLObjectProperty hasPet = fac.getOWLObjectProperty(IRI.create("http://owl.man.ac.uk/2005/07/sssw/people#has_pet")); // Now ask the reasoner for the has_pet property values for Mick NodeSet<OWLNamedIndividual> petValuesNodeSet = reasoner.getObjectPropertyValues(mick, hasPet); Set<OWLNamedIndividual> values = petValuesNodeSet.getFlattened(); System.out.println("The has_pet property values for Mick are: "); for (OWLNamedIndividual ind : values) { System.out.println(" " + ind); } // Notice that Mick has a pet Rex, which wasn't asserted in the ontology. // Finally, let's print out the class hierarchy. // Get hold of the top node in the class hierarchy (containing owl:Thing) // Now print the hierarchy out Node<OWLClass> topNode = reasoner.getTopClassNode(); print(topNode, reasoner, 0); } catch (UnsupportedOperationException exception) { System.out.println("Unsupported reasoner operation."); } catch (OWLOntologyCreationException e) { System.out.println("Could not load the pizza ontology: " + e.getMessage()); } }
public Set<NamingIssue> detectNonMatchingChildIssues(OWLOntology ontology, boolean directChild) { long start = System.currentTimeMillis(); // get SubClass - SuperClass pairs Set<NamingIssue> nonMatchingChildren = new HashSet<NamingIssue>(); if (directChild) { Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF); for (OWLSubClassOfAxiom ax : axioms) { OWLClassExpression subClass = ax.getSubClass(); OWLClassExpression superClass = ax.getSuperClass(); if (!subClass.isAnonymous() && !superClass.isAnonymous()) { String subClassURI = subClass.asOWLClass().toStringID(); String superClassURI = superClass.asOWLClass().toStringID(); if (ignoreSingleTokenSubClasses && !singleToken(subClassURI)) { String subClassHead = getHeadNoun(subClassURI); String superClassHead = getHeadNoun(superClassURI); boolean matching = subClassHead.equals(superClassHead) || isHypernymOf(superClassHead, subClassHead); if (!matching) { String newClassURI = buildNewURI(subClassURI, superClassHead); nonMatchingChildren.add( new NamingIssue( subClassURI, superClassURI, new RenamingInstruction(subClassURI, newClassURI))); } } } } } else { OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance(); OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(ontology); Set<OWLClass> classes = ontology.getClassesInSignature(); for (OWLClass cls : classes) { Set<OWLClass> superClasses = reasoner.getSuperClasses(cls, false).getFlattened(); superClasses.remove(OWL_THING); for (OWLClass superClass : superClasses) { String subClassURI = cls.asOWLClass().toStringID(); String superClassURI = superClass.asOWLClass().toStringID(); if (ignoreSingleTokenSubClasses && !singleToken(subClassURI)) { String subClassHead = getHeadNoun(subClassURI); String superClassHead = getHeadNoun(superClassURI); boolean matching = subClassHead.equals(superClassHead) || isHypernymOf(superClassHead, subClassHead); if (!matching) { String newClassURI = buildNewURI(subClassURI, superClassHead); nonMatchingChildren.add( new NamingIssue( subClassURI, superClassURI, new RenamingInstruction(subClassURI, newClassURI))); } } } } } long end = System.currentTimeMillis(); logger.info("Operation took " + (end - start) + "ms"); return nonMatchingChildren; }
public DLQueryEngine(OWLReasoner reasoner, ShortFormProvider shortFormProvider) { this.reasoner = reasoner; parser = new DLQueryParser(reasoner.getRootOntology(), shortFormProvider); }
private void rearrangeAndCompareResults( OWLOntology ontology, OWLReasoner reasoner, Jedis resultStore, Jedis resultStore2, Jedis idReader) throws Exception { new ResultRearranger().initializeAndRearrange(); Set<OWLClass> classes = ontology.getClassesInSignature(); // rearranged results are in DB-1 resultStore.select(1); double classCount = 0; int multiplier = 1; int missCount = 0; String bottomID = Util.getPackedID(Constants.BOTTOM_ID, EntityType.CLASS); System.out.println("Comparing Classes... " + classes.size()); OWLClass owlThing = ontology.getOWLOntologyManager().getOWLDataFactory().getOWLThing(); for (OWLClass cl : classes) { String classID = conceptToID(cl.toString(), idReader); // REL/Pellet doesn't consider individuals i.e. {a} \sqsubseteq \bottom // so skipping checking bottom if (classID.equals(bottomID)) continue; classCount++; Set<OWLClass> reasonerSuperClasses = reasoner.getSuperClasses(cl, false).getFlattened(); // add cl itself to S(X) computed by reasoner. That is missing // in its result. reasonerSuperClasses.add(cl); reasonerSuperClasses.add(owlThing); // adding equivalent classes -- they are not considered if asked for superclasses Iterator<OWLClass> iterator = reasoner.getEquivalentClasses(cl).iterator(); while (iterator.hasNext()) reasonerSuperClasses.add(iterator.next()); Set<String> superClasses = resultStore.smembers(classID); if (superClasses.size() == reasonerSuperClasses.size()) { compareAndPrintEqualSizedClasses(cl, reasonerSuperClasses, superClasses, idReader); } else { System.out.println( "\n" + cl.toString() + " -- " + superClasses.size() + ", " + reasonerSuperClasses.size()); for (OWLClass scl : reasonerSuperClasses) { String sclID = conceptToID(scl.toString(), idReader); if (!superClasses.contains(sclID)) { System.out.print(cl.toString() + " -ne- " + scl.toString()); System.out.print(" , "); } superClasses.remove(sclID); } for (String s : superClasses) System.out.println("\t -- " + Util.idToConcept(s, idReader) + "(" + s + ")"); System.out.println(); missCount++; } } System.out.println("No of classes not equal: " + missCount); Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature(); System.out.println("Rearranging individuals..."); System.out.println("Individuals: " + individuals.size()); System.out.println("Not checking for individuals..."); /* rearrangeIndividuals(individuals, resultStore, resultStore2, idReader); int cnt = 0; for(OWLClass cl : classes) { Set<OWLNamedIndividual> instances = reasoner.getInstances(cl, false).getFlattened(); Set<String> computedInstances = resultStore2.smembers( conceptToID(cl.toString(), idReader)); if(computedInstances.size() == instances.size()) { compareAndPrintEqualSizedIndividuals(cl, instances, computedInstances, idReader); } else { System.out.println(cl.toString() + " -- " + computedInstances.size() + " , " + instances.size()); compareAndPrintUnEqualSizedIndividuals(cl, instances, computedInstances, idReader); cnt++; } } System.out.println("No of classes for which individuals didn't match: " + cnt); */ resultStore.select(0); }
public void updateLsignatureWithUnsatClasses(OWLReasoner reasoner) { Set<OWLClass> unsatClasses = reasoner.getBottomClassNode().getEntities(); if (lSignatureClasses.addAll(unsatClasses)) compSignatureClasses.removeAll(unsatClasses); }
private void computeObjectPropertyHierarchyDepthMetrics() { Node<OWLDataProperty> topNode = reasoner.getTopDataPropertyNode(); super.topDownTraverse(topNode, 0); }
private void precomputeAndCheckResults(OWLOntology ontology) throws Exception { System.out.println("Not Normalizing"); PropertyFileHandler propertyFileHandler = PropertyFileHandler.getInstance(); HostInfo resultNodeHostInfo = propertyFileHandler.getResultNode(); // port: 6489 for snapshot testing Jedis resultStore = new Jedis( resultNodeHostInfo.getHost(), resultNodeHostInfo.getPort(), Constants.INFINITE_TIMEOUT); Jedis resultStore2 = new Jedis( resultNodeHostInfo.getHost(), resultNodeHostInfo.getPort(), Constants.INFINITE_TIMEOUT); resultStore2.select(2); HostInfo localHostInfo = propertyFileHandler.getLocalHostInfo(); Jedis localStore = new Jedis(localHostInfo.getHost(), localHostInfo.getPort()); Set<String> idHosts = localStore.zrange( AxiomDistributionType.CONCEPT_ID.toString(), Constants.RANGE_BEGIN, Constants.RANGE_END); // currently there is only one ID node String[] idHostPort = idHosts.iterator().next().split(":"); Jedis idReader = new Jedis(idHostPort[0], Integer.parseInt(idHostPort[1]), Constants.INFINITE_TIMEOUT); GregorianCalendar cal1 = new GregorianCalendar(); try { // OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); // OWLReasoner reasoner = reasonerFactory.createReasoner(ontology); // reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // PelletReasoner reasoner = PelletReasonerFactory.getInstance(). // createReasoner( ontology ); // reasoner.prepareReasoner(); // Reasoner hermitReasoner = new Reasoner(ontology); // hermitReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); // OWLReasoner reasoner = reasonerFactory.createReasoner(ontology); // reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // RELReasonerFactory relfactory = new RELReasonerFactory(); // RELReasoner reasoner = relfactory.createReasoner(ontology); // reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // JcelReasoner reasoner = new JcelReasoner(ontology, false); // reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ontology); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); System.out.println("Reasoner completed in (millis): " + Util.getElapsedTime(cal1)); System.out.println("Comparing results using ELK....."); rearrangeAndCompareResults(ontology, reasoner, resultStore, resultStore2, idReader); // pelletReasoner.dispose(); // reasonerELK.dispose(); reasoner.dispose(); } finally { localStore.disconnect(); resultStore.disconnect(); resultStore2.disconnect(); idReader.disconnect(); } }