Package org.semanticweb.owl.inference

Examples of org.semanticweb.owl.inference.OWLReasoner


      case 1: reasonerFactory = new PelletReasonerFactory(); break;
      case 2: reasonerFactory = new FaCTPlusPlusReasonerFactory(); break;
      default: reasonerFactory = new PelletReasonerFactory(); break;
    }
   
    OWLReasoner reasoner = reasonerFactory.createReasoner(manager);
   
    logger.info("Reasoner: "+reasonerFactory.getReasonerName());
   
    /* Load Tbox and all imported ontologies */
    reasoner.loadOntologies(Collections.singleton(tbox));
   
    /*  Load Abox into reasoner */
    reasoner.loadOntologies(Collections.singleton(abox));
   
    double time = 0;
    double classificationTime = 0;
   
    /*
    try {
      System.out.println("classify: " + new Benchmark(new TaskClassify(reasoner)));
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
    */
   
    /* Classify the ontology if necessary */
    if (!reasoner.isClassified()){
      Timer timerClassify = timers.startTimer( "classification" );
      reasoner.classify();
      timerClassify.stop();
      classificationTime = timerClassify.getTotal();
    }
   
    /* Maps each class to the number of instances (including direct and indirect) */
    HashMap<OWLClass, Integer> counts = new HashMap<OWLClass, Integer>();
   
    /* Maps each class to the number of direct instances */
    HashMap<OWLClass, Integer> directIndividualsCounts = new HashMap<OWLClass, Integer>();
   
    /* Maps each class to the number of indirect instances */
    HashMap<OWLClass, Integer> indirectIndividualsCounts = new HashMap<OWLClass, Integer>();   
   
    int cumulativeNumberOfInstances = 0;
    int cumulativeNumberOfDirectInstances = 0;
    int cumulativeNumberOfIndirectInstances = 0;
    double instanceRetrievalTime = 0;
   
    for (OWLClass cc : classes){
      allIndividuals = new HashSet<OWLIndividual>();
      directIndividuals = new HashSet<OWLIndividual>();
      timers.createTimer("retrieval");
     
      System.out.println(reasoner.getEquivalentClasses(cc).size());
     
      /* retrieve all individuals of the class (direct and indirect individuals) */
      Timer timerRetrieval = timers.startTimer( "retrieval" );
      allIndividuals = reasoner.getIndividuals(cc, false);
      timerRetrieval.stop();
     
      /* update instance retrieval time */
      instanceRetrievalTime += timerRetrieval.getTotal();
     
      /* retrieve all direct instances of the class */
      directIndividuals = reasoner.getIndividuals(cc, true);   
     
      /* set the number of instances (direct + indirect) of the class */
      counts.put(cc, new Integer(allIndividuals.size()));
     
      /* set the number of direct instances of the class */
      directIndividualsCounts.put(cc, new Integer(directIndividuals.size()));
     
      /* set the number of indirect instances of the class */
      indirectIndividualsCounts.put(cc, new Integer(allIndividuals.size()-directIndividuals.size()));     
     
      complete.put(cc, allIndividuals);
      cumulativeNumberOfInstances += allIndividuals.size();
      cumulativeNumberOfDirectInstances += directIndividuals.size();
      cumulativeNumberOfIndirectInstances += (allIndividuals.size()-directIndividuals.size());
    }
   
    reasoner.clearOntologies();
    reasoner.dispose();
    manager.removeOntology(abox.getURI());
    manager.removeOntology(tbox.getURI());
    reasoner = null;
   
    time = classificationTime + instanceRetrievalTime;
