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> 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; }
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)); }
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); }