Esempio n. 1
0
  @Override
  public boolean preprocess() {
    t.reset();
    Utility.logInfo("Preprocessing ... checking satisfiability ... ");

    String name = "data", datafile = importedData.toString();
    rlLowerStore.importRDFData(name, datafile);
    rlLowerStore.materialise("lower program", program.getLower().toString());
    //		program.getLower().save();
    if (!consistency.checkRLLowerBound()) return false;
    Utility.logInfo(
        "The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber());

    String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology);

    elLowerStore.importRDFData(name, datafile);
    elLowerStore.materialise("saturate named individuals", originalMarkProgram);
    elLowerStore.materialise("lower program", program.getLower().toString());
    elLowerStore.initialiseKarma();
    if (!consistency.checkELLowerBound()) return false;

    if (lazyUpperStore != null) {
      lazyUpperStore.importRDFData(name, datafile);
      lazyUpperStore.materialise("saturate named individuals", originalMarkProgram);
      int tag = lazyUpperStore.materialiseRestrictedly(program, null);
      if (tag != 1) {
        lazyUpperStore.dispose();
        lazyUpperStore = null;
      }
      if (tag == -1) return false;
    }
    if (consistency.checkLazyUpper()) {
      satisfiable = true;
      Utility.logInfo("time for satisfiability checking: " + t.duration());
    }

    trackingStore.importRDFData(name, datafile);
    trackingStore.materialise("saturate named individuals", originalMarkProgram);

    //		materialiseFullUpper();
    //		GapByStore4ID gap = new GapByStore4ID(trackingStore);
    GapByStore4ID gap = new GapByStore4ID2(trackingStore, rlLowerStore);
    trackingStore.materialiseFoldedly(program, gap);
    predicatesWithGap = gap.getPredicatesWithGap();
    gap.clear();

    if (program.getGeneral().isHorn())
      encoder = new TrackingRuleEncoderWithGap(program.getUpper(), trackingStore);
    else encoder = new TrackingRuleEncoderDisjVar1(program.getUpper(), trackingStore);
    //			encoder = new TrackingRuleEncoderDisj1(program.getUpper(), trackingStore);
    //			encoder = new TrackingRuleEncoderDisjVar2(program.getUpper(), trackingStore);
    //			encoder = new TrackingRuleEncoderDisj2(program.getUpper(), trackingStore);

    program.deleteABoxTurtleFile();

    if (!isConsistent()) return false;

    consistency.extractBottomFragment();
    return true;
  }
Esempio n. 2
0
  @Override
  public void evaluate(QueryRecord queryRecord) {
    OWLOntology knowledgebase = relevantPart(queryRecord);

    if (knowledgebase == null) {
      Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty());
      return;
    }

    int aboxcount = knowledgebase.getABoxAxioms(true).size();
    Utility.logDebug(
        "ABox axioms: "
            + aboxcount
            + " TBox axioms: "
            + (knowledgebase.getAxiomCount() - aboxcount));
    //		queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl");

    Timer t = new Timer();
    Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT());
    //		int validNumber =
    summarisedChecker.check(queryRecord.getGapAnswers());
    summarisedChecker.dispose();
    Utility.logDebug("Total time for full reasoner: " + t.duration());
    //		if (validNumber == 0) {
    queryRecord.markAsProcessed();
    Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty());
    //		}
  }
Esempio n. 3
0
 private void queryUpperBound(
     BasicQueryEngine upperStore,
     QueryRecord queryRecord,
     String queryText,
     String[] answerVariables) {
   AnswerTuples rlAnswer = null;
   try {
     Utility.logDebug(queryText);
     rlAnswer = upperStore.evaluate(queryText, answerVariables);
     Utility.logDebug(t.duration());
     queryRecord.updateUpperBoundAnswers(rlAnswer);
   } finally {
     if (rlAnswer != null) rlAnswer.dispose();
     rlAnswer = null;
   }
 }
Esempio n. 4
0
 @Override
 public boolean isConsistent() {
   if (satisfiable == null) {
     satisfiable = consistency.check();
     Utility.logInfo("time for satisfiability checking: " + t.duration());
   }
   return satisfiable;
 }
