Beispiel #1
0
 private void compareAndPrintEqualSizedClasses(
     OWLClass cl, Set<OWLClass> reasonerSuperClasses, Set<String> superClasses, Jedis idReader)
     throws Exception {
   // compare each element of these 2 sets
   boolean print = false;
   for (OWLClass scl : reasonerSuperClasses) {
     String sclID = conceptToID(scl.toString(), idReader);
     if (!superClasses.contains(sclID)) {
       print = true;
       System.out.print(cl.toString() + " -e- " + scl.toString());
       System.out.print("  ,  ");
     }
   }
   if (print) System.out.println("\n");
 }
Beispiel #2
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));
 }
 public String[] searchOntology(String term, String ontofilepath, String type) {
   OWLAccessorImpl owlapi = new OWLAccessorImpl(new File(ontofilepath));
   List<OWLClass> matches = owlapi.retrieveConcept(term);
   Iterator<OWLClass> it = matches.iterator();
   String[] result = null;
   while (it.hasNext()) {
     OWLClass c = it.next();
     String label = owlapi.getLabel(c);
     if (label.compareToIgnoreCase(term) == 0) {
       result = new String[3];
       result[0] = type;
       result[1] =
           c.toString()
               .replaceFirst("http.*?(?=(PATO|TAO)_)", "")
               .replaceFirst("_", ":")
               .replaceFirst(">$", "");
       result[2] = label;
       return result;
     }
   }
   it = matches.iterator();
   result = new String[] {"", "", ""};
   while (it.hasNext()) {
     OWLClass c = it.next();
     String label = owlapi.getLabel(c);
     result[0] = type;
     result[1] +=
         c.toString()
                 .replaceFirst(".*http.*?(?=(PATO|TAO)_)", "")
                 .replaceFirst("_", ":")
                 .replaceFirst(">$", "")
             + ";";
     result[2] += label + ";";
   }
   if (result != null) {
     result[1] = result[1].replaceFirst(";$", "");
     result[2] = result[2].replaceFirst(";$", "");
   }
   return result;
 }
Beispiel #4
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 #5
0
 private void compareAndPrintUnEqualSizedIndividuals(
     OWLClass cl,
     Set<OWLNamedIndividual> reasonerInstances,
     Set<String> computedInstances,
     Jedis idReader)
     throws Exception {
   // compare each element of these 2 sets
   boolean print = false;
   for (OWLNamedIndividual scl : reasonerInstances) {
     String sclID = conceptToID(scl.toString(), idReader);
     if (!computedInstances.contains(sclID)) {
       print = true;
       System.out.print(cl.toString() + " -ne- " + scl.toString());
       System.out.print("  ,  ");
     }
     computedInstances.remove(sclID);
   }
   for (String s : computedInstances)
     System.out.println("\t -- " + Util.idToConcept(s, idReader) + "(" + s + ")");
   System.out.println();
 }
Beispiel #6
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb
  * .owlapi.model.OWLClass)
  */
 @Override
 public void visit(OWLClass axiom) {
   sb.append(print(axiom.toString()));
 }
Beispiel #7
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);
  }