public OWLOntology loadOWLOntology(
      OWLOntologyDocumentSource documentSource, final OWLOntologyCreationHandler mediator)
      throws OWLOntologyCreationException {
    // Attempt to parse the ontology by looping through the parsers.  If the
    // ontology is parsed successfully then we break out and return the ontology.
    // I think that this is more reliable than selecting a parser based on a file extension
    // for example (perhaps the parser list could be ordered based on most likely parser, which
    // could be determined by file extension).
    Map<OWLParser, OWLParserException> exceptions =
        new LinkedHashMap<OWLParser, OWLParserException>();
    // Call the super method to create the ontology - this is needed, because
    // we throw an exception if someone tries to create an ontology directly

    OWLOntology existingOntology = null;
    IRI iri = documentSource.getDocumentIRI();
    if (getOWLOntologyManager().contains(iri)) {
      existingOntology = getOWLOntologyManager().getOntology(iri);
    }
    OWLOntologyID ontologyID = new OWLOntologyID();
    OWLOntology ont =
        super.createOWLOntology(ontologyID, documentSource.getDocumentIRI(), mediator);
    // Now parse the input into the empty ontology that we created
    for (final OWLParser parser : getParsers()) {
      try {
        if (existingOntology == null && !ont.isEmpty()) {
          // Junk from a previous parse.  We should clear the ont
          getOWLOntologyManager().removeOntology(ont);
          ont = super.createOWLOntology(ontologyID, documentSource.getDocumentIRI(), mediator);
        }
        OWLOntologyFormat format = parser.parse(documentSource, ont);
        mediator.setOntologyFormat(ont, format);
        return ont;
      } catch (IOException e) {
        // No hope of any parsers working?
        // First clean up
        getOWLOntologyManager().removeOntology(ont);
        throw new OWLOntologyCreationIOException(e);
      } catch (UnloadableImportException e) {
        // First clean up
        getOWLOntologyManager().removeOntology(ont);
        throw e;
      } catch (OWLParserException e) {
        // Record this attempts and continue trying to parse.
        exceptions.put(parser, e);
      } catch (RuntimeException e) {
        // Clean up and rethrow
        getOWLOntologyManager().removeOntology(ont);
        throw e;
      }
    }
    if (existingOntology == null) {
      getOWLOntologyManager().removeOntology(ont);
    }
    // We haven't found a parser that could parse the ontology properly.  Throw an
    // exception whose message contains the stack traces from all of the parsers
    // that we have tried.
    throw new UnparsableOntologyException(documentSource.getDocumentIRI(), exceptions);
  }
Example #2
0
  private OWLOntology relevantPart(QueryRecord queryRecord) {
    AnswerTuples rlAnswer = null, elAnswer = null;

    t.reset();
    try {
      rlAnswer =
          rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables());
      Utility.logDebug(t.duration());
      queryRecord.updateLowerBoundAnswers(rlAnswer);
    } finally {
      if (rlAnswer != null) rlAnswer.dispose();
    }
    queryRecord.addProcessingTime(Step.LowerBound, t.duration());
    rlAnswer = null;

    t.reset();
    BasicQueryEngine upperStore =
        queryRecord.isBottom() || lazyUpperStore == null ? trackingStore : lazyUpperStore;

    String[] extendedQuery = queryRecord.getExtendedQueryText();

    queryUpperBound(
        upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables());
    if (!queryRecord.processed() && !queryRecord.getQueryText().equals(extendedQuery[0]))
      queryUpperBound(upperStore, queryRecord, extendedQuery[0], queryRecord.getAnswerVariables());
    if (!queryRecord.processed() && queryRecord.hasNonAnsDistinguishedVariables())
      queryUpperBound(
          upperStore, queryRecord, extendedQuery[1], queryRecord.getDistinguishedVariables());

    queryRecord.addProcessingTime(Step.UpperBound, t.duration());
    if (queryRecord.processed()) {
      queryRecord.setDifficulty(Step.UpperBound);
      return null;
    }

    t.reset();
    try {
      elAnswer =
          elLowerStore.evaluate(
              extendedQuery[0],
              queryRecord.getAnswerVariables(),
              queryRecord.getLowerBoundAnswers());
      Utility.logDebug(t.duration());
      queryRecord.updateLowerBoundAnswers(elAnswer);
    } finally {
      if (elAnswer != null) elAnswer.dispose();
    }
    queryRecord.addProcessingTime(Step.ELLowerBound, t.duration());

    if (queryRecord.processed()) {
      queryRecord.setDifficulty(Step.ELLowerBound);
      return null;
    }

    t.reset();

    QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord);

    OWLOntology knowledgebase;
    t.reset();
    //		if (program.getGeneral().isHorn()) {
    //			knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true);
    //			queryRecord.addProcessingTime(Step.Fragment, t.duration());
    //			return knowledgebase;
    //		}
    //		else {
    knowledgebase = tracker.extract(trackingStore, consistency.getQueryRecords(), true);
    queryRecord.addProcessingTime(Step.Fragment, t.duration());
    //		}

    if (knowledgebase.isEmpty() || queryRecord.isBottom()) return knowledgebase;

    if (program.getGeneral().isHorn()) return knowledgebase;

    //		t.reset();
    //		if (queryRecord.isHorn() && lazyUpperStore != null) {
    ////			knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true);
    //		} else if (queryRecord.getArity() < 3) {
    //			IterativeRefinement iterativeRefinement = new IterativeRefinement(queryRecord, tracker,
    // trackingStore, consistency.getQueryRecords());
    //			knowledgebase = iterativeRefinement.extractWithFullABox(importedData.toString(),
    // program.getUpperBottomStrategy());
    //		}
    //
    //		queryRecord.addProcessingTime(Step.FragmentRefinement, t.duration());
    //
    //		if (knowledgebase == null)
    //			queryRecord.setDifficulty(Step.FragmentRefinement);

    return knowledgebase;
  }