public Set<OWLClass> getSuperClasses(String classExpressionString, boolean direct) {
   if (classExpressionString.trim().length() == 0) {
     return Collections.emptySet();
   }
   OWLClassExpression classExpression = parser.parseClassExpression(classExpressionString);
   NodeSet<OWLClass> superClasses = reasoner.getSuperClasses(classExpression, direct);
   return superClasses.getFlattened();
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 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));
 }
Beispiel #4
0
  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);
  }
Beispiel #5
0
  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;
  }