public Set<FormulaSet<OWLLogicalAxiom>> getRandomDiagSet(
      String matchingsDir,
      String ontologyDir,
      Map<File, String> map,
      File file,
      String o1,
      String o2,
      String n,
      OAEI11ConferenceSession conferenceSession)
      throws SolverException, InconsistentTheoryException {
    OWLOntology preOntology =
        loadOntology(matchingsDir, ontologyDir, map, conferenceSession, file, o1, o2, n);
    OWLTheory preTheory = loadTheory(preOntology, ontologyDir, o1, o2);
    TreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom> search =
        getUniformCostSearch(preTheory, false);

    Map<OWLLogicalAxiom, BigDecimal> map1 =
        conferenceSession.readRdfMapping(matchingsDir + map.get(file), n + ".rdf");
    OWLAxiomCostsEstimator es = new OWLAxiomCostsEstimator(preTheory, map1);
    search.setCostsEstimator(es);
    preTheory.getReasoner().addFormulasToCache(preTheory.getKnowledgeBase().getFaultyFormulas());
    assertFalse(preTheory.verifyConsistency());
    search.reset();

    try {
      search.setMaxDiagnosesNumber(30);
      search.start();
    } catch (NoConflictException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    Set<FormulaSet<OWLLogicalAxiom>> diagnoses =
        new TreeSet<FormulaSet<OWLLogicalAxiom>>(search.getDiagnoses());

    search.reset();

    return diagnoses;
  }
Exemple #2
0
  /** @param args */
  public static void main(String[] args) {
    // INFO: if you want to use the asp module as executable jar, uncomment the following comment
    handleCommandLine(args);

    ASPConverter converter = new ASPConverter();
    String src = converter.convertFromFileToString(fileToDebug);

    // do the parsing
    ANTLRInputStream input = null;
    input = new ANTLRInputStream(src);
    ASPProgramLexer lexer = new ASPProgramLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ASPProgramParser parser = new ASPProgramParser(tokens);
    ParseTree tree = parser.prog();
    ProgramListener pl = new ProgramListener();
    ParseTreeWalker.DEFAULT.walk(pl, tree);

    //       	parser.setBuildParseTree(true);
    //       	ParserRuleContext tree = parser.prog();
    //       	tree.inspect(parser);

    // fill the asp model with rules
    ASPModel model = ASPModel.getASPModelInstance();
    for (IProgramElement r : model.getRules()) {
      model.addProgramElement(r);
    }

    //        ReasonerASP reasoner = new ReasonerASP();
    //        boolean consistent = reasoner.isConsistent();
    //        System.out.println("is consistent: " + consistent);

    ASPTheory theory = new ASPTheory();
    ReasonerASP reasoner = new ReasonerASP();
    theory.setReasoner(reasoner);
    KnowledgeBase<IProgramElement> knowledgeBase = new KnowledgeBase<IProgramElement>();
    knowledgeBase.setBackgroundFormulas(model.getFacts());
    theory.setKnowledgeBase(knowledgeBase);
    theory.getKnowledgeBase().addFormulas(model.getProgramElements());

    HsTreeSearch<FormulaSet<IProgramElement>, IProgramElement> search =
        new HsTreeSearch<FormulaSet<IProgramElement>, IProgramElement>();

    // we want to use UniformCostSearch as our start strategy
    search.setSearchStrategy(new BreadthFirstSearchStrategy<IProgramElement>());

    // because we use Reiter's Tree nodes are conflicts which we start using QuickXplain
    search.setSearcher(new QuickXplain<IProgramElement>());

    // because we use UniformCostSearch we have to give a cost estimator to the start
    search.setCostsEstimator(new SimpleCostsEstimator<IProgramElement>());

    // at last we combine theory with start and get our ready to use object
    search.setSearchable(theory);
    try {
      search.start();
    } catch (SolverException e1) {
      e1.printStackTrace();
    } catch (NoConflictException e1) {
      e1.printStackTrace();
    } catch (InconsistentTheoryException e1) {
      e1.printStackTrace();
    }

    Set<FormulaSet<IProgramElement>> conflicts = search.getConflicts();
    Set<FormulaSet<IProgramElement>> diagnosis = search.getDiagnoses();
    int i = 0;
    int j = 0;
    for (FormulaSet<IProgramElement> fs : conflicts) {
      System.out.println("\nConflicts " + i + ":");
      for (IProgramElement pe : fs) {
        System.out.println(pe.getString());
      }
      i++;
    }
    for (FormulaSet<IProgramElement> fs : diagnosis) {
      System.out.println("\nDiagnosis " + j + ":");
      for (IProgramElement pe : fs) {
        System.out.println(pe.getString());
      }
      j++;
    }
  }