Package com.hp.hpl.jena.query

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


        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


  private Map<Property, Integer> getHighDegreeProperties(String query,
      String resourceURI) {
    if (!supportsSPARQL11) return null;
    query = preProcessQuery(query, resourceURI);
    ResultSet rs = execQuerySelect(query);
    Map<Property, Integer> results = new HashMap<Property, Integer>();
    while (rs.hasNext()) {
      QuerySolution solution = rs.next();
      if (!solution.contains("p") || !solution.contains("count")) continue;
      Resource p = solution.get("p").asResource();
      int count = solution.get("count").asLiteral().getInt();
      results.put(ResourceFactory.createProperty(p.getURI()), count);
    }
View Full Code Here

  }
 
  @Override
  public List<Resource> getIndex() {
    List<Resource> result = new ArrayList<Resource>();
    ResultSet rs = execQuerySelect(
        "SELECT DISTINCT ?s { " +
        "?s ?p ?o " +
        "FILTER (isURI(?s)) " +
        "} LIMIT " + DataSource.MAX_INDEX_SIZE);
    while (rs.hasNext()) {
      result.add(rs.next().getResource("s"));
    }
    if (result.size() < DataSource.MAX_INDEX_SIZE) {
      rs = execQuerySelect(
          "SELECT DISTINCT ?o { " +
          "?s ?p ?o " +
          "FILTER (isURI(?o)) " +
          "} LIMIT " + (DataSource.MAX_INDEX_SIZE - result.size()));
      while (rs.hasNext()) {
        result.add(rs.next().getResource("o"));
      }
    }
    return result;
  }
View Full Code Here

                        "   (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

        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

    }

    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

    //

    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);
View Full Code Here

      // SELECT
      else if ( query.isSelectType() ) {
        if ( log.isDebugEnabled() ) {
          log.debug("Executing select: [" +sparqlQuery+ "] form=" +form);
        }
        ResultSet results = qe.execSelect();
        if ( log.isDebugEnabled() ) {
          log.debug("execSelect returned.");
        }
        boolean hasNext = results.hasNext();
        if ( log.isDebugEnabled() ) {
          log.debug("hasNext = " +hasNext);
        }
        queryResult.setIsEmpty(! hasNext);
View Full Code Here

    }
   
    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;
     
      QuerySolution sol = results.nextSolution();
      Iterator<?> varNames = sol.varNames();
      while ( varNames.hasNext() ) {
        String varName = String.valueOf(varNames.next());

        RDFNode rdfNode = sol.get(varName);
View Full Code Here

    }
   
    Query query = QueryFactory.create(propertiesQuery);
    QueryExecution qe = QueryExecutionFactory.create(query, ontModel);
   
    ResultSet results = qe.execSelect();
   
    while ( results.hasNext() ) {
     
      String entityUri = null;
      String domainUri = null;
     
      QuerySolution sol = results.nextSolution();
      Iterator<?> varNames = sol.varNames();
      while ( varNames.hasNext() ) {
        String varName = String.valueOf(varNames.next());

        RDFNode rdfNode = sol.get(varName);
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.query.ResultSet

Copyright © 2018 www.massapicom. 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.