Beispiel #1
0
  @Test
  public void testWF() {

    String query =
        "prefix c: <http://www.inria.fr/acacia/comma#>"
            + "select     * where {"
            + "?x c:hasGrandParent c:Pierre "
            + "}";

    String ent = "select * where {graph kg:entailment {?x ?p ?y}}";

    graph.addEngine(fengine);

    QueryProcess exec = QueryProcess.create(graph);
    Mappings map;
    try {
      map = exec.query(query);
      assertEquals("Result", 4, map.size());

      map = exec.query(ent);
      // System.out.println(map);

    } catch (EngineException e) {
      assertEquals("Result", 4, e);
    }
  }
Beispiel #2
0
  void validate(Graph g, int n) throws EngineException {
    QueryProcess exec = QueryProcess.create(g);
    String q = "select * " + "from kg:rule " + "where {?x ?p ?y}";

    Mappings map = exec.query(q);
    assertEquals(n, map.size());
  }
Beispiel #3
0
  @Test
  public void testOWLRL() throws LoadException, EngineException {
    GraphStore g = GraphStore.create();
    Load ld = Load.create(g);
    ld.loadWE(data + "template/owl/data/primer.owl");
    RuleEngine re = RuleEngine.create(g);
    re.setProfile(RuleEngine.OWL_RL_LITE);
    re.process();

    String q = "select * " + "from kg:rule " + "where { ?x ?p ?y }";

    QueryProcess exec = QueryProcess.create(g);
    Mappings map = exec.query(q);

    assertEquals(611, map.size());

    String qq =
        "select distinct ?p ?pr "
            + "from kg:rule "
            + "where { ?x ?p ?y bind (kg:provenance(?p) as ?pr) }";

    map = exec.query(qq);

    assertEquals(31, map.size());

    String qqq =
        "select distinct ?q  "
            + "from kg:rule "
            + "where { "
            + "?x ?p ?y bind (kg:provenance(?p) as ?pr) "
            + "graph ?pr { [] sp:predicate ?q }"
            + "} order by ?q";

    map = exec.query(qqq);

    assertEquals(19, map.size());

    String q4 = "select ?q  " + "where { " + "graph eng:engine { ?q a sp:Construct }" + "} ";

    map = exec.query(q4);

    assertEquals(64, map.size());

    String q5 = "select ?q  " + "where { " + "graph eng:record { ?r a kg:Index }" + "} ";

    map = exec.query(q5);

    assertEquals(159, map.size());

    String q6 = "select ?r  " + "where { " + "graph kg:re2 {  ?r a kg:Index  }" + "} ";

    map = exec.query(q6);
    assertEquals(3, map.size());

    String q7 = "select ?r  " + "where { " + "graph eng:queries {  ?r a sp:Construct  }" + "} ";

    map = exec.query(q7);
    assertEquals(4, map.size());
  }
