Exemplo n.º 1
0
  /**
   * 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();
  }
Exemplo n.º 2
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);
   }
 }
Exemplo n.º 3
0
 /**
  * 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();
 }
Exemplo n.º 4
0
  @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());
  }
Exemplo n.º 5
0
  @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());
  }