Examples of QueryExecution


Examples of com.hp.hpl.jena.query.QueryExecution

        // Potentially expensive query.
        String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
        // See http://www.openjena.org/ARQ/app_api.html
       
        Query query = QueryFactory.create(sparqlQueryString) ;
        QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
        ResultSet results = qexec.execSelect() ;
        ResultSetFormatter.out(results) ;
        qexec.close() ;

        dataset.close();
    }
View Full Code Here

Examples of com.hp.hpl.jena.query.QueryExecution

                        "   (5 'Friday'@en)"+
                        "   (6 'Saturday'@en)" +
                        "}"
                );
        Model m=ModelFactory.createDefaultModel();
        QueryExecution qe=QueryExecutionFactory.create(q,m);
        ResultSet r=qe.execSelect();
        assertEquals(1,r.getResultVars().size());
        assertEquals("dayName",r.getResultVars().get(0));
        assertTrue(r.hasNext());
        QuerySolution qs=r.nextSolution();
        assertEquals("Sunday",qs.get("dayName").asLiteral().getLexicalForm())
View Full Code Here

Examples of com.hp.hpl.jena.query.QueryExecution

    public static RDFNode fetchScalar(Dataset m,Query query) throws Exception {
        return fetchScalar(m,query,null);
    }

    public static RDFNode fetchScalar(Dataset m,Query query,QuerySolution bindings) throws Exception {
        QueryExecution qe=QueryExecutionFactory.create(query,m);

        try {
            if(null!=bindings) {
                qe.setInitialBinding(bindings);
            }

            ResultSet results=qe.execSelect();
            if(!results.hasNext())
                return null;

            List<String> vars=results.getResultVars();
            if(vars.size()!=1) {
                throw new Exception("Scalar query returns other than one column");
            }

            QuerySolution row=results.nextSolution();
            RDFNode value=row.get(vars.get(0));
            if (results.hasNext()) {
                throw new Exception("Scalar query returns more than one row");
            }
            return value;
        } finally { qe.close(); }
    }
View Full Code Here

Examples of com.hp.hpl.jena.query.QueryExecution

            return value;
        } finally { qe.close(); }
    }

    public static Map<RDFNode,RDFNode> fetchMap(Dataset m,Query query,QuerySolution bindings) throws Exception {
        QueryExecution qe=QueryExecutionFactory.create(query,m);   
        try {
            ResultSet results=qe.execSelect();
            Map<RDFNode,RDFNode> map=Maps.newHashMap();
            List<String> vars=results.getResultVars();

            while(results.hasNext()) {
                QuerySolution row=results.nextSolution();
                map.put(row.get(vars.get(0)),row.get(vars.get(1)));
            }
            return map;
        } finally { qe.close(); }
    }
View Full Code Here

Examples of com.hp.hpl.jena.query.QueryExecution

    //
    // fetch as a map but reject results that occur more than once
    //

    public static Map<RDFNode,RDFNode> fetchMapSingle(Dataset m,Query query,QuerySolution bindings) throws Exception {
        QueryExecution qe=QueryExecutionFactory.create(query,m);   
        try {
            ResultSet results=qe.execSelect();
            Set<RDFNode> seen=Sets.newHashSet();
            Map<RDFNode,RDFNode> map=Maps.newHashMap();
            List<String> vars=results.getResultVars();

            while(results.hasNext()) {
                QuerySolution row=results.nextSolution();
                RDFNode key=row.get(vars.get(0));
                if(seen.contains(key)) {
                    map.remove(key);
                } else {
                    seen.add(key);
                    map.put(key,row.get(vars.get(1)));
                }
            }
            return map;
        } finally { qe.close(); }
    }
View Full Code Here

Examples of com.hp.hpl.jena.query.QueryExecution

    public static void appendConstruct(Model outModel,
            String queryString,
            Model inModel,
            QuerySolution bindings) {
        Query query=QueryFactory.create(queryString);
        QueryExecution qe=QueryExecutionFactory.create(query,inModel);
        try {
            if(null!=bindings) {
                qe.setInitialBinding(bindings);
            }

            qe.execConstruct(outModel);
        } finally{ qe.close(); }
    }
View Full Code Here

Examples of com.hp.hpl.jena.query.QueryExecution

   * @param form Only used for a "select" query.
   * @return
   * @throws Exception
   */
  public static QueryResult executeQuery(Model model, String sparqlQuery, String form) throws Exception {
    QueryExecution qe = null;
    try {
      Query query = QueryFactory.create(sparqlQuery);
      qe = QueryExecutionFactory.create(query, model);
      if ( log.isDebugEnabled() ) {
        log.debug("QueryExecution class: " +qe.getClass().getName());
      }
      return executeQuery(query, qe, sparqlQuery, form);
    }
    catch ( Throwable thr ) {
      String error = "Error preparing query.";
      throw new Exception(error, thr);
    }
    finally {
      if ( qe != null ) {
        qe.close();
      }
    }
  }
View Full Code Here

Examples of com.hp.hpl.jena.query.QueryExecution

    if ( entities == null ) {
      entities = new ArrayList<IndividualInfo>();
    }
   
    Query query = QueryFactory.create(INDIVIDUALS_QUERY);
    QueryExecution qe = QueryExecutionFactory.create(query, ontModel);
   
    ResultSet results = qe.execSelect();
   
    while ( results.hasNext() ) {
     
      String entityUri = null;
      String classUri = null;
View Full Code Here

Examples of com.hp.hpl.jena.query.QueryExecution

    if ( entities == null ) {
      entities = new ArrayList<PropertyInfo>();
    }
   
    Query query = QueryFactory.create(propertiesQuery);
    QueryExecution qe = QueryExecutionFactory.create(query, ontModel);
   
    ResultSet results = qe.execSelect();
   
    while ( results.hasNext() ) {
     
      String entityUri = null;
      String domainUri = null;
View Full Code Here

Examples of com.hp.hpl.jena.query.QueryExecution

    if ( entities == null ) {
      entities = new ArrayList<ClassInfo>();
    }
   
    Query query = QueryFactory.create(CLASSES_QUERY);
    QueryExecution qe = QueryExecutionFactory.create(query, ontModel);
   
    ResultSet results = qe.execSelect();
   
    while ( results.hasNext() ) {
      QuerySolution sol = results.nextSolution();
      Iterator<?> varNames = sol.varNames();
      while ( varNames.hasNext() ) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.