/** * {@inheritDoc} */ @Override public QuerySolution nextSolution() { return super.object.nextSolution(); }
/** * {@inheritDoc} */ public QuerySolution nextSolution() { row++; return results.nextSolution(); }
@Override public QuerySolution nextSolution() { return resultset.nextSolution(); }
/** * Turn the result set into a java.util.List * @param resultSet The result set * @return List of QuerySolutions */ static public List<QuerySolution> toList(ResultSet resultSet) { List<QuerySolution> list = new ArrayList<QuerySolution>() ; for ( ; resultSet.hasNext() ; ) { QuerySolution result = resultSet.nextSolution() ; list.add(result) ; } return list ; }
/** * Turn the result set into a java.util.List * @param resultSet The result set * @return List of QuerySolutions */ static public List<QuerySolution> toList(ResultSet resultSet) { List<QuerySolution> list = new ArrayList<QuerySolution>() ; for ( ; resultSet.hasNext() ; ) { QuerySolution result = resultSet.nextSolution() ; list.add(result) ; } return list ; }
public ResultSetWrapper(final ResultSet jenaResultSet) { final List<QuerySolution> solutions = new ArrayList<QuerySolution>(); while (jenaResultSet.hasNext()) { solutions.add(jenaResultSet.nextSolution()); } solutionsIter = solutions.iterator(); resultVars = jenaResultSet.getResultVars(); }
@Override public QuerySolution next() { if (resultSet.getRowNumber() >= offset && getRowNumber() < (offset + size)){ final QuerySolution solution = resultSet.nextSolution(); rows.add(solution); return solution; } throw new IllegalStateException("Invalid iterable state on this ResultSet!"); }
/** * Extracts a List filled with the binding of selectElement variable for each * query solution as RDFNodes (Resources or Literals). * Exhausts the result set. Create a rewindable one to use multiple times. * Suggested by James Howison * @see com.hp.hpl.jena.query.ResultSetFactory */ public static List<RDFNode> resultSetToList(ResultSet rs, String selectElement) { List<RDFNode> items = new ArrayList<RDFNode>() ; while (rs.hasNext()) { QuerySolution qs = rs.nextSolution() ; RDFNode n = qs.get(selectElement) ; items.add(n) ; } return items ; }
/** * Extracts a List filled with the binding of selectElement variable for each * query solution as RDFNodes (Resources or Literals). * Exhausts the result set. Create a rewindable one to use multiple times. * * @see com.hp.hpl.jena.query.ResultSetFactory */ public static List<RDFNode> resultSetToList(ResultSet rs, String selectElement) { // feature suggested by James Howison List<RDFNode> items = new ArrayList<RDFNode>() ; while (rs.hasNext()) { QuerySolution qs = rs.nextSolution() ; RDFNode n = qs.get(selectElement) ; items.add(n) ; } return items ; }
/** This operation faithfully walks the results but does nothing with them. * @return The count of the number of solutions. */ public static int consume(ResultSet resultSet) { int count = 0 ; for ( ; resultSet.hasNext() ; ) { // Force nodes to be materialized. QuerySolution result = resultSet.nextSolution() ; for ( Iterator<String> iter = result.varNames() ; iter.hasNext() ; ) { String vn = iter.next(); RDFNode n = result.get(vn) ; } count++ ; } return count ; }
/** This operation faithfully walks the results but does nothing with them. * @return The count of the number of solutions. */ public static int consume(ResultSet resultSet) { int count = 0 ; for ( ; resultSet.hasNext() ; ) { // Force nodes to be materialized. QuerySolution result = resultSet.nextSolution() ; for ( Iterator<String> iter = result.varNames() ; iter.hasNext() ; ) { String vn = iter.next(); RDFNode n = result.get(vn) ; } count++ ; } return count ; }
private List<T> processResults(ResultSet results) { List<T> result=Lists.newArrayList(); for(; results.hasNext();) { QuerySolution solution = results.nextSolution(); B builder = newBuilder(); solutionParser(). withSolution(solution). withBuilder(builder). parse(); result.add(builder.build()); } return result; }
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(); } }
private DataEntry getDataEntryFromRS(ResultSet rs) { DataEntry dataEntry = new DataEntry(); QuerySolution soln = rs.nextSolution(); String colName, value; boolean useColumnNumbers = this.isUsingColumnNumbers(); /* for each column get the colName and colValue and add to the data entry */ for (int i = 0; i < rs.getResultVars().size(); i++) { colName = rs.getResultVars().get(i); RDFNode node = soln.get(colName) ; if (node.isLiteral()) { value = convertRSToString(soln, colName); } else { value = soln.getResource(colName).getURI(); } dataEntry.addValue(useColumnNumbers ? Integer.toString(i + 1) : colName, new ParamValue(value)); } return dataEntry; }
public DataEntry getDataEntryFromRS(ResultSet rs) { DataEntry dataEntry = new DataEntry(); QuerySolution soln = rs.nextSolution(); String colName, value; boolean useColumnNumbers = this.isUsingColumnNumbers(); /* for each column get the colName and colValue and add to the data entry */ for (int i = 0; i < rs.getResultVars().size(); i++) { colName = rs.getResultVars().get(i); RDFNode node = soln.get(colName) ; if (node.isLiteral()) { value = convertRSToString(soln, colName); } else { value = soln.getResource(colName).getURI(); } dataEntry.addValue(useColumnNumbers ? Integer.toString(i + 1) : colName, new ParamValue(value)); } return dataEntry; }
/** Execute, expecting the result to be one row, one column. * Return that one RDFNode or null * Throw excpetion if more than one. */ public static RDFNode getOne(QueryExecution qExec, String varname) { try { ResultSet rs = qExec.execSelect() ; if ( ! rs.hasNext() ) return null ; QuerySolution qs = rs.nextSolution() ; RDFNode r = qs.get(varname) ; if ( rs.hasNext() ) throw new ARQException("More than one: var ?"+varname) ; return r ; } finally { qExec.close() ; } }
/** Execute, expecting the result to be one row, one column. Return that one RDFNode or throw an exception */ public static RDFNode getExactlyOne(QueryExecution qExec, String varname) { try { ResultSet rs = qExec.execSelect() ; if ( ! rs.hasNext() ) throw new ARQException("Not found: var ?"+varname) ; QuerySolution qs = rs.nextSolution() ; RDFNode r = qs.get(varname) ; if ( rs.hasNext() ) throw new ARQException("More than one: var ?"+varname) ; return r ; } finally { qExec.close() ; } }
/** Execute, expecting the result to be one row, one column. Return that one RDFNode or throw an exception */ public static RDFNode getExactlyOne(QueryExecution qExec, String varname) { try { ResultSet rs = qExec.execSelect() ; if ( ! rs.hasNext() ) throw new ARQException("Not found: var ?"+varname) ; QuerySolution qs = rs.nextSolution() ; RDFNode r = qs.get(varname) ; if ( rs.hasNext() ) throw new ARQException("More than one: var ?"+varname) ; return r ; } finally { qExec.close() ; } }
@SuppressWarnings("static-access") public void testGetLayer() { System.out.println("--------GetLayer-------\n"); String uri = "http://geni-orca.renci.org/owl/ben-dtn.rdf#Duke/Infinera/DTN/fB/1/ocgB/1"; System.out.println(ontProcessor.getOntModel().getResource(uri).getLocalName()); ResultSet results = ontProcessor.getLayer(ontProcessor.getOntModel(), uri); String layerName = null; String varName = (String) results.getResultVars().get(0); while (results.hasNext()) { layerName = results.nextSolution().getResource(varName).getLocalName(); System.out.println(layerName); } assertTrue(layerName != null); }
private static List<Pair<String, String>> storesByQuery(String fn) { Model model = FileManager.get().loadModel(fn) ; List<Pair<String, String>> data = new ArrayList<Pair<String, String>>(); Query query = QueryFactory.create(queryString) ; QueryExecution qExec = QueryExecutionFactory.create(query, model) ; try { ResultSet rs = qExec.execSelect() ; for ( ; rs.hasNext() ; ) { QuerySolution qs = rs.nextSolution() ; String label = qs.getLiteral("label").getLexicalForm() ; String desc = qs.getResource("desc").getURI() ; data.add(new Pair<String, String>(label, desc)) ; } } finally { qExec.close() ; } return data ; } }