View Full Code Here


      if (approximationResult != null) {
        System.out.println("Creating Tbox approximation "+runCounter);
       
        OWLOntology abox = null;
        OWLOntology approximatedTbox = null;
        OWLReasoner reasoner = null;
        int newIndividualsToAdd = 0;
       
        /* get the approximated Tbox */
        approximatedTbox = approximationResult.approximatedOntology();
     
        if (approximationResult.isOriginal()){
          /* Last run. Use original Abox to compute the baseline run */
          aboxPhysicalURI = originalAboxURI;
        }
       
        /* Load Abox into the manager */
        abox = manager.loadOntologyFromPhysicalURI(aboxPhysicalURI);
        int aboxIndividualAxiomsCount = abox.getIndividualAxioms().size();
         
        if (measureApproximationTime) {
          /* update time with the time it takes to build the Tbox based on the current vocabulary set */
          approximationTime = timerApproximation.getTotal();
        }
     
        //OWLOntology currentTBox2 = approximationResult.approximatedOntology();
       
        /* Create a new physical URI based on the current run */
        URI tboxPhysicalURI = createNewURI(tmpTboxPhysicalURI, runCounter);
        if (saveApproximatedTbox){
          /* Save approximated Tbox to disk - for debugging purposes only */
          saveOntologyToFile(approximatedTbox, tboxPhysicalURI);
        }     
       
        /* Create the reasoner */
        reasoner = reasonerFactory.createReasoner(manager);
        logger.info("Using reasoner: "+reasonerFactory.getReasonerName());
       
        Set<OWLOntology> ontologiesToLoad = new HashSet<OWLOntology>();
        ontologiesToLoad.add(abox);
        ontologiesToLoad.add(approximatedTbox);
       
        /* Load approximated Tbox into the reasoner */
        //reasoner.loadOntologies(ontologiesToLoad);

        /* Load approximated Tbox into reasoner */
        reasoner.loadOntologies(Collections.singleton(approximatedTbox));
       
        /* Print statistics */
        printStatistics(runCounter, approximation, approximatedTbox, abox, aboxPhysicalURI);
       
        /* Classify ontology if needed */
        double classificationTime = 0;
       
        if ( !(reasoner.isClassified()) ){
          logger.info("Classifying KB...");
          Timer timerClassify = timers.startTimer( "classification" );
          reasoner.classify();
          timerClassify.stop();
          classificationTime = timerClassify.getTotal();
        }
       
        /* Load Abox into reasoner */
        reasoner.loadOntologies(Collections.singleton(abox));
         
        /* In each run this variable maps classes to number of instances (direct and indirect) retrieved for that class */
        HashMap<OWLClass, Integer> instancesPerClass = new HashMap<OWLClass, Integer>();
        /* Maps classes to number of direct instances */
        HashMap<OWLClass, Integer> directIndividualsCounts = new HashMap<OWLClass, Integer>();
        /* Maps classes to number of indirect instances */
        HashMap<OWLClass, Integer> indirectIndividualsCounts = new HashMap<OWLClass, Integer>();
       
        /* Total number of direct instances retrieved (among all classes) in the current run */
        int cumulativeDirectInstancesCnt = 0;
       
        /* Total number of indirect instances retrieved (among all classes) in the current run */
        int cumulativeIndirectInstancesCnt = 0;
         
        logger.info("Iterating over "+concepts.size()+" atomic concept names (calculated from original tbox)");
        /* Retrieve Instances from (T', A) */
        for (OWLClass cc : concepts){
          /* In each run this variable contains the instances (direct and indirect) retrieved from a given class */
          Set<OWLIndividual> individuals = new HashSet<OWLIndividual>()
           
          /* In each run this variable contains the instances (direct) retrieved from a given class */
          Set<OWLIndividual> directIndividuals = new HashSet<OWLIndividual>();
           
          /* get all individuals (direct and indirect) of class cc only if the class is defined in the ontology */
          if (reasoner.isDefined(cc)){
            timers.createTimer("retrieval");
            Timer timerRetrieval = timers.startTimer( "retrieval" );
            individuals = reasoner.getIndividuals(cc, false);
            timerRetrieval.stop();
           
            /* get direct individuals only */
            directIndividuals = reasoner.getIndividuals(cc, true);
           
            /* update instance retrieval time */
            instanceRetrievalTime += timerRetrieval.getTotal();
           
            if (individuals.size() > 0){
              logger.info("");
              logger.info("Instance relations found for class "+cc.getURI()+": "+individuals.size()+" (class's retrieval time:"+timerRetrieval.getTotal()+")");
              for (OWLIndividual owli : individuals){
                logger.info(individualCounter+": "+owli.getURI());
                individualCounter++;
              }         
            }
           
          }else{
            //System.out.println("Undefined Concept in Tbox: "+cc);
            logger.info("Undefined Concept in Tbox: "+cc);
          }
           
          /* save the instance relations that were retrieved for the class */
          classInstances.put(cc, individuals);
         
          /* Update number of instances (including direct and indirect) of the current class */
          instancesPerClass.put(cc, new Integer(individuals.size()));
                 
          /* save number of direct and indirect instances of each class */
          directIndividualsCounts.put(cc, new Integer(directIndividuals.size()));
          indirectIndividualsCounts.put(cc, new Integer(individuals.size()-directIndividuals.size()));
         
          if (isInterruptible){
            List<OWLOntologyChange> changesToMake = new Vector<OWLOntologyChange>();
            /* Add instances retrieved in the current run to the current Abox */
            OWLDataFactory factory = manager.getOWLDataFactory();
            timers.createTimer("aboxupdate");
            Timer timerAboxUpdate = timers.startTimer("aboxupdate");
            for (OWLIndividual ci : individuals){
              changesToMake.add(new AddAxiom(abox, factory.getOWLClassAssertionAxiom(ci, cc)));
            }
            List<OWLOntologyChange> actualChangesMade = manager.applyChanges(changesToMake);
            timerAboxUpdate.stop();
            newIndividualsToAdd += actualChangesMade.size();
            aboxUpdateTime = timerAboxUpdate.getTotal();
          }
           
          /* Update total number of direct and indirect instances retrieved in the current run */
          cumulativeDirectInstancesCnt += directIndividuals.size();
          cumulativeIndirectInstancesCnt += (individuals.size()-directIndividuals.size());
        }
         
        time = approximationTime + classificationTime + instanceRetrievalTime + aboxUpdateTime;
       
        /* Save the results of the run */
        rr = new RunResult(instancesPerClass, time, approximation.getCurrentVocabularyConceptSize(), approximation.getCurrentVocabularyPropertySize());
        rr.setIndirectIndividuals(indirectIndividualsCounts);
        rr.setDirectIndividuals(directIndividualsCounts);
        rr.setClassificationTime(classificationTime);
        rr.setAboxUpdateTime(aboxUpdateTime);
        rr.setInstanceRetrievalTime(instanceRetrievalTime);
        rr.setApproximationTime(approximationTime);
        rr.setInstances(classInstances);
        rr.setAxiomRewriteTime(approximationResult.axiomRewriteTime());
        rr.setVocabularySelectionTime(approximationResult.selectionTime());
        rr.setRunNumber(runCounter);
   
        results.addRun(rr);
         
        if (isInterruptible){
          /* Save the modified abox to disk so we can use it in the next iteration */
          /* create the logical URI of the new Abox */
          URI newAboxURI = createNewURI(abox.getURI().toString(), rr.getRunNumber());
          /* create the physical URI of the new Abox */
          URI newAboxPhysicalURI = createNewURI(tmpAboxURI, rr.getRunNumber());
          /* Set up a mapping, which maps the ontology URI to the physical URI */
          SimpleURIMapper mapper = new SimpleURIMapper(newAboxURI, newAboxPhysicalURI);
          manager.addURIMapper(mapper);
         
          /* Create a new Abox to store the newly inferred instance relations and the Abox used in the current run */
          modifiedAbox = manager.createOntology(newAboxURI);
          manager.addAxioms(modifiedAbox, abox.getAxioms());
         
          /* Save the modified Abox */
          manager.saveOntology(modifiedAbox, newAboxPhysicalURI);
           
          /* update physical URI of the next Abox to use */
          aboxPhysicalURI = newAboxPhysicalURI;
        }
       
        logger.info("");
        logger.info("#direct instances retrieved in current run: "+cumulativeDirectInstancesCnt);
        logger.info("#indirect instances retrieved in current run: "+cumulativeIndirectInstancesCnt);
        logger.info("#individual axioms in Abox before adding new axioms (anytime): "+aboxIndividualAxiomsCount);
        logger.info("#individual axioms added to the Abox (anytime): "+newIndividualsToAdd);
        if (isInterruptible){
          logger.info("#individual axioms in Abox after adding new axioms (anytime): "+modifiedAbox.getIndividualAxioms().size());
        }
        logger.info("Iteration runtime (ms): "+time);
        logger.info("Instance Retrieval Time (ms): "+instanceRetrievalTime);
        logger.info("Classification Time (ms): "+classificationTime);
        logger.info("Approximation Time (includes axiom rewriting and vocabulary selection time) (ms): "+approximationTime);
        logger.info("Axiom rewriting Time (ms): "+approximationResult.axiomRewriteTime());
        logger.info("Vocabulary selection Time (ms): "+approximationResult.selectionTime());
        logger.info("Abox Update Time (for incremental case only) (ms): "+aboxUpdateTime);
        logger.info("Iteration runtime (runtime-approximationTime-aboxUpdateTime) (ms): "+(time-approximationTime-aboxUpdateTime));
        logger.info("Tbox's Logical URI: "+approximatedTbox.getURI());
        logger.info("Abox's Physical URI: "+aboxPhysicalURI);
        logger.info("Abox's Logical URI: "+abox.getURI());
        logger.info("======================================================");
        logger.info("");
       
        /* Remove approximated Tbox and Abox from reasoner */
        reasoner.unloadOntologies(Collections.singleton(approximatedTbox));
        reasoner.unloadOntologies(Collections.singleton(abox));
        reasoner.dispose();
        /* Remove Abox from manager */
        manager.removeOntology(abox.getURI());
        manager = null;
        reasoner = null;
       
View Full Code Here

      org.mindswap.pellet.utils.Timers timers = new Timers();
     
      timers.createTimer("classification");

      /* Create the reaosner */
      OWLReasoner reasoner = reasonerFactory.createReasoner(manager);

      System.out
          .println("Classifying and retrieving instance relations...");
      this.logger
          .info("Classifying and retrieving instance relations...");
      this.logger.info("Using reasoner: "
          + reasonerFactory.getReasonerName());

      /* Load Tbox into reasoner */
      reasoner.loadOntologies(Collections.singleton(tbox));

      /* Load Abox into reasoner */
      // reasoner.loadOntologies(Collections.singleton(abox));
      /* Classify the ontology if necessary */
      if (!reasoner.isClassified())
      {
        /* Measure time using Benchmarking framework */
        Timer timerClassify = timers.startTimer("classification");
        reasoner.classify();
        timerClassify.stop();
        classificationTime = timerClassify.getTotal();
      }

      /* Load Abox into reasoner */
      reasoner.loadOntologies(Collections.singleton(abox));
      if (!reasoner.isClassified())
      {
        reasoner.classify();
      }

      /*
       * Maps each class to the number of instances (including direct and
       * indirect)
       */
      HashMap<OWLClass, Integer> allIndividualsCounts = new HashMap<OWLClass, Integer>();

      /* Maps each class to the number of direct instances */
      HashMap<OWLClass, Integer> directIndividualsCounts = new HashMap<OWLClass, Integer>();

      /* Maps each class to the number of indirect instances */
      HashMap<OWLClass, Integer> indirectIndividualsCounts = new HashMap<OWLClass, Integer>();

      int individualCounter = 1;

      for (OWLClass cc : classes)
      {
        allIndividuals = new HashSet<OWLIndividual>();
        directIndividuals = new HashSet<OWLIndividual>();

        if (reasoner.isDefined(cc))
        {
          /*
           * retrieve all individuals of the class (direct and
           * indirect individuals)
           */
          timers.createTimer("retrieval");
          Timer timerRetrieval = timers.startTimer("retrieval");
          allIndividuals = reasoner.getIndividuals(cc, false);
          timerRetrieval.stop();

          /* update instance retrieval time */
          instanceRetrievalTime += timerRetrieval.getTotal();

          /* retrieve all direct instances of the class */
          directIndividuals = reasoner.getIndividuals(cc, true);
        } else
        {
          logger.info("Undefined Concept in Tbox: " + cc);
        }

        /* set the number of instances (direct + indirect) of the class */
        allIndividualsCounts
            .put(cc, new Integer(allIndividuals.size()));

        /* set the number of direct instances of the class */
        directIndividualsCounts.put(cc, new Integer(directIndividuals
            .size()));

        /* set the number of indirect instances of the class */
        indirectIndividualsCounts.put(cc, new Integer(allIndividuals
            .size()
            - directIndividuals.size()));

        complete.put(cc, allIndividuals);
        cumulativeNumberOfInstances += allIndividuals.size();
        cumulativeNumberOfDirectInstances += directIndividuals.size();
        cumulativeNumberOfIndirectInstances += (allIndividuals.size() - directIndividuals
            .size());

        /* Log the indirect instances found */
        HashSet<OWLIndividual> difference = new HashSet<OWLIndividual>(
            allIndividuals);
        difference.removeAll(directIndividuals);
        if (difference.size() > 0)
        {
          logger.info("");
          logger.info("Indirect instance relations found for class "
              + cc.getURI() + ": " + difference.size());
          for (OWLIndividual owli : difference)
          {
            logger.info(individualCounter + ": " + owli.getURI());
            individualCounter++;
          }
        }
      }

      time = (classificationTime + instanceRetrievalTime) - loadingTime;
      RunResult result = new RunResult(allIndividualsCounts, time,
          classes.size(), properties.size());
      result.setClassificationTime(classificationTime);
      result.setOntologyLoadingTime(loadingTime);
      result.setDirectIndividuals(directIndividualsCounts);
      result.setIndirectIndividuals(indirectIndividualsCounts);
      result.setInstanceRetrievalTime(instanceRetrievalTime);
      result.setInstances(complete);
      result.setRunNumber(approximationCnt);
      result.setRunType(runType);

      this.logger.info("");
      this.logger.info("#Instance relations: "
          + cumulativeNumberOfInstances);
      this.logger.info("#Direct instances relations retrieved: "
          + cumulativeNumberOfDirectInstances);
      this.logger.info("#Indirect instances relations retrieved: "
          + cumulativeNumberOfIndirectInstances);
      this.logger.info("Runtime (ms): " + time);
      this.logger.info("Classification Time (ms): " + classificationTime);
      this.logger
          .info("Reasoner creation and ontology loading time (ms): "
              + loadingTime);
      this.logger
          .info("Instance Retrieval Time (ms) (approx.: total time - classification time): "
              + instanceRetrievalTime);
      this.logger.info("Tbox URI: " + tboxPhysicalURI);
      this.logger.info("Abox URI: " + aboxPhysicalURI);
      this.logger
          .info("============================================================================================================");

      reasoner.clearOntologies();
     
      reasoner.dispose();
      manager.removeOntology(abox.getURI());
      manager.removeOntology(tbox.getURI());
      reasoner = null;

      return result;
View Full Code Here

      System.out.println("Running Approximation No. " + runCounter);
      OWLReasonerFactory reasonerFactory = new PelletReasonerFactory();
      // OWLReasonerFactory reasonerFactory = new
      // FaCTPlusPlusReasonerFactory();
      OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
      OWLReasoner reasoner = null;

      OWLOntology aboxOntology = null;
      ApproximationResult approximationResult = null;
      OWLOntology approximatedTboxOntology = null;

      HashMap<OWLClass, Integer> allIndividualsCounts = new HashMap<OWLClass, Integer>();
      HashMap<OWLClass, Integer> directIndividualsCounts = new HashMap<OWLClass, Integer>();
      HashMap<OWLClass, Integer> indirectIndividualsCounts = new HashMap<OWLClass, Integer>();

      int cumulativeDirectIndividualsCounts = 0;
      int cumulativeIndirectIndividualsCounts = 0;

      Timers timers = new Timers();

      double classificationTime = 0;
      double approximationTime = 0;
      double instanceRetrievalTime = 0;
      double aboxUpdateTime = 0;
      double time = 0;

      // System.out.println("--->approximating...");
      timers.createTimer("approximation");
      Timer timerApproximation = timers.startTimer("approximation");
      approximationResult = approximation.getNextTBox();
      timerApproximation.stop();
      if (measureApproximationTime)
      {
        approximationTime += timerApproximation.getTotal();
      }

      if (approximationResult != null)
      {
        approximatedTboxOntology = approximationResult
            .approximatedOntology();

        URI tboxPhysicalURI = createURI(tmpTboxPhysicalURI, runCounter);
        if (saveApproximatedTbox)
        {
          saveOntology(approximatedTboxOntology, tboxPhysicalURI);
        }

        // System.out.println("--->classifying...");
        reasoner = reasonerFactory.createReasoner(manager);
        reasoner.loadOntologies(Collections
            .singleton(approximatedTboxOntology));
        timers.createTimer("classification");
        if (!(reasoner.isClassified()))
        {
          Timer timerClassify = timers.startTimer("classification");
          reasoner.classify();
          timerClassify.stop();
          classificationTime += timerClassify.getTotal();
        }

        if (approximationResult.isOriginal())
        {
          aboxPhysicalURI = originalAboxPhysicalURI;
        }

        aboxOntology = manager
            .loadOntologyFromPhysicalURI(aboxPhysicalURI);

        reasoner.loadOntologies(Collections.singleton(aboxOntology));

        // System.out.println("--->retrieving instances...");
        for (OWLClass cc : concepts)
        {
          Set<OWLIndividual> individuals = new HashSet<OWLIndividual>();
          Set<OWLIndividual> directIndividuals = new HashSet<OWLIndividual>();

          if (reasoner.isDefined(cc))
          {
            timers.createTimer("retrieval");
            Timer timerRetrieval = timers.startTimer("retrieval");
            individuals = reasoner.getIndividuals(cc, false);
            timerRetrieval.stop();
            instanceRetrievalTime += timerRetrieval.getTotal();
          }

          directIndividuals = reasoner.getIndividuals(cc, true);
          allIndividualsCounts.put(cc,
              new Integer(individuals.size()));
          directIndividualsCounts.put(cc, new Integer(
              directIndividuals.size()));
          indirectIndividualsCounts.put(cc, new Integer(individuals
              .size()
              - directIndividuals.size()));

          if (isInterruptible)
          {

            List<OWLOntologyChange> changesToMake = new Vector<OWLOntologyChange>();
            OWLDataFactory factory = manager.getOWLDataFactory();
            timers.createTimer("aboxupdate");
            Timer timerAboxUpdate = timers.startTimer("aboxupdate");
            for (OWLIndividual ci : individuals)
            {
              changesToMake.add(new AddAxiom(aboxOntology,
                  factory.getOWLClassAssertionAxiom(ci, cc)));
            }
            timerAboxUpdate.stop();
            aboxUpdateTime += timerAboxUpdate.getTotal();
          }

          cumulativeDirectIndividualsCounts += directIndividuals
              .size();
          cumulativeIndirectIndividualsCounts += (individuals.size() - directIndividuals
              .size());
        }

        time = approximationTime + classificationTime
            + instanceRetrievalTime + aboxUpdateTime;

        /* Save the results of the run */
        runResult = new RunResult(allIndividualsCounts, time,
            approximation.getCurrentVocabularyConceptSize(),
            approximation.getCurrentVocabularyPropertySize());
        runResult.setIndirectIndividuals(indirectIndividualsCounts);
        runResult.setDirectIndividuals(directIndividualsCounts);
        runResult.setClassificationTime(classificationTime);
        runResult.setAboxUpdateTime(aboxUpdateTime);
        runResult.setInstanceRetrievalTime(instanceRetrievalTime);
        runResult.setApproximationTime(approximationTime);
        runResult.setInstances(approximateClassInstances);
        runResult.setAxiomRewriteTime(approximationResult
            .axiomRewriteTime());
        runResult.setVocabularySelectionTime(approximationResult
            .selectionTime());
        runResult.setRunNumber(runCounter);

        if (StrategyManager.getLastSelectionStrategy() != null)
          StrategyManager.getLastSelectionStrategy().feedback(
              runResult);

        results.addRunResult(runResult);

        if (isInterruptible)
        {
          URI newAboxURI = createURI(aboxOntology.getURI(), runResult
              .getRunNumber());
          URI newAboxPhysicalURI = createURI(tmpAboxURI, runResult
              .getRunNumber());
          SimpleURIMapper mapper = new SimpleURIMapper(newAboxURI,
              newAboxPhysicalURI);
          manager.addURIMapper(mapper);

          modifiedAboxOntology = manager.createOntology(newAboxURI);
          manager.addAxioms(modifiedAboxOntology, aboxOntology
              .getAxioms());

          /*
           * System.out.println(newAboxPhysicalURI.toString() + ", " +
           * newAboxURI);
           */

          manager.saveOntology(modifiedAboxOntology,
              newAboxPhysicalURI);
          aboxPhysicalURI = newAboxPhysicalURI;
        }

        reasoner.unloadOntologies(Collections
            .singleton(approximatedTboxOntology));
        reasoner.unloadOntologies(Collections.singleton(aboxOntology));
        reasoner.dispose();
        manager.removeOntology(aboxOntology.getURI());
        manager = null;
        reasoner = null;
        runCounter++;
      } else
View Full Code Here

    System.out.println("Running Full Ontology..." + tboxURI.toString());
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLReasonerFactory reasonerFactory = new PelletReasonerFactory();
    // OWLReasonerFactory reasonerFactory = new
    // FaCTPlusPlusReasonerFactory();
    OWLReasoner reasoner = null;
    OWLOntology tboxOntology = null, aboxOntology = null;

    fullCassIndividuals = new HashMap<OWLClass, Set<OWLIndividual>>();
    Set<OWLIndividual> allIndividuals;
    Set<OWLIndividual> directIndividuals;

    HashMap<OWLClass, Integer> allIndividualsCounts = new HashMap<OWLClass, Integer>();
    HashMap<OWLClass, Integer> directIndividualsCounts = new HashMap<OWLClass, Integer>();
    HashMap<OWLClass, Integer> indirectIndividualsCounts = new HashMap<OWLClass, Integer>();

    int cumulativeIndividualsCount = 0;
    int cumulativeDirectindividualsCount = 0;
    int cumulativeIndirectIndividualsCount = 0;

    Timers timers = new Timers();
    double time = 0;
    double classificationTime = 0;
    double instanceRetrievalTime = 0;

    try
    {
      tboxOntology = manager.loadOntology(tboxURI);
      aboxOntology = manager.loadOntology(aboxURI);

    } catch (OWLOntologyCreationException e)
    {
      e.printStackTrace();
      System.exit(0);
    }

    // System.out.println("--->classifying...");
    reasoner = reasonerFactory.createReasoner(manager);
    reasoner.loadOntologies(Collections.singleton(tboxOntology));
    reasoner.loadOntologies(Collections.singleton(aboxOntology));
    timers.createTimer("classification");

    if (!reasoner.isClassified())
    {
      Timer timerClassify = timers.startTimer("classification");
      reasoner.classify();
      timerClassify.stop();
      classificationTime += timerClassify.getTotal();
    }
    // System.out.println("--->retrieving instances...");
    for (OWLClass cc : classes)
    {
      allIndividuals = new HashSet<OWLIndividual>();
      directIndividuals = new HashSet<OWLIndividual>();
      timers.createTimer("retrieval");
      Timer timerRetrieval = timers.startTimer("retrieval");
      allIndividuals = reasoner.getIndividuals(cc, false);
      timerRetrieval.stop();
      instanceRetrievalTime += timerRetrieval.getTotal();

      fullCassIndividuals.put(cc, allIndividuals);

      directIndividuals = reasoner.getIndividuals(cc, true);

      allIndividualsCounts.put(cc, new Integer(allIndividuals.size()));
      directIndividualsCounts.put(cc, new Integer(directIndividuals
          .size()));
      indirectIndividualsCounts.put(cc, new Integer(allIndividuals.size()
          - directIndividuals.size()));

      cumulativeIndividualsCount += allIndividuals.size();
      cumulativeDirectindividualsCount += directIndividuals.size();
      cumulativeIndirectIndividualsCount += (allIndividuals.size() - directIndividuals
          .size());

    }
    reasoner.clearOntologies();
    reasoner.dispose();
    manager.removeOntology(tboxOntology.getURI());
    manager.removeOntology(aboxOntology.getURI());

    time = classificationTime + instanceRetrievalTime;
    RunResult result = new RunResult(allIndividualsCounts, time, classes
View Full Code Here

    }


    public OWLReasoner createReasoner(OWLOntologyManager manager) {
        try {
            OWLReasoner reasoner = (OWLReasoner) factPPConstructor.newInstance(manager);
            setSynchronisingMethod.invoke(reasoner, Boolean.FALSE);
            return reasoner;
        }
        catch (InstantiationException e) {
            throw new OWLReasonerSetupException(this, e);
View Full Code Here

    }


    private static OWLReasoner createAndLoadReasoner(OWLOntologyManager man, OWLReasonerFactory factory,
                                                     OWLOntology ont) {
        OWLReasoner reasoner = factory.createReasoner(man);
        try {
            reasoner.loadOntologies(man.getImportsClosure(ont));
            return reasoner;
        }
        catch (OWLReasonerException e) {
            throw new OWLRuntimeException(e);
        }
View Full Code Here

TOP

Related Classes of org.semanticweb.owl.inference.OWLReasoner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.