Ejemplo n.º 1
0
  private void compareQuery(URL htmlURL, URL compareURL) throws SAXException, IOException {
    Query query = QueryFactory.read(compareURL.toExternalForm());

    Map<String, Query> qs =
        QueryUtilities.makeQueries(ParserFactory.Format.XHTML, htmlURL.toExternalForm());

    assertTrue("We have a query", qs.size() != 0);

    Query qFromHTML = qs.get(qs.keySet().toArray()[0]);

    assertEquals(
        "Query matches (" + htmlURL + ")", Algebra.compile(query), Algebra.compile(qFromHTML));
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    // String sA = "Select * { ?s ?p ?o . Filter((?s || ?p) && ?o) . }";
    // String sA = "Select * { ?s ?p ?o . Filter((?s || ?p) && !(?o || ?g)) . }";

    String sA =
        "Select * { ?s ?p ?o . Filter(?o != <http://Person>). Optional { { ?x ?y ?z . Filter(?x != <http://x> && ?x = ?y) . } Union { ?x a ?y . Filter(?x = <http://x>) . } } . }";

    // String sA = "Select * { ?s ?p ?o . Filter(!(?s = ?p || ?p = ?o && ?s = ?o || ?o = ?s)) . }";
    // String sA = "Select * { ?s ?p ?o . Filter(!(?s = ?p || ?j = <http://x>)) . }";
    Query qA = QueryFactory.create(sA);

    Op opA = Algebra.compile(qA);
    opA = Algebra.toQuadForm(opA);

    System.out.println(opA);

    // How to deal with union? variables appearing in them

    // System.out.println(opA.getClass());
    ExprList exprs = FilterUtils.collectExprs(opA, new ExprList());

    ExprList proc = eval(exprs);
    System.out.println(proc);

    List<ExprList> clauses = dnfToClauses(proc);

    System.out.println("Mentioned vars:" + proc.getVarsMentioned());

    System.out.println("Clauses: " + clauses);
  }