Esempio n. 1
0
  private void getPelletIncrementalClassifierRunTime(String baseOnt, String ontDir)
      throws Exception {
    System.out.println("Using Pellet Incremental Classifier...");
    GregorianCalendar start = new GregorianCalendar();
    File ontFile = new File(baseOnt);
    IRI documentIRI = IRI.create(ontFile);
    OWLOntology baseOntology = OWL.manager.loadOntology(documentIRI);
    IncrementalClassifier classifier = new IncrementalClassifier(baseOntology);
    classifier.classify();
    System.out.println("Logical axioms: " + baseOntology.getLogicalAxiomCount());
    System.out.println("Time taken for base ontology (millis): " + Util.getElapsedTime(start));
    File ontDirPath = new File(ontDir);
    File[] allFiles = ontDirPath.listFiles();
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    addTripsBaseOntologies(manager);
    int count = 1;
    for (File owlFile : allFiles) {
      IRI owlDocumentIRI = IRI.create(owlFile);
      OWLOntology ontology = manager.loadOntologyFromOntologyDocument(owlDocumentIRI);
      Set<OWLLogicalAxiom> axioms = ontology.getLogicalAxioms();
      for (OWLLogicalAxiom axiom : axioms)
        OWL.manager.applyChange(new AddAxiom(baseOntology, axiom));

      System.out.println("\nLogical axioms: " + baseOntology.getLogicalAxiomCount());
      System.out.println(count + "  file: " + owlFile.getName());
      //			System.out.println("" + count + "  file: " + owlFile.getName());
      //			GregorianCalendar start2 = new GregorianCalendar();
      classifier.classify();
      //	        System.out.println("Time taken (millis): " +
      //					Util.getElapsedTime(start2));
      manager.removeOntology(ontology);
      count++;
    }
    System.out.println("\nTotal time taken (millis): " + Util.getElapsedTime(start));
  }
Esempio n. 2
0
 private void classifyWithJCEL(OWLOntology ontology) {
   System.out.println("\nUsing jCEL...");
   long startTime = System.nanoTime();
   JcelReasoner jcelReasoner = new JcelReasoner(ontology, false);
   jcelReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
   jcelReasoner.dispose();
   System.out.println("Time taken (secs): " + Util.getElapsedTimeSecs(startTime));
 }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
 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));
 }
Esempio n. 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();
 }
Esempio n. 6
0
  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));
  }
Esempio n. 7
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();
    }
  }
Esempio n. 8
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);
  }