Package org.semanticweb.owl.model

Examples of org.semanticweb.owl.model.OWLOntologyManager


    String rParameter = "";
    String iParameter = "";
    String approximationConfig = "";
    for (int i = 0; i < noRestarts; i++)
    {
      OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
      OWLOntology tboxOntology = null, aboxOntology = null;

      URI aboxLogicalURI = null;
      try
      {
        aboxOntology = manager
            .loadOntologyFromPhysicalURI(aboxPhysicalURI);
        aboxLogicalURI = aboxOntology.getURI();
      } catch (OWLOntologyCreationException e)
      {
        e.printStackTrace();
        System.exit(0);
      }

      URI tboxLogicalURI = null;
      try
      {
        tboxOntology = manager.loadOntology(tboxPhysicalURI);
        tboxLogicalURI = tboxOntology.getURI();
      } catch (OWLOntologyCreationException e)
      {
        e.printStackTrace();
        System.exit(0);
      }

      VocabularyManager vocabularyManager = new VocabularyManager(
          tboxOntology);
      Set<OWLClass> concepts = vocabularyManager.getConceptSet();
      Set<OWLProperty<?, ?>> properties = new HashSet<OWLProperty<?, ?>>();

      manager.removeOntology(tboxLogicalURI);
      manager.removeOntology(aboxLogicalURI);

      StepSizeStrategy stepSizeStrategy = StrategyFactory
          .newStepSizeStrategy(stepSizeStrategyID, concepts.size());
      /*
       * SelectionStrategy selectionStrategy = StrategyFactory
View Full Code Here


    String rParameter = "";
    String iParameter = "";
    String approximationConfig = "";
    for (int i = 0; i < noRestarts; i++)
    {
      OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
      OWLOntology tboxOntology = null, aboxOntology = null;

      URI aboxLogicalURI = null;
      try
      {
        aboxOntology = manager
            .loadOntologyFromPhysicalURI(aboxPhysicalURI);
        aboxLogicalURI = aboxOntology.getURI();
      } catch (OWLOntologyCreationException e)
      {
        e.printStackTrace();
        System.exit(0);
      }

      URI tboxLogicalURI = null;
      try
      {
        tboxOntology = manager.loadOntology(tboxPhysicalURI);
        tboxLogicalURI = tboxOntology.getURI();
      } catch (OWLOntologyCreationException e)
      {
        e.printStackTrace();
        System.exit(0);
      }

      VocabularyManager vocabularyManager = new VocabularyManager(
          tboxOntology);
      Set<OWLClass> concepts = vocabularyManager.getConceptSet();
      Set<OWLProperty<?, ?>> properties = new HashSet<OWLProperty<?, ?>>();

      manager.removeOntology(tboxLogicalURI);
      manager.removeOntology(aboxLogicalURI);

      SelectionStrategy selectionStrategyCopy = new TrivialStrategy(
          selectionStrategy.getConceptsSet(), properties,
          StrategyFactory.newStepSizeStrategy("EqualParts",
              selectionStrategy.getConceptsSet().size()),
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

  private RunResult runFullOntology(URI tboxURI, URI aboxURI,
      Set<OWLClass> classes, Set<OWLProperty<?, ?>> properties)
      throws OWLReasonerException
  {
    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
        .size(), properties.size());
    result.setClassificationTime(classificationTime);
View Full Code Here

        getConsumer().addOntology(object);
        if (!schemaImportsURIs.contains(object)) {
            OWLImportsDeclaration importsDeclaration = getDataFactory().getOWLImportsDeclarationAxiom(getConsumer().getOntology(),
                                                                                                      object);
            addAxiom(importsDeclaration);
            OWLOntologyManager man = getConsumer().getOWLOntologyManager();
            man.makeLoadImportRequest(importsDeclaration);
            getConsumer().importsClosureChanged();
        }
        // We need to think about what we should do when the subject of the imports statement doesn't
        // match the ontology being parsed
//        OWLOntology importing = getConsumer().getOWLOntologyManager().getOntology(subject);
View Full Code Here

      remainingConcepts.removeAll(auxiliarySelection);
      auxiliarySelection.clear();

    } else
    {
      OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
      OWLOntology tbox = null, abox = null;
      try
      {
        tbox = manager.loadOntology(tboxURI);
        abox = manager.loadOntology(aboxURI);
      } catch (OWLOntologyCreationException e)
      {
        e.printStackTrace();
        System.exit(0);
      }
View Full Code Here

  public IndividualsStrategy(Set<OWLClass> v, Set<OWLProperty<?, ?>> p, StepSizeStrategy s, URI tboxURI, URI aboxURI)
  {
    super(v, p, s);
   
    // Compute the ordered list of classes
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
   
    OWLOntology tbox = null, abox = null;
    try {
     
      tbox = manager.loadOntology(tboxURI);
      abox = manager.loadOntology(aboxURI);
     
      // Compute the number of direct individuals for each class
      for (OWLClass owlClass : v)
      {
        hashClasses.put(owlClass, 1.0 * owlClass.getIndividuals(abox).size());
      }
     
      manager.removeOntology(tboxURI);
      manager.removeOntology(aboxURI);
    }
    catch(OWLOntologyCreationException e)
    {
      e.printStackTrace();
    }
View Full Code Here

    assert (index == n);

    // // compute matrix S = H + A

    // Compute the ordered list of classes
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    OWLOntology tbox = null;
    try {
      tbox = manager.loadOntology(tboxURI);

      // Compute the number of direct subclasses of each class
      for (OWLClass owlClass : v) {
        Set<OWLDescription> superClasses = owlClass
            .getSuperClasses(tbox);

        if (superClasses == null || superClasses.size() == 0) {

//          System.out.println("Concept with NO superClass");

          // add A, hence make the appropriate column equal to 1.0/n
          // for all rows;
          final int j = conceptIndex.get(owlClass);
          final double fraction = 1.0 / n;
          for (int i = 0; i < n; i++)
            S.put(i, j, fraction);

//          System.out.println("Conceptul " + owlClass.getURI()
//              + " nu are superclase.");
//          System.out.println("Ok.");
        } else {

//          System.out.println("Concept with superClass");
          final int j = conceptIndex.get(owlClass);

          // only give credit to superConcepts
          int superClassCount = 0;
          for (OWLDescription superClass : superClasses) {
            if (superClass instanceof OWLClass
                && conceptIndex.get(superClass) != null)
              superClassCount++;
          }

          if (superClassCount > 0) {

            final double fraction = 1.0 / superClassCount;

            for (OWLDescription superClass : superClasses) {
              if (superClass instanceof OWLClass
                  && conceptIndex.get(superClass) != null) {

                S.put(conceptIndex.get(superClass), j,fraction);
              }
            }
          } else {
//            System.out.println("No real superClass.");
            final double fraction = 1.0 / n;
            for (int i = 0; i < n; i++)
              S.put(i, j, fraction);

//            System.out.println("Conceptul " + owlClass.getURI()
//                + " nu are superclase.");
          }
//          System.out.println("Ok.");

        }
      }

      manager.removeOntology(tboxURI);
    } catch (OWLOntologyCreationException e) {
      e.printStackTrace();
    }

    // check property of having each column sum to exactly 1
View Full Code Here

  public ExtendedIndividualsStrategy(Set<OWLClass> v, Set<OWLProperty<?, ?>> p, StepSizeStrategy s, URI tboxURI, URI aboxURI)
  {
    super(v, p, s);
   
    // Compute the ordered list of classes
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
   
    OWLOntology tbox = null, abox = null;
    try {
     
      tbox = manager.loadOntology(tboxURI);
      abox = manager.loadOntology(aboxURI);
     
      // Compute the number of direct individuals for each class
      for (OWLClass owlClass : v)
      {
        fillScores(owlClass, 1.0 * owlClass.getIndividuals(abox).size(), tbox, MAX_STEP);
      }
     
      manager.removeOntology(tboxURI);
      manager.removeOntology(aboxURI);
    }
    catch(OWLOntologyCreationException e)
    {
      e.printStackTrace();
    }
View Full Code Here

  public AllLinksIndividualsStrategy(Set<OWLClass> v, Set<OWLProperty<?, ?>> p, StepSizeStrategy s, URI tboxURI, URI aboxURI)
  {
    super(v, p, s);
   
    // Compute the ordered list of classes
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
   
    OWLOntology tbox = null, abox = null;
    try {
     
      tbox = manager.loadOntology(tboxURI);
      abox = manager.loadOntology(aboxURI);
     
      // Compute the number of direct individuals for each class
      for (OWLClass owlClass : v)
      {
        fillScores(owlClass, 1.0 * owlClass.getIndividuals(abox).size(), tbox, MAX_STEP);
      }
     
      manager.removeOntology(tboxURI);
      manager.removeOntology(aboxURI);
    }
    catch(OWLOntologyCreationException e)
    {
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of org.semanticweb.owl.model.OWLOntologyManager

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.