Package org.semanticweb.owl.model

Examples of org.semanticweb.owl.model.OWLOntologyManager


    }
  }
 
  private OWLOntology loadOntology(URI uri){
    OWLOntology ontology = null;
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    try{
      ontology = manager.loadOntologyFromPhysicalURI(uri);
      return ontology;
    }catch (OWLOntologyCreationException e) {
      this.logger.error(e);
      return null;
    }   
View Full Code Here


      System.exit(-1);
   
   
    initLogger("ontologysplit.log");
   
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
   
    readOntologyList(args[0]);
   
    for (InputOntology inputOnt : inputOntologies){
      ontologyURI = inputOnt.getUri();
      String prefix = inputOnt.getName();
     
      tboxURI = URI.create("file:/Users/tonga/Tmp/OntologySplit/"+prefix+"-Tbox.owl");
      aboxURI = URI.create("file:/Users/tonga/Tmp/OntologySplit/"+prefix+"-Abox.owl");
     
      try {
        ontology = manager.loadOntology(ontologyURI);
       
        /* Print ontology's metrics */
        printMetrics(ontology, manager);

        logger.info("Splitting ontology "+ontologyURI);
        System.out.println("Splitting ontology "+ontologyURI);
       
        if (args[1].compareToIgnoreCase("1") == 0){
          splitOntologyOWLIndividualAxiom(ontology, tboxURI, aboxURI);
        }
        if (args[1].compareToIgnoreCase("2") == 0){
          splitOntologyOWLClassAssertionAxiom(ontology, tboxURI, aboxURI);
        }
        logger.info("---------------------------------------------------------------");
       
        manager.removeOntology(ontologyURI);
       
      } catch (OWLOntologyCreationException e) {
        logger.error(e);
        logger.info("---------------------------------------------------------------");
      }
View Full Code Here

   * @author Gaston Tagni
   *    * */
  private static void splitOntologyOWLIndividualAxiom(OWLOntology ontology, URI tboxURI, URI aboxURI){
    logger.info("Splitting based on OWLIndividualAxiom");
    try{
      OWLOntologyManager tboxMgr = OWLManager.createOWLOntologyManager();
      OWLOntologyManager aboxMgr = OWLManager.createOWLOntologyManager();
     
      // Create two ontologies: Tbox and Abox
      OWLOntology tbox = tboxMgr.createOntology(tboxURI);
      OWLOntology abox = aboxMgr.createOntology(aboxURI);
   
      Set<OWLLogicalAxiom> axioms = ontology.getLogicalAxioms();
      logger.info("Number of logical axioms: "+axioms.size());
      for (OWLLogicalAxiom axiom : axioms){
        if (axiom instanceof OWLIndividualAxiom){
          // put it in abox
          AddAxiom axiomToAdd = new AddAxiom(abox,axiom);
          aboxMgr.applyChange(axiomToAdd);
          //logger.info("To Abox: "+axiom.getClass());
        }else{
          // put it in tbox
          AddAxiom axiomToAdd = new AddAxiom(tbox,axiom);
          tboxMgr.applyChange(axiomToAdd);
          //logger.info("To Tbox: "+axiom.getClass()+" "+axiom.toString());
        }
      }
      tboxMgr.saveOntology(tbox);
      aboxMgr.saveOntology(abox);
     
      /* Remove all class axioms from the Abox that where added by the OWLManager */
      //abox = aboxMgr.getOntology(abox.getURI());
     
     
View Full Code Here

   * @author Giorgios Karafotias
   * */
  private static void splitOntologyOWLClassAssertionAxiom(OWLOntology ontology, URI tboxURI, URI aboxURI){
    logger.info("Splitting based on OWLClassAssertionAxiom");
    try{
      OWLOntologyManager tboxMgr = OWLManager.createOWLOntologyManager();
      OWLOntologyManager aboxMgr = OWLManager.createOWLOntologyManager();
     
      // Create two ontologies: Tbox and Abox
      OWLOntology tbox = tboxMgr.createOntology(tboxURI);
      OWLOntology abox = aboxMgr.createOntology(aboxURI);
   
      Set<OWLLogicalAxiom> axioms = ontology.getLogicalAxioms();
      logger.info("Number of logical axioms: "+axioms.size());
      for (OWLLogicalAxiom axiom : axioms){
        if (axiom instanceof OWLClassAssertionAxiom){
          // put it in abox
          AddAxiom axiomToAdd = new AddAxiom(abox,axiom);
          aboxMgr.applyChange(axiomToAdd);
        }else{
          // put it in tbox
          AddAxiom axiomToAdd = new AddAxiom(tbox,axiom);
          tboxMgr.applyChange(axiomToAdd);       
        }
      }
      tboxMgr.saveOntology(tbox);
      aboxMgr.saveOntology(abox);
    }catch(OWLOntologyCreationException e){logger.error(e);}
     catch(OWLOntologyChangeException e){logger.error(e);}
     catch(OWLOntologyStorageException e){logger.error(e);}
  }
View Full Code Here

      System.out.println("\t target: URI of resulting ontology");
    }
  }

  private static boolean populate(URI uri, int instances, URI outputFile){
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = loadOntology(manager, uri);
    if (ontology != null){
      try {
        OWLDataFactory factory = manager.getOWLDataFactory();
        VocabularyManager vManager = new VocabularyManager(ontology);
        List<OWLClass> classes = new Vector<OWLClass>(vManager.getConceptSet());
       
        List<OWLAxiomChange> toAdd = new Vector<OWLAxiomChange>();
        for (int i = 0; i < instances; i++) {
          int rnd = m_random.nextInt(classes.size());
          OWLClassAssertionAxiom newAxiom = factory.getOWLClassAssertionAxiom(newIndividual(factory), classes.get(rnd));
          toAdd.add(new AddAxiom(ontology,newAxiom))
          System.out.println((i+1)+"- new axiom: "+newAxiom.toString());
        }       
        manager.applyChanges(toAdd);
        OutputStreamWriter sw = new FileWriter(new File(outputFile));
        OWLOntologyOutputTarget target = new WriterOutputTarget(sw);
        manager.saveOntology(ontology, target);
        return true;
      } catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        return false;
      } catch (IOException e) {
        e.printStackTrace();
        return false;
      } catch (OWLOntologyStorageException e) {
        e.printStackTrace();
        return false;
      } finally{
        manager.removeOntology(ontology.getURI());
        manager = null;
      }
    }
    return false;
  }
View Full Code Here

 
  @Override
  public void run(URI tBoxPhysicalURI, String outputCSVFile)
  {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
   
    Vector<ConceptMetric> metrics = ConceptManager.getMetrics();
   
    Logger logger = Logger.getLogger(Processor.class.getName());
   
    logger.info("Ontology: " + tBoxPhysicalURI.toString());
   
    OWLOntology tboxOntology;
    try
    {
      // load the ontology using the ontology manager
      // we need only classes (concepts) from it
      tboxOntology = manager.loadOntologyFromPhysicalURI(tBoxPhysicalURI);
      VocabularyManager vManager = new VocabularyManager(tboxOntology);
     
      CSVFileWriter out = new CSVFileWriter(outputCSVFile, ',');
      Vector<String> fields = new Vector<String>();
      fields.add("Concept name");
View Full Code Here

    double instanceRetrievalTime = 0;

    /* Stores the set of instances of every class */
    HashMap<OWLClass, Set<OWLIndividual>> complete = new HashMap<OWLClass, Set<OWLIndividual>>();

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    OWLOntology tbox = null;
    OWLOntology abox = null;
    try
    {
      tbox = manager.loadOntologyFromPhysicalURI(tboxPhysicalURI);
      abox = manager.loadOntologyFromPhysicalURI(aboxPhysicalURI);

      VocabularyManager vManager = new VocabularyManager(tbox);
      Set<OWLClass> classes = vManager.getConceptSet();
     
      Set<OWLProperty<?, ?>> properties = new HashSet<OWLProperty<?, ?>>();

      logger.info("Selected vocabulary subset: ");
      int cCounter = 1;
      for (OWLClass owlClass : classes)
      {
        logger.info("Concept " + cCounter + ": " + owlClass.getURI());
        cCounter++;
      }
      logger.info("Selected property subset: ");
      int pCounter = 1;
      for (OWLProperty<?, ?> owlProperty : properties)
      {
        logger.info("Property " + pCounter + ": "
            + owlProperty.getURI());
        pCounter++;
      }
      logger.info("");

      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;

    } catch (OWLOntologyCreationException e)
View Full Code Here

        .concat(secondPart));
  }

  private void saveOntology(OWLOntology ontology, URI physicalURI)
  {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    SimpleURIMapper mapper = new SimpleURIMapper(ontology.getURI(),
        physicalURI);
    manager.addURIMapper(mapper);

    try
    {
      manager.saveOntology(ontology, new RDFXMLOntologyFormat(),
          physicalURI);
    } catch (UnknownOWLOntologyException e)
    {
    } catch (OWLOntologyStorageException e)
    {
View Full Code Here

        maxID = currentID;
      }
    }
    try
    {
      OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
      OWLOntology tboxOntology = null, aboxOntology = null;
      try
      {
        // load the Tbox and Abox
        tboxOntology = manager.loadOntology(tboxPhysicalURI);
        aboxOntology = manager
            .loadOntologyFromPhysicalURI(aboxPhysicalURI);
      } catch (OWLOntologyCreationException e)
      {
        e.printStackTrace();
        System.exit(0);
View Full Code Here

  }

  private ArrayList<OWLClass> getStartingPoint(URI tboxPhysicalURI,
      URI aboxPhysicalURI, int method, String ontology)
  {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology tboxOntology = null, aboxOntology = null;
    try
    {
      // load the Tbox and Abox
      tboxOntology = manager.loadOntology(tboxPhysicalURI);
      aboxOntology = manager.loadOntologyFromPhysicalURI(aboxPhysicalURI);
    } catch (OWLOntologyCreationException e)
    {
      e.printStackTrace();
      System.exit(0);
    }
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.