Beispiel #1
0
 /** TODO: prevent loop n = [ st:import st:cal ] st:cal st:param [ ... ] */
 void importer(Node n) {
   Edge imp = g.getEdge(Context.STL_IMPORT, n, 0);
   if (imp != null) {
     Edge par = g.getEdge(Context.STL_PARAM, imp.getNode(1), 0);
     if (par != null) {
       context(par.getNode(1));
     }
   }
 }
Beispiel #2
0
  @Test
  public void test8() {
    Graph g = createGraph();
    QueryProcess exec = QueryProcess.create(g);

    QueryEngine qe = QueryEngine.create(g);
    String query = "insert data { <John> rdfs:label 'John' }";
    qe.addQuery(query);

    qe.process();

    assertEquals("Result", 1, g.size());
  }
 /**
  * Dans le cas des chemins
  *
  * @param gNode
  * @param from
  * @param qEdge
  * @param env ne pas prendre en compte l'env dans le calcul des chemins
  * @param exp
  * @param src l'ensemble des
  * @param start noeud courant
  * @param index sens du parcours
  * @return
  */
 @Override
 public Iterable<Entity> getEdges(
     Node gNode,
     List<Node> from,
     Edge qEdge,
     Environment env,
     Regex exp,
     Node src,
     Node start,
     int index) {
   Graph resGraph = Graph.create();
   return resGraph.getEdges();
 }
Beispiel #4
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;
  }
Beispiel #5
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;
  }
Beispiel #6
0
 /** Create a Context from content of st:param */
 public Context process() {
   Entity ent = g.getEdges(Context.STL_PARAM).iterator().next();
   if (ent == null) {
     return new Context();
   }
   return process(ent.getNode(1));
 }
Beispiel #7
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 #8
0
 IDatatype list(Graph g, Node object) {
   List<IDatatype> list = g.getDatatypeList(object);
   if (!list.isEmpty()) {
     IDatatype dt = DatatypeMap.createList(list);
     return dt;
   }
   return null;
 }
  /**
   * 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 #10
0
 public ContextBuilder(String path) {
   g = Graph.create();
   Load ld = Load.create(g);
   try {
     ld.loadWE(path);
   } catch (LoadException ex) {
     Logger.getLogger(ContextBuilder.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
  @Test
  public void rdfsEntailQuery() throws EngineException, MalformedURLException, IOException {

    Graph gRes = Graph.create(false);
    QueryProcessDQP exec = QueryProcessDQP.create(gRes);
    exec.addRemote(new URL("http://localhost:" + port + "/kgram/sparql"), WSImplem.REST);

    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 #12
0
  void context(Node ctx) {
    importer(ctx);

    for (Entity ent : g.getEdgeList(ctx)) {
      if (!ent.getEdge().getLabel().equals(Context.STL_IMPORT)) {
        Node object = ent.getNode(1);

        if (object.isBlank()) {
          IDatatype list = list(g, object);
          if (list != null) {
            c.set(ent.getEdge().getLabel(), list);
            continue;
          }
        }
        c.set(ent.getEdge().getLabel(), (IDatatype) object.getValue());
      }
    }
  }
  @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 #14
0
 public Iterable<Entity> getEdges() {
   Graph g = getGraph();
   if (g == null) return new ArrayList<Entity>();
   return g.getEdges();
 }