Ejemplo n.º 1
0
 @Override
 protected boolean exec() {
   Timer t = new Timer();
   if (ontology == null) {
     lSigExtractor = null;
     return true;
   }
   if (integrateRangesFirst) {
     OWLNormalization4MORe normalization =
         new OWLNormalization4MORe(ontology, true, false, false);
     Set<OWLAxiom> axioms = normalization.getNormalizedOntology();
     try {
       OWLOntologyManager manager = ontology.getOWLOntologyManager();
       ontology = manager.createOntology();
       manager.addAxioms(ontology, axioms);
     } catch (OWLOntologyCreationException e) {
       e.printStackTrace();
       lSigExtractor = null;
       return true;
     }
   }
   lSigExtractor.findLsignature(ontology, fragment);
   if (!integrateRangesFirst) stats.updateNelkAxioms(lSigExtractor.nAxiomsInFragment());
   Logger_MORe.logDebug(
       t.duration() + "s to find Lsignature with integrateRangesFirst=" + integrateRangesFirst);
   return true;
 }
Ejemplo n.º 2
0
 public LsignatureExtractorViaInverseRewritingLauncher(
     OWLOntology ontology, LogicFragment fragment) {
   this.ontology = null;
   try {
     manager = ontology.getOWLOntologyManager();
     this.ontology = manager.createOntology();
     manager.addAxioms(this.ontology, ontology.getAxioms());
   } catch (OWLOntologyCreationException e) {
     e.printStackTrace();
   }
   this.fragment = fragment;
 }
Ejemplo n.º 3
0
 public LsignatureExtractorLauncher(
     OWLOntology ontology, LogicFragment fragment, boolean integrateRangesFirst) {
   this.ontology = null;
   try {
     OWLOntologyManager manager = ontology.getOWLOntologyManager();
     this.ontology = manager.createOntology();
     manager.addAxioms(this.ontology, ontology.getAxioms());
   } catch (OWLOntologyCreationException e) {
     e.printStackTrace();
   }
   this.fragment = fragment;
   this.integrateRangesFirst = integrateRangesFirst;
 }
Ejemplo n.º 4
0
  private String parseWithOWLAPI(
      URL ontologyURL,
      boolean useOWLAPI,
      boolean considerImportedOntologies,
      boolean considerImportedClosure,
      boolean useReasoner)
      throws OWLOntologyCreationException, OWLOntologyStorageException, URISyntaxException {
    String result = "";

    if (useOWLAPI) {
      OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

      OWLOntology ontology = manager.loadOntology(IRI.create(ontologyURL.toString()));

      if (considerImportedClosure || considerImportedOntologies) {
        Set<OWLOntology> setOfImportedOntologies = new HashSet<OWLOntology>();
        if (considerImportedOntologies) {
          setOfImportedOntologies.addAll(ontology.getDirectImports());
        } else {
          setOfImportedOntologies.addAll(ontology.getImportsClosure());
        }
        for (OWLOntology importedOntology : setOfImportedOntologies) {
          manager.addAxioms(ontology, importedOntology.getAxioms());
        }
      }

      if (useReasoner) {
        ontology = parseWithReasoner(manager, ontology);
      }

      StringDocumentTarget parsedOntology = new StringDocumentTarget();

      manager.saveOntology(ontology, new RDFXMLOntologyFormat(), parsedOntology);
      result = parsedOntology.toString();
    }

    return result;
  }
Ejemplo n.º 5
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));
  }
