本文整理匯總了Java中org.openrdf.query.TupleQueryResult.hasNext方法的典型用法代碼示例。如果您正苦於以下問題:Java TupleQueryResult.hasNext方法的具體用法?Java TupleQueryResult.hasNext怎麽用?Java TupleQueryResult.hasNext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openrdf.query.TupleQueryResult
的用法示例。
在下文中一共展示了TupleQueryResult.hasNext方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPredicates
import org.openrdf.query.TupleQueryResult; //導入方法依賴的package包/類
/**
* Get Predicate List
* @param endPointUrl SPARQL endPoint Url
* @param graph Named graph
* @return predLst Predicates List
*/
private static List<String> getPredicates(String endPointUrl, String graph) throws Exception
{
List<String> predLst = new ArrayList<String>();
String strQuery = getPredQuery(graph);
SPARQLRepository repo = new SPARQLRepository(endPointUrl);
repo.initialize();
RepositoryConnection conn = repo.getConnection();
try {
TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery);
TupleQueryResult res = query.evaluate();
while (res.hasNext())
{
String pred = res.next().getValue("p").toString();
predLst.add(pred);
}
} finally {
conn.close();
repo.shutDown();
}
return predLst;
}
示例2: runSPARQL
import org.openrdf.query.TupleQueryResult; //導入方法依賴的package包/類
/**
* Execute a SELECT SPARQL query against the graph
*
* @param qs
* SELECT SPARQL query
* @return list of solutions, each containing a hashmap of bindings
*/
public List runSPARQL(String qs) {
try {
RepositoryConnection con = therepository.getConnection();
try {
TupleQuery query = con.prepareTupleQuery(org.openrdf.query.QueryLanguage.SPARQL, qs);
TupleQueryResult qres = query.evaluate();
ArrayList reslist = new ArrayList();
while (qres.hasNext()) {
BindingSet b = qres.next();
Set names = b.getBindingNames();
HashMap hm = new HashMap();
for (Object n : names) {
hm.put((String) n, b.getValue((String) n));
}
reslist.add(hm);
}
return reslist;
} finally {
con.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例3: getSelect
import org.openrdf.query.TupleQueryResult; //導入方法依賴的package包/類
public static final <T> T getSelect( QueryExecutor<T> query,
RepositoryConnection rc, boolean dobindings ) throws RepositoryException,
MalformedQueryException, QueryEvaluationException {
String sparql = processNamespaces( dobindings ? query.getSparql()
: query.bindAndGetSparql(), query.getNamespaces() );
ValueFactory vfac = new ValueFactoryImpl();
TupleQuery tq = rc.prepareTupleQuery( QueryLanguage.SPARQL, sparql );
if ( null != query.getContext() ) {
DatasetImpl dataset = new DatasetImpl();
dataset.addDefaultGraph( query.getContext() );
tq.setDataset( dataset );
}
if ( dobindings ) {
tq.setIncludeInferred( query.usesInferred() );
query.setBindings( tq, vfac );
}
TupleQueryResult rslt = tq.evaluate();
query.start( rslt.getBindingNames() );
while ( rslt.hasNext() ) {
query.handleTuple( rslt.next(), vfac );
}
query.done();
rslt.close();
return query.getResults();
}