Package nl.vu.few.anytimereasoning.workbench.approximation

Examples of nl.vu.few.anytimereasoning.workbench.approximation.RunResult


      /* Measure reasoner creation and loading time */
      // Tester tester = new Tester(selectReasoner);
      // double loadingTime = tester.measureLoadingTime(tboxPhysicalURI,
      // aboxPhysicalURI);
      /* Classify and retrive instance relations */
      RunResult results = reason(tboxPhysicalURI, aboxPhysicalURI,
          reasonerFactory, 0);

      if (results != null)
      {
        /* Save results to data file */
 
View Full Code Here


          }
        }
      }

      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: "
View Full Code Here

        this.runResults.size() - 1).getTime();
    /* Cumulative time, i.e. sum of the times of every run */
    long cumulativeTime = 0;
    for (int i = 0; i < this.runResults.size(); i++)
    {
      RunResult result = this.runResults.elementAt(i);
      result.setRunType("approximation");
      cumulativeTime += result.getTime();

      int allIndividualsCountApp = result.getAllIndividualsCnt();
      int indirectIndividualsCountApp = 0;
      double cumulativeRecall = 0;
      double cumulativeIndirectRecall = 0;
      double minRecall = 1;
      double maxRecall = 0;
      double minIndirectRecall = Double.MAX_VALUE;
      double maxIndirectRecall = 0;

      for (OWLClass cc : this.fullConceptSet)
      {
        int classAllIndividualsCountApp = result
            .getClassInstanceCnt(cc);
        int classIndirectIndividualsCountApp = result
            .getClassIndirectInstanceCnt(cc);
        if (classIndirectIndividualsCountApp > 0)
        {
          indirectIndividualsCountApp += classIndirectIndividualsCountApp;
        }
        int classAllIndividualsCount = fullRunResult
            .getClassInstanceCnt(cc);
        if (classAllIndividualsCount > 0)
        {
          double currentRecall = 0;
          currentRecall = (double) classAllIndividualsCountApp
              / (double) classAllIndividualsCount;
          cumulativeRecall += currentRecall;
          if (currentRecall > maxRecall)
          {
            maxRecall = currentRecall;
          }
          if (currentRecall < minRecall)
          {
            minRecall = currentRecall;
          }
        }

        int classIndirectIndividualsCount = fullRunResult
            .getClassIndirectInstanceCnt(cc);
        if (classIndirectIndividualsCount > 0)
        {
          double currentIndirectRecall = 0;
          currentIndirectRecall = (double) (classIndirectIndividualsCountApp)
              / (double) classIndirectIndividualsCount;
          cumulativeIndirectRecall += currentIndirectRecall;
          if (currentIndirectRecall > maxIndirectRecall)
          {
            maxIndirectRecall = currentIndirectRecall;
          }
          if (currentIndirectRecall < minIndirectRecall)
          {
            minIndirectRecall = currentIndirectRecall;
          }
        }
      }

      // 1. Average Recall
      double value = 0;
      if (classesWithInstancesCount > 0)
      {
        value = round2Decimals(cumulativeRecall
            / classesWithInstancesCount);
      }
      statistics[i][0] = value;
      // 2. Minimum Recall
      value = round2Decimals(minRecall);

      // 3. Maximum Recall
      value = round2Decimals(maxRecall);

      // 4. Total Recall
      if (allIndividualsCount > 0)
      {
        value = round2Decimals((double) allIndividualsCountApp
            / (double) allIndividualsCount);
      } else
      {
        value = 0;
      }

      // 5. Average Indirect Recall
      if (classesWithIndirectIndividualsCount != 0)
      {
        value = round2Decimals(cumulativeIndirectRecall
            / classesWithIndirectIndividualsCount);
      } else
      {
        value = 0;
      }

      // 6. Minimum Indirect Recall
      if (minIndirectRecall != Double.MAX_VALUE)
      {
        value = round2Decimals(minIndirectRecall);
      } else
      {
        value = 0;
      }

      // 7. Maximum Indirect Recall
      value = round2Decimals(maxIndirectRecall);

      // 8. Total Indirect Recall
      if (indirectIndividualsCount != 0)
      {
        value = round2Decimals((double) indirectIndividualsCountApp
            / (double) indirectIndividualsCount);
      } else
      {
        value = 0;
      }

      // 9. Iteration time = runtime of the incremental step
      // dataOutputStream.writeBytes(result.getTime() + " ");
      statistics[i][1] = result.getTime();

      // 10. Iteration time as fraction of full's time
      value = round2Decimals((double) result.getTime()
          / (double) goldStandardIterationTime);

      // 11. Cumulative time = Sum of times of every run
      // dataOutputStream.writeBytes(cumulativeTime + " ");

      // 12. Cumulative time as percentage of full time
      value = round2Decimals((double) cumulativeTime
          / (double) goldStandardIterationTime);

      // 13. Vocabulary size
      // dataOutputStream.writeBytes(result.getVocabularySize() +
      // " ");

      // 14. Vocabulary size as fraction of full vocabulary
      value = round2Decimals((double) result.getVocabularySize()
          / (double) vocabularySize);

      // 15. Classification time of the current run
      // dataOutputStream.writeBytes(result.getClassificationTime()
      // + " ");
View Full Code Here

      Logger logger = Logger.getLogger(ApproximationTask.class.getName());
      logger.setLevel(Level.OFF);

      try
      {
        RunResult resultsFull = runFullOntology(tboxPhysicalURI,
            aboxPhysicalURI, concepts, properties);

        String xmlFile = filePrefix + rParameter + iParameter + "_"
            + approximation.getConfiguration()
            + "-ApproximationData";
View Full Code Here

      Logger logger = Logger.getLogger(ApproximationTask.class.getName());
      logger.setLevel(Level.OFF);

      try
      {
        RunResult resultsFull = runFullOntology(tboxPhysicalURI,
            aboxPhysicalURI, concepts, properties);

        String xmlFile = filePrefix + rParameter + iParameter + "_"
            + approximation.getConfiguration()
            + "-ApproximationData";
View Full Code Here

      boolean saveApproximatedTbox) throws OWLOntologyStorageException,
      OWLOntologyCreationException, OWLOntologyChangeException,
      OWLReasonerException, UnknownOWLOntologyException
  {
    Map<OWLClass, Set<OWLIndividual>> approximateClassInstances = new HashMap<OWLClass, Set<OWLIndividual>>();
    RunResult runResult;

    URI originalAboxPhysicalURI = aboxPhysicalURI;
    OWLOntology modifiedAboxOntology = null;

    int runCounter = 1;
    while (true)
    {
      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);

View Full Code Here

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

    time = classificationTime + instanceRetrievalTime;
    RunResult result = new RunResult(allIndividualsCounts, time, classes
        .size(), properties.size());
    result.setClassificationTime(classificationTime);
    result.setDirectIndividuals(directIndividualsCounts);
    result.setIndirectIndividuals(indirectIndividualsCounts);
    result.setInstanceRetrievalTime(instanceRetrievalTime);
    result.setInstances(fullCassIndividuals);

    return result;
  }
View Full Code Here

TOP

Related Classes of nl.vu.few.anytimereasoning.workbench.approximation.RunResult

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.