Ejemplo n.º 6
0
  public OWLOntology findLsignature(
      OWLOntology ontology, LogicFragment fragment, Statistics stats) {
    Timer t = new Timer();
    this.stats = stats;
    Logger_MORe.logInfo("extracting " + fragment.toString() + "-signature");
    OWLOntology ret = null;
    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    try {
      ret = manager.createOntology();
      manager.addAxioms(ret, ontology.getAxioms());
    } catch (OWLOntologyCreationException e) {
      e.printStackTrace();
    }
    lSignatureClasses = new HashSet<OWLClass>();
    lSignatureOther = new HashSet<OWLEntity>();
    compSignatureClasses = new HashSet<OWLClass>();
    compSignatureOther = new HashSet<OWLEntity>();

    LsignatureExtractorLauncher elkSignatureExtractorLauncher = null;
    LsignatureExtractorLauncher elkSignatureExtractorIntegratingRangesLauncher = null;
    LsignatureExtractorViaInverseRewritingLauncher elkSignatureExtractorRewritingInversesLauncher =
        null;

    ForkJoinPool executor = new ForkJoinPool();
    elkSignatureExtractorLauncher =
        new LsignatureExtractorLauncher(ontology, LogicFragment.ELK, false);
    executor.execute(elkSignatureExtractorLauncher);

    if (ret != null) {
      // otherwise we have nowhere to return the axioms in the normalised ontologies necessary to
      // really classify all the extra classses in the lSignature
      if (rewriteInverses) {
        elkSignatureExtractorRewritingInversesLauncher =
            new LsignatureExtractorViaInverseRewritingLauncher(ontology, LogicFragment.ELK);
        executor.execute(elkSignatureExtractorRewritingInversesLauncher);
      }
      if (integrateRanges) {
        elkSignatureExtractorIntegratingRangesLauncher =
            new LsignatureExtractorLauncher(ontology, LogicFragment.ELK, true);
        executor.execute(elkSignatureExtractorIntegratingRangesLauncher);
      }

      // check the output of the normal ELKsignature and cancel the other threads if the lSig is the
      // whole signature
      initialiseLsignature((LsignatureExtractor) elkSignatureExtractorLauncher.join());

      if (compSignatureClasses.isEmpty())
        cancelTasks(
            elkSignatureExtractorIntegratingRangesLauncher,
            elkSignatureExtractorRewritingInversesLauncher);
      else {
        if (elkSignatureExtractorRewritingInversesLauncher != null
            && extendLsignature(
                    (LsignatureExtractor) elkSignatureExtractorRewritingInversesLauncher.join())
                > 0) {
          manager.addAxioms(
              ret,
              ((LsignatureExtractorViaInverseRewritingLauncher)
                      elkSignatureExtractorRewritingInversesLauncher)
                  .getOntology()
                  .getAxioms());
        }
        if (compSignatureClasses.isEmpty())
          cancelTasks(elkSignatureExtractorRewritingInversesLauncher);
        else if (elkSignatureExtractorIntegratingRangesLauncher != null
            && extendLsignature(
                    (LsignatureExtractor) elkSignatureExtractorIntegratingRangesLauncher.join())
                > 0) {
          manager.addAxioms(
              ret,
              ((LsignatureExtractorLauncher) elkSignatureExtractorIntegratingRangesLauncher)
                  .getOntology()
                  .getAxioms());
        }
      }
      stats.updateLsignatureSize(lSignatureClasses.size(), true);
    } else {
      ret = ontology;
      initialiseLsignature((LsignatureExtractor) elkSignatureExtractorLauncher.join());
    }

    Logger_MORe.logInfo(lSignatureClasses.size() + "classes in lSignature");
    Logger_MORe.logDebug(lSignatureClasses.toString());
    Logger_MORe.logInfo(compSignatureClasses.size() + "classes in compSignature");

    // might be a good idea to try to isolate extra axioms in the normalisation/rewriting - is this
    // possible/worth the effort?
    // check the order in which we try to extend the lSignature with each of the rewritten
    // ontologies and consider if one may be better that the other
    Logger_MORe.logDebug(t.duration() + "s to find Lsignature");

    return ret;
  }
Ejemplo n.º 7
0
    @Override
    protected boolean exec() {
      Timer t = new Timer();
      if (ontology == null) {
        extractor = null;
        return true;
      }
      IRI iri =
          IRI.create("http://www.cs.ox.ac.uk/isg/tools/MORe/ontologies/inverseRewritingModule.owl");
      extractor.findLsignature(ontology, LogicFragment.SHOIQ);
      if (containsNonInternalClasses(
          extractor
              .getCompSignature())) { // then the ontology goes beyond SHOIQ and we need to work
        // with a SHOIQ module rather than the whole ontology
        Set<OWLEntity> aux = getNonInternalClasses(extractor.getLsignature());
        if (aux.isEmpty()) {
          extractor = null;
          Logger_MORe.logDebug(
              t.duration()
                  + "s to find Lsignature with inverseRewriting (failed - empty SHOIQ-signature)");
          return true;
        }
        SyntacticLocalityModuleExtractor moduleExtractor =
            new SyntacticLocalityModuleExtractor(manager, ontology, ModuleType.BOT);
        try {
          //					ontology = manager.createOntology(iri);
          //					manager.addAxioms(ontology, moduleExtractor.extract(aux));
          ontology = moduleExtractor.extractAsOntology(aux, iri);
        } catch (OWLOntologyCreationException e1) {
          extractor = null;
          e1.printStackTrace();
          Logger_MORe.logDebug(
              t.duration()
                  + "s to find Lsignature with inverseRewriting (failed - exception creating a SHOIQ module)");
          return true;
        }
      }

      // if we get this far then we have a nonempty ontology (maybe module) that we need to
      // normalize and then rewrite
      OWLNormalization4MORe normalization = new OWLNormalization4MORe(ontology, true, true, true);
      Rewriter rewriter =
          new Rewriter(normalization.getNormalizedOntology(), normalization.getSortedGCIs());
      if (manager.contains(iri)) manager.removeOntology(ontology);
      Set<OWLAxiom> rewrittenAxioms = rewriter.getRewrittenOntology();
      if (!rewriter.anyRewrittenRoles()) {
        extractor = null;
        Logger_MORe.logDebug(
            t.duration()
                + "s to find Lsignature with inverseRewriting (failed - could not rewrite any roles)");
        return true;
      }
      try {
        ontology = manager.createOntology();
        manager.addAxioms(ontology, rewrittenAxioms);
        extractor = new LsignatureExtractor_reducedGreedyness();
        extractor.findLsignature(ontology, fragment);
      } catch (OWLOntologyCreationException e1) {
        extractor = null;
        e1.printStackTrace();
        Logger_MORe.logDebug(
            t.duration()
                + "s to find Lsignature with inverseRewriting (failed - exception creating ontology for rewritten axioms)");
        return true;
      }
      Logger_MORe.logDebug(t.duration() + "s to find Lsignature with inverseRewriting");
      return true;
    }