Esempio n. 5
0
  @Override
  public void sample() throws RDFHandlerException {
    getStartNodes();

    Utility.logInfo(queue.size());

    int u, v, pick, index;
    int individualLimit = statementLimit / queue.size(), currentLimit = 0;
    RDFEdge edge;
    List<RDFEdge> edges;
    Stack<Integer> stack = new Stack<Integer>();
    while (true) {
      if (noOfStatements >= statementLimit) {
        System.out.println("The number of statements in the sampling: " + noOfStatements);
        return;
      }
      if (noOfStatements >= currentLimit) {
        stack.clear();
      }

      if (stack.isEmpty()) {
        if (queue.isEmpty()) v = rand.nextInt(m_graph.numberOfIndividuals);
        else {
          v = queue.poll();
          currentLimit += individualLimit;
        }
        stack.add(v);
        //				Utility.logInfo(noOfStart + " new start: " + m_graph.getRawString(v));
        visit(v);
      }
      u = stack.peek();
      if (rand.nextInt(100) < 15) {
        stack.pop();
        continue;
      }
      if ((edges = m_graph.edges.get(u)) == null || edges.size() == 0) {
        stack.clear();
        continue;
      }

      index = 0;
      pick = rand.nextInt(edges.size());
      for (Iterator<RDFEdge> iter = edges.iterator(); iter.hasNext(); ++index) {
        edge = iter.next();
        if (index == pick) {
          stack.add(v = edge.m_dst);
          visit(v);
          m_writer.handleStatement(m_graph.getStatement(u, edge.m_label, edge.m_dst));
          ++noOfStatements;
          iter.remove();
        }
      }
    }
  }
Esempio n. 6
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;
  }
  public static void main(String[] args) throws Exception {
    if (args.length == 0) {
      //			args = new String[] { "/home/yzhou/backup/20141212/univ-bench-dl-queries.owl"};
      args = new String[] {PagodaTester.onto_dir + "fly/fly-all-in-one_rolledUp.owl"};
      //			args = new String[] { PagodaTester.onto_dir +
      // "dbpedia/integratedOntology-all-in-one-minus-datatype.owl" };
      //			args = new String[] { PagodaTester.onto_dir + "npd/npd-all-minus-datatype.owl" };
      //			args = new String[] { PagodaTester.onto_dir + "bio2rdf/chembl/cco-noDPR.ttl" };
      //			args = new String[] { PagodaTester.onto_dir +
      // "bio2rdf/reactome/biopax-level3-processed.owl" };
      //			args = new String[] { PagodaTester.onto_dir + "bio2rdf/uniprot/core-processed-noDis.owl"
      // };
    }

    //		OWLOntology ontology = OWLHelper.getMergedOntology(args[0], null);
    //		OWLHelper.correctDataTypeRangeAxioms(ontology);
    OWLOntology ontology = OWLHelper.loadOntology(args[0]);

    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    OWLDataFactory factory = manager.getOWLDataFactory();
    //		manager.saveOntology(ontology, new FileOutputStream(args[0].replace(".owl",
    // "_owlapi.owl")));

    if (outputFile != null) Utility.redirectCurrentOut(outputFile);

    int queryID = 0;
    for (OWLClass cls : ontology.getClassesInSignature(true)) {
      if (cls.equals(factory.getOWLThing()) || cls.equals(factory.getOWLNothing())) continue;
      if (!cls.toStringID().contains("Query")) continue;
      System.out.println("^[Query" + ++queryID + "]");
      System.out.println(template.replace("@CLASS", cls.toStringID()));
      System.out.println();
    }

    for (OWLOntology onto : ontology.getImportsClosure())
      for (OWLObjectProperty prop : onto.getObjectPropertiesInSignature()) {
        //				if (!prop.toStringID().contains("Query")) continue;
        System.out.println("^[Query" + ++queryID + "]");
        System.out.println("SELECT ?X ?Y");
        System.out.println("WHERE {");
        System.out.println("?X <" + prop.toStringID() + "> ?Y .");
        System.out.println("}");
        System.out.println();
      }

    String[] answerVars = new String[] {"?X", "?Y"};

    for (OWLOntology onto : ontology.getImportsClosure())
      for (OWLObjectProperty prop : onto.getObjectPropertiesInSignature()) {
        //				if (!prop.toStringID().contains("Query")) continue;
        for (int i = 0; i < answerVars.length; ++i) {
          System.out.println("^[Query" + ++queryID + "]");
          System.out.println("SELECT " + answerVars[i]);
          System.out.println("WHERE {");
          System.out.println("?X <" + prop.toStringID() + "> ?Y .");
          System.out.println("}");
          System.out.println();
        }
      }

    if (outputFile != null) Utility.closeCurrentOut();
  }