Esempio n. 1
0
 protected String computeHSShortLog(
     TreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom> search,
     OWLTheory theory,
     FormulaSet<OWLLogicalAxiom> diagnoses,
     List<Double> queries,
     QSSType type,
     String message,
     OWLTheory queryAnswerTheory) {
   SimulatedSession session = new SimulatedSession();
   session.setShowElRates(false);
   TableList entry = new TableList();
   session.setEntry(entry);
   session.setMessage(message);
   session.setTargetD(diagnoses);
   session.setScoringFunct(type);
   session.setTheory(theory);
   session.setQueryAnswerTheory(queryAnswerTheory);
   session.setSearch(search);
   String out = session.simulateQuerySession();
   FormulaSet<OWLLogicalAxiom> diag = getMostProbable(search.getDiagnoses());
   logger.info("found Diag: " + CalculateDiagnoses.renderAxioms(diag));
   boolean foundCorrectD =
       diagnoses.containsAll(
           diag); // with ConflictTreeTest only a subset of the diagnosis could be returned
   if (this.getClass() != ConflictTreeTest.class) {
     foundCorrectD = diag.equals(diagnoses);
     theory.getKnowledgeBase().clearTestCases(); // don't clear if called from ConflictTreeTest
   }
   search.reset();
   // Assert.assertTrue(foundCorrectD);
   queries.add(entry.getMeanQuery());
   return out;
 }
Esempio n. 2
0
  /**
   * Runs ConflictTreeSimulatedSession with calculated diagnoses
   *
   * @param matchingsDir
   * @param ontologyDir
   * @param files
   * @param map
   * @throws SolverException
   * @throws InconsistentTheoryException
   * @throws OWLOntologyCreationException
   */
  private void runOaeiConferenceTests(
      String matchingsDir,
      String ontologyDir,
      Set<File> files,
      Map<File, String> map,
      int numberOfConflicts)
      throws SolverException, InconsistentTheoryException, OWLOntologyCreationException {
    OAEI11ConferenceSession conferenceSession = new OAEI11ConferenceSession();

    QSSType[] qssTypes = new QSSType[] {QSSType.MINSCORE};
    // QSSType[] qssTypes = new QSSType[]{QSSType.MINSCORE, QSSType.SPLITINHALF,
    // QSSType.DYNAMICRISK};

    TargetSource targetSource = TargetSource.FROM_30_DIAGS;
    for (File file : files) {
      logger.info("processing " + file.getName());
      String out = "STAT, " + file;

      // file parameter
      String fileName = file.getName();
      StringTokenizer t = new StringTokenizer(fileName, "-");
      String matcher = t.nextToken();
      String o1 = t.nextToken();
      String o2 = t.nextToken();
      o2 = o2.substring(0, o2.length() - 4);
      String n = file.getName().substring(0, file.getName().length() - 4);

      Set<FormulaSet<OWLLogicalAxiom>> targetDgSet =
          getRandomDiagSet(matchingsDir, ontologyDir, map, file, o1, o2, n, conferenceSession);
      logger.info("number of found diagnoses (max. 30): " + targetDgSet.size());
      /*
      TODO: for each ontology always the same "randomly" chosen diagnosis is calculated, dependent
          from the size of the targetDgSet -> change to a real random selection
       */
      Random random = new Random(12311);
      int randomNr = conferenceSession.chooseRandomNum(targetDgSet, random);
      Set<OWLLogicalAxiom> targetDg =
          conferenceSession.chooseRandomDiag(targetDgSet, file, randomNr);

      OWLOntology inconsOntology =
          loadOntology(matchingsDir, ontologyDir, map, conferenceSession, file, o1, o2, n);
      //                OWLTheory faultyTheory = getExtendTheory(inconsOntology, false);
      OWLTheory faultyTheory = loadTheory(inconsOntology, ontologyDir, o1, o2);
      Set<OWLLogicalAxiom> rem = validateMinimality(targetDg, faultyTheory);
      if (!rem.isEmpty()) {
        targetDg.removeAll(rem);
        assertTrue(validateMinimality(targetDg, faultyTheory).isEmpty());
      }

      Map<QSSType, DurationStat> ctTimes = new HashMap<QSSType, DurationStat>();
      Map<QSSType, List<Double>> ctQueries = new HashMap<QSSType, List<Double>>();

      for (QSSType qssType : qssTypes) {
        String message =
            "act,"
                + file.getName()
                + ","
                + map.get(file)
                + ","
                + targetSource
                + ","
                + qssType
                + ","
                + randomNr;
        long preprocessModulExtract = System.currentTimeMillis();
        OWLOntology ontology =
            loadOntology(matchingsDir, ontologyDir, map, conferenceSession, file, o1, o2, n);
        ctTheory = loadTheory(ontology, ontologyDir, o1, o2);
        preprocessModulExtract = System.currentTimeMillis() - preprocessModulExtract;
        message += "," + preprocessModulExtract;

        // Define Treesearch here
        TreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom> search =
            getUniformCostSearch(ctTheory, false);

        Map<OWLLogicalAxiom, BigDecimal> map1 =
            conferenceSession.readRdfMapping(matchingsDir + map.get(file), n + ".rdf");
        OWLAxiomCostsEstimator es = new OWLAxiomCostsEstimator(ctTheory, map1);
        search.setCostsEstimator(es);
        search.reset();

        // set for all found diagnoses during search
        foundDiagnoses = new LinkedHashSet<OWLLogicalAxiom>();

        ctTimes.put(qssType, new DurationStat());
        ctQueries.put(qssType, new LinkedList<Double>());

        // calculation part
        ConflictTreeSession conflictTreeSearch = new ConflictTreeSession(this, ctTheory, search);
        if (numberOfConflicts > 0) {
          conflictTreeSearch.setMaximumNumberOfConflicts(numberOfConflicts);
        }
        conflictTreeSearch.setOutputString(out);
        conflictTreeSearch.setMessageString(message);
        FormulaSet<OWLLogicalAxiom> targetD =
            new FormulaSetImpl<OWLLogicalAxiom>(new BigDecimal(1), targetDg, null);
        long completeTime = conflictTreeSearch.search(targetD, ctQueries, qssType, true);
        ctTimes.get(qssType).add(completeTime);
        out += conflictTreeSearch.getOutputString();

        foundDiagnoses = conflictTreeSearch.getDiagnosis();
        logger.info("targetD: " + targetD.size() + ", " + CalculateDiagnoses.renderAxioms(targetD));
        logger.info(
            "foundD: "
                + foundDiagnoses.size()
                + ", "
                + CalculateDiagnoses.renderAxioms(foundDiagnoses));

        faultyTheory
            .getReasoner()
            .addFormulasToCache(faultyTheory.getKnowledgeBase().getFaultyFormulas());
        assertFalse(faultyTheory.verifyConsistency());
        Set<OWLLogicalAxiom> removedFound = validateMinimality(foundDiagnoses, faultyTheory);
        // assertTrue(removed.isEmpty());
        Set<OWLLogicalAxiom> removedTarget = validateMinimality(targetD, faultyTheory);
        assertTrue(removedTarget.isEmpty());

        assertTrue(targetD.containsAll(foundDiagnoses));
        // TODO uncomment later
        // assertTrue(foundDiagnoses.containsAll(targetD));

        resetTheoryTests(ctTheory);
        search.reset();
      }
      logger.info(out);
    }
  }