Exemple #1
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());
  }
Exemple #2
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);
    }
  }
Exemple #3
0
  public Graph testRuleNotOpt() throws LoadException, EngineException {
    RuleEngine re = testRules();
    Graph g = re.getRDFGraph();

    System.out.println("Graph: " + g.size());
    Date d1 = new Date();
    re.process();
    Date d2 = new Date();
    System.out.println("** Time std: " + (d2.getTime() - d1.getTime()) / (1000.0));

    validate(g, 41109);
    assertEquals(57402, g.size());
    return g;
  }
Exemple #4
0
  public Graph testRuleOpt() throws LoadException, EngineException {
    RuleEngine re = testRules();
    Graph g = re.getRDFGraph();

    re.setSpeedUp(true);
    System.out.println("Graph: " + g.size());
    Date d1 = new Date();
    re.process();
    Date d2 = new Date();
    System.out.println("** Time opt: " + (d2.getTime() - d1.getTime()) / (1000.0));
    validate(g, 37735);

    assertEquals(54028, g.size());
    return g;
  }
Exemple #5
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);
    }
  }