Beispiel #4
0
  /** Rule engine with QueryExec on two graphs */
  @Test
  public void test6() {
    QuerySolver.definePrefix("c", "http://www.inria.fr/acacia/comma#");

    Graph g1 = createGraph(true);
    Graph g2 = createGraph(true);

    Load load1 = Load.create(g1);
    Load load2 = Load.create(g2);

    load1.load(data + "engine/ontology/test.rdfs");
    load2.load(data + "engine/data/test.rdf");

    QueryProcess exec = QueryProcess.create(g1);
    exec.add(g2);
    RuleEngine re = RuleEngine.create(g2, exec);
    // re.setOptimize(true);

    load2.setEngine(re);

    try {
      load2.loadWE(data + "engine/rule/test2.brul");
      load2.load(new FileInputStream(data + "engine/rule/meta.brul"), "meta.brul");
    } catch (LoadException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Engine rengine = Engine.create(exec);

    rengine.load(data + "engine/rule/test2.brul");
    rengine.load(data + "engine/rule/meta.brul");

    String query =
        "prefix c: <http://www.inria.fr/acacia/comma#>"
            + "select     * where {"
            + "?x c:hasGrandParent c:Pierre "
            + "}";

    LBind bind = rengine.SPARQLProve(query);
    assertEquals("Result", 4, bind.size());
    // System.out.println(bind);

    re.process();

    try {
      Mappings map = exec.query(query);
      assertEquals("Result", 4, map.size());
      // System.out.println(map);
    } catch (EngineException e) {
      assertEquals("Result", 4, e);
    }
  }
Beispiel #5
0
  @Test
  public void test7() {
    Graph g1 = createGraph(true);
    Load load1 = Load.create(g1);
    load1.load(root + "sdk/sdk.rdf");

    String init = "load <" + root + "rule/server.rul> into graph kg:rule";
    String query = "select * where {?x a ?class}";
    QueryProcess exec = QueryProcess.create(g1);

    try {
      exec.query(init);
      Mappings map = exec.query(query);
      // System.out.println(map);
      assertEquals("Result", 6, map.size());
    } catch (EngineException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Beispiel #6
0
  @Test
  public void testRuleOptimization() throws LoadException, EngineException {
    Graph g1 = testRuleOpt();
    Graph g2 = testRuleNotOpt();

    QueryProcess e1 = QueryProcess.create(g1, true);
    QueryProcess e2 = QueryProcess.create(g2, true);

    String q =
        "prefix c: <http://www.inria.fr/acacia/comma#>"
            + "select distinct ?x where {"
            + "?x a c:Person ; "
            + " c:hasCreated ?doc "
            + "?doc a c:Document"
            + "}";

    Mappings m1 = e1.query(q);
    Mappings m2 = e2.query(q);
    assertEquals(m1.size(), m2.size());
  }
Beispiel #7
0
  @Test
  public void testOWLRL2() throws LoadException, EngineException {
    GraphStore g = GraphStore.create();
    Load ld = Load.create(g);
    ld.loadWE(data + "template/owl/data/primer.owl");
    RuleEngine re = RuleEngine.create(g);
    re.setProfile(RuleEngine.OWL_RL_LITE);
    // re.process();
    g.addEngine(re);
    String q = "select * " + "from kg:rule " + "where { ?x ?p ?y }";
    QueryProcess exec = QueryProcess.create(g);
    Mappings map = exec.query(q);

    assertEquals(611, map.size());
  }
  /**
   * Transforms an EDGE request into a simple SPARQL query pushed to the remote producer. Results
   * are returned through standard web services protocol.
   *
   * @param gNode graph variable if it exists, null otherwise
   * @param from "from named <g>" list
   * @param qEdge edge searched for
   * @param env query execution context (current variable values, etc.)
   * @return an iterator over graph entities
   */
  @Override
  public Iterable<Entity> getEdges(Node gNode, List<Node> from, Edge qEdge, Environment env) {
    // si gNode != null et from non vide, alors "from named"
    // si gNode == null et from non vide alors "from"

    String query = getSparqlQuery(qEdge, env);
    Graph resGraph = Graph.create();
    Graph g = Graph.create();

    StopWatch sw = new StopWatch();
    sw.start();

    InputStream is = null;
    try {
      QueryProcess exec = QueryProcess.create(resGraph);

      if (query != null) {
        Mappings map = exec.query(query);

        //            logger.info("Received results in " + sw.getTime());

        String sparqlRes = RDFFormat.create(map).toString();
        //            System.out.println(XMLFormat.create(map));

        if (sparqlRes != null) {
          Load l = Load.create(g);
          is = new ByteArrayInputStream(sparqlRes.getBytes());
          l.load(is);
          //                logger.info("Results (cardinality " + g.size() + ") merged in  " +
          // sw.getTime() + " ms.");
        }
      }

    } catch (LoadException ex) {
      ex.printStackTrace();
    } catch (EngineException ex) {
      ex.printStackTrace();
    }
    //        for (Iterator<Entity> it = g.getEdges().iterator(); it.hasNext();) {
    //            Edge e = (Edge) it.next();
    //            System.out.println(e);
    //        }
    //
    return g.getEdges();
  }
Beispiel #9
0
  @Test
  public void test5() {

    Graph g = createGraph();
    Pipe pipe = Pipe.create(g);
    pipe.load(root + "pipe/pipe.rdf");
    pipe.process();

    QueryProcess exec = QueryProcess.create(g);
    String query = "select * where {graph ?g {?x ?p ?y}}";
    try {
      Mappings map = exec.query(query);
      // System.out.println(map);
      assertEquals("Result", 9, map.size());
    } catch (EngineException e) {
      assertEquals("Result", 9, e);
    }
  }
  @Test
  public void localEntailments() throws EngineException {
    Graph localGraph = Graph.create(true);
    Load ld = Load.create(localGraph);
    ld.load(humanData.getAbsolutePath());
    ld.load(humanOnt.getAbsolutePath());

    QueryProcess exec = QueryProcess.create(localGraph);
    StopWatch sw = new StopWatch();
    sw.start();
    Mappings res = exec.query(sparqlEntailQueryPerson);

    System.out.println("--------");
    System.out.println("Results in " + sw.getTime() + "ms");
    System.out.println(res);

    assertEquals(17, res.size());
  }
Beispiel #11
0
  @Test
  public void test4() {

    String query =
        "prefix c: <http://www.inria.fr/acacia/comma#>"
            + "select     * where {"
            + "?x c:hasGrandParent c:Pierre "
            + "}";

    fengine.process();
    QueryProcess exec = QueryProcess.create(graph);
    Mappings map;
    try {
      map = exec.query(query);
      assertEquals("Result", 4, map.size());
    } catch (EngineException e) {
      assertEquals("Result", 4, e);
    }
  }