本文整理汇总了Java中org.eclipse.rdf4j.query.TupleQueryResult.next方法的典型用法代码示例。如果您正苦于以下问题:Java TupleQueryResult.next方法的具体用法?Java TupleQueryResult.next怎么用?Java TupleQueryResult.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.rdf4j.query.TupleQueryResult
的用法示例。
在下文中一共展示了TupleQueryResult.next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
@Override
public void serialize(@NonNull TupleQueryResult tupleQueryResult,
@NonNull JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
throws IOException {
writeStart(jsonGenerator);
while (tupleQueryResult.hasNext()) {
writeStartItem(jsonGenerator);
BindingSet bindingSet = tupleQueryResult.next();
for (Binding binding : bindingSet) {
jsonGenerator.writeObjectField(binding.getName(), serializeValue(binding.getValue()));
}
writeEndItem(jsonGenerator);
}
writeEnd(jsonGenerator);
}
示例2: size
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* Returns number of triples in the entire triple store.
*
* @return long
* @throws RepositoryException
*/
@Override
public long size() throws RepositoryException{
try {
MarkLogicTupleQuery tupleQuery = prepareTupleQuery(COUNT_EVERYTHING);
tupleQuery.setIncludeInferred(false);
tupleQuery.setRulesets((SPARQLRuleset)null);
tupleQuery.setConstrainingQueryDefinition((QueryDefinition)null);
TupleQueryResult qRes = tupleQuery.evaluate();
// just one answer
BindingSet result = qRes.next();
qRes.close();
return ((Literal) result.getBinding("ct").getValue()).longValue();
} catch (QueryEvaluationException | MalformedQueryException e) {
throw new RepositoryException(e);
}
}
示例3: testSPARQLQueryWithRuleset
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
@Test
public void testSPARQLQueryWithRuleset()
throws Exception {
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 100 ";
MarkLogicTupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleQuery.setRulesets(SPARQLRuleset.RDFS_FULL);
TupleQueryResult results = tupleQuery.evaluate();
Assert.assertEquals(results.getBindingNames().get(0), "s");
Assert.assertEquals(results.getBindingNames().get(1), "p");
Assert.assertEquals(results.getBindingNames().get(2), "o");
BindingSet bindingSet = results.next();
Value sV = bindingSet.getValue("s");
Value pV = bindingSet.getValue("p");
Value oV = bindingSet.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#AttaliaGeodata", sV.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV.stringValue());
Assert.assertEquals("0", oV.stringValue());
results.close();
}
示例4: testSPARQLQueryWithMultipleRulesets
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
@Test
public void testSPARQLQueryWithMultipleRulesets()
throws Exception {
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 100 ";
MarkLogicTupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleQuery.setRulesets(SPARQLRuleset.RDFS_FULL,SPARQLRuleset.DOMAIN);
TupleQueryResult results = tupleQuery.evaluate();
Assert.assertEquals(results.getBindingNames().get(0), "s");
Assert.assertEquals(results.getBindingNames().get(1), "p");
Assert.assertEquals(results.getBindingNames().get(2), "o");
BindingSet bindingSet = results.next();
Value sV = bindingSet.getValue("s");
Value pV = bindingSet.getValue("p");
Value oV = bindingSet.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#AttaliaGeodata", sV.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV.stringValue());
Assert.assertEquals("0", oV.stringValue());
results.close();
}
示例5: executeQuery
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* Execute query and return the number of results
* @param query SPARQL query
* @param bgpGroups BGPs
* @param stmtToSources Triple Pattern to sources
* @param repo repository
* @return Number of results
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public static int executeQuery(String query, HashMap<Integer, List<StatementPattern>> bgpGroups, Map<StatementPattern, List<StatementSource>> stmtToSources, SPARQLRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String newQuery = QueryRewriting.doQueryRewriting(query,bgpGroups,stmtToSources);
System.out.println(newQuery);
TupleQuery tupleQuery = repo.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, newQuery);
int count = 0;
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
{
//System.out.println(result.next());
result.next();
count++;
}
return count;
}
示例6: executeQuery
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* Execute query and return the number of results
* @param query SPARQL query
* @param bgpGroups BGPs
* @param stmtToSources Triple Pattern to sources
* @param repo repository
* @return Number of results
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public static int executeQuery(String query, HashMap<Integer, List<StatementPattern>> bgpGroups, Map<StatementPattern, List<StatementSource>> stmtToSources, SPARQLRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String newQuery = QueryRewriting.doQueryRewriting(query,bgpGroups,stmtToSources);
// System.out.println(newQuery);
TupleQuery tupleQuery = repo.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, newQuery);
int count = 0;
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
{
//System.out.println(result.next());
result.next();
count++;
}
return count;
}
示例7: buildPrefixes
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
void buildPrefixes(RepositoryConnection conn, String query, SortedMap<KeyTuple, ValueTuple> prefixMap, boolean isSbjPrefix) {
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext())
{
BindingSet row = result.next();
String endpoint = row.getValue("url").stringValue();
String predicate = row.getValue("p").stringValue();
String prefix = row.getValue("prefix").stringValue();
long unique = Long.parseLong(row.getValue("unique").stringValue());
long card = Long.parseLong(row.getValue("card").stringValue());
//log.info(predicate + " : " + prefix + " : " + card);
String eid = getEID(endpoint);
KeyTuple kt = new KeyTuple(predicate, prefix);
updateMap(prefixMap, kt, eid);
KeyTuple kt0 = new KeyTuple(null, prefix);
updateMap(prefixMap, kt0, eid);
updateCapabilityPrefix(eid, predicate, prefix, unique, card, isSbjPrefix);
}
result.close();
}
示例8: getCurrentResult
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
private static Set<String> getCurrentResult(TupleQueryResult res) throws QueryEvaluationException
{
List<String> bindingNames = res.getBindingNames();
Set<String> curResults = new HashSet<String>() ;
while (res.hasNext()) {
BindingSet result = res.next();
String recordLine ="";
for(int i = 0 ; i < bindingNames.size(); i++)
{
String bindingName = bindingNames.get(i);
String bindingVal = result.getBinding(bindingName).getValue().toString().replaceAll("\n", " ").replace("]", "").replace("[", "");
if(i< bindingNames.size()-1)
recordLine = recordLine+bindingName+"="+bindingVal+";";
else
recordLine = recordLine+bindingName+"="+bindingVal;
}
curResults.add("["+recordLine+"]");
}
return curResults;
}
示例9: getStatementListBySPARQL
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* Executes SPARQL query against triplestore. Note, the query must return a list containing spoc in order to convert
* the results to a list of statements.
*
* @param sparqlQuery the SPARQL query
* @return list of statements returned by SPARQL query
* @throws Exception the exception
*/
public List<Statement> getStatementListBySPARQL(String sparqlQuery)
throws Exception {
List <Statement> stmts = new ArrayList <Statement>();
TupleQuery tupleQuery = getConnection().prepareTupleQuery(QueryLanguage.SPARQL, sparqlQuery);
TupleQueryResult resultset = tupleQuery.evaluate();
while (resultset.hasNext()) {
BindingSet bindingSet = resultset.next();
Statement stmt = getValueFactory().createStatement((Resource) bindingSet.getBinding("s").getValue(),
(IRI)bindingSet.getBinding("p").getValue(),
bindingSet.getBinding("o").getValue(),
(Resource) bindingSet.getBinding("c").getValue());
stmts.add(stmt);
}
return stmts;
}
示例10: testLikeAndNamespace
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
@Test
public void testLikeAndNamespace() throws Exception {
ValueFactory vf = con.getValueFactory();
con.add(vf.createIRI("urn:test/subjx"), vf.createIRI("urn:test/pred"), vf.createLiteral("valuex"));
con.add(vf.createIRI("urn:test/xsubj"), vf.createIRI("urn:test/pred"), vf.createLiteral("xvalue"));
String serql = "SELECT * FROM {s} test:pred {o} WHERE s LIKE \"urn:test/subj*\" USING NAMESPACE test = <urn:test/>";
TupleQueryResult res = con.prepareTupleQuery(QueryLanguage.SERQL, serql).evaluate();
assertTrue(res.hasNext());
res.next();
assertFalse(res.hasNext());
serql = "SELECT * FROM {s} test:pred {o} WHERE o LIKE \"value*\" USING NAMESPACE test = <urn:test/>";
res = con.prepareTupleQuery(QueryLanguage.SERQL, serql).evaluate();
assertTrue(res.hasNext());
res.next();
assertFalse(res.hasNext());
}
示例11: testSPARQLQueryWithPrepareQuery
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
@Test
public void testSPARQLQueryWithPrepareQuery()
throws Exception {
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 1 ";
Query q = conn.prepareQuery(QueryLanguage.SPARQL, queryString);
try {
if (q instanceof TupleQuery) {
TupleQueryResult result = ((TupleQuery) q).evaluate();
while (result.hasNext()) {
BindingSet tuple = result.next();
Assert.assertEquals("s", tuple.getBinding("s").getName());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#AttaliaGeodata", tuple.getBinding("s").getValue().stringValue());
}
result.close();
}
}
catch(Exception ex)
{
throw ex;
}
finally {
conn.close();
Thread.sleep(1000);
}
}
示例12: testSPARQLQueryWithDefaultInferred
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
@Test
public void testSPARQLQueryWithDefaultInferred()
throws Exception {
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 2 ";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleQuery.setIncludeInferred(true);
TupleQueryResult results = tupleQuery.evaluate();
Assert.assertEquals(results.getBindingNames().get(0), "s");
Assert.assertEquals(results.getBindingNames().get(1), "p");
Assert.assertEquals(results.getBindingNames().get(2), "o");
BindingSet bindingSet = results.next();
Value sV = bindingSet.getValue("s");
Value pV = bindingSet.getValue("p");
Value oV = bindingSet.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#AttaliaGeodata", sV.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV.stringValue());
Assert.assertEquals("0", oV.stringValue());
BindingSet bindingSet1 = results.next();
Value sV1 = bindingSet1.getValue("s");
Value pV1 = bindingSet1.getValue("p");
Value oV1 = bindingSet1.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#BabylonGeodata", sV1.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV1.stringValue());
Assert.assertEquals("0", oV1.stringValue());
results.close();
}
示例13: testSPARQLQueryWithPagination
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
@Test
public void testSPARQLQueryWithPagination()
throws Exception {
try{
for(int i=0; i<101; i++){
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 100 ";
MarkLogicTupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult results = tupleQuery.evaluate(3, 1);
Assert.assertEquals(results.getBindingNames().get(0), "s");
Assert.assertEquals(results.getBindingNames().get(1), "p");
Assert.assertEquals(results.getBindingNames().get(2), "o");
BindingSet bindingSet = results.next();
Value sV = bindingSet.getValue("s");
Value pV = bindingSet.getValue("p");
Value oV = bindingSet.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#BethanyBeyondtheJordanGeodata", sV.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV.stringValue());
Assert.assertEquals("0", oV.stringValue());
Assert.assertFalse(results.hasNext());
results.close();
}
}
catch(Exception ex)
{
throw ex;
}
finally {
conn.close();
Thread.sleep(1000);
}
}
示例14: testSPARQLQueryWithNullRulesets
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
@Test
public void testSPARQLQueryWithNullRulesets()
throws Exception {
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 100 ";
MarkLogicTupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleQuery.setRulesets(SPARQLRuleset.RDFS_FULL,null);
tupleQuery.setRulesets(null);
Assert.assertTrue(tupleQuery.getRulesets() == null);
TupleQueryResult results = tupleQuery.evaluate();
Assert.assertEquals(results.getBindingNames().get(0), "s");
Assert.assertEquals(results.getBindingNames().get(1), "p");
Assert.assertEquals(results.getBindingNames().get(2), "o");
BindingSet bindingSet = results.next();
Value sV = bindingSet.getValue("s");
Value pV = bindingSet.getValue("p");
Value oV = bindingSet.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#AttaliaGeodata", sV.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV.stringValue());
Assert.assertEquals("0", oV.stringValue());
results.close();
}
示例15: testPrepareQuery2
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
@Test
public void testPrepareQuery2() throws Exception {
Reader ir = new BufferedReader(new InputStreamReader(
MarkLogicRepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "property-paths.ttl")));
testAdminCon.add(ir, "", RDFFormat.TURTLE, (Resource) null);
StringBuilder queryBuilder = new StringBuilder(128);
queryBuilder.append(" prefix : <http://learningsparql.com/ns/papers#> ");
queryBuilder.append(" prefix c: <http://learningsparql.com/ns/citations#>");
queryBuilder.append(" SELECT ?s");
queryBuilder.append(" WHERE { ");
queryBuilder.append(" ?s ^c:cites :paperK2 . ");
queryBuilder.append(" FILTER (?s != :paperK2)");
queryBuilder.append(" } ");
queryBuilder.append(" ORDER BY ?s ");
Query query = testAdminCon.prepareQuery(queryBuilder.toString());
query.setBinding("whatcode", vf.createLiteral("33333"));
TupleQueryResult result = null;
if (query instanceof TupleQuery) {
result = ((TupleQuery) query).evaluate();
}
try {
assertThat(result, is(notNullValue()));
while (result.hasNext()) {
BindingSet solution = result.next();
assertThat(solution.hasBinding("s"), is(equalTo(true)));
Value totalResult = solution.getValue("s");
Assert.assertEquals(vf.createIRI("http://learningsparql.com/ns/papers#paperJ"), totalResult);
}
} finally {
result.close();
}
}