本文整理汇总了Java中org.eclipse.rdf4j.query.TupleQueryResult.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java TupleQueryResult.hasNext方法的具体用法?Java TupleQueryResult.hasNext怎么用?Java TupleQueryResult.hasNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.rdf4j.query.TupleQueryResult
的用法示例。
在下文中一共展示了TupleQueryResult.hasNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapCollection
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
private Object mapCollection(TupleEntity entity, ArrayProperty schema,
ValueContext valueContext) {
Property itemSchema = schema.getItems();
if (itemSchema == null) {
throw new EntityMapperRuntimeException("Array schemas must have an 'items' property.");
}
if (!(itemSchema instanceof ObjectProperty)) {
throw new EntityMapperRuntimeException(
"Only array items of type 'object' are supported for now.");
}
TupleQueryResult result = entity.getResult();
ImmutableList.Builder<Map<String, Object>> collectionBuilder = new ImmutableList.Builder<>();
Map<String, Property> itemProperties = ((ObjectProperty) itemSchema).getProperties();
while (result.hasNext()) {
collectionBuilder.add(mapBindingSet(result.next(), itemProperties, valueContext));
}
return collectionBuilder.build();
}
示例2: 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);
}
示例3: FedSumClassLookup
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* HiBISCuS Index lookup for rdf:type and its its corresponding values
* @param p Predicate i.e. rdf:type
* @param o Predicate value
* @param stmt Statement Pattern
* @throws RepositoryException Repository Error
* @throws MalformedQueryException Query Error
* @throws QueryEvaluationException Query Execution Error
*/
public void FedSumClassLookup(StatementPattern stmt, String p, String o) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String queryString = "Prefix ds:<http://aksw.org/fedsum/> "
+ "SELECT Distinct ?url "
+ " WHERE {?s ds:url ?url. "
+ " ?s ds:capability ?cap. "
+ " ?cap ds:predicate <" + p + ">."
+ "?cap ds:objAuthority <" + o + "> }" ;
TupleQuery tupleQuery = getSummaryConnection().prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
{
String endpoint = result.next().getValue("url").stringValue();
String id = "sparql_" + endpoint.replace("http://", "").replace("/", "_");
addSource(stmt, new StatementSource(id, StatementSourceType.REMOTE));
}
}
示例4: FedSumClassLookup
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* Index lookup for rdf:type and its its corresponding values
* @param p Predicate i.e. rdf:type
* @param o Predicate value
* @param stmt Statement Pattern
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public void FedSumClassLookup(StatementPattern stmt, String p, String o) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String queryString = "Prefix ds:<http://aksw.org/fedsum/> "
+ "SELECT Distinct ?url "
+ " WHERE {?s ds:url ?url. "
+ " ?s ds:capability ?cap. "
+ " ?cap ds:predicate <" + p + ">."
+ "?cap ds:objAuthority <" + o + "> }" ;
TupleQuery tupleQuery = FedSumConfig.con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
{
String endpoint = result.next().getValue("url").stringValue();
String id = "sparql_" + endpoint.replace("http://", "").replace("/", "_");
addSource(stmt, new StatementSource(id, StatementSourceType.REMOTE));
}
}
示例5: FedSumD_getMatchingSbjAuthorities
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* Get matching Subject authorities from a specific source for a triple pattern
* @param stmt Triple pattern
* @param src Capable source
* @return List of authorities
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public ArrayList<String> FedSumD_getMatchingSbjAuthorities(StatementPattern stmt, StatementSource src) throws RepositoryException, MalformedQueryException, QueryEvaluationException
{
String endPointUrl = "http://"+src.getEndpointID().replace("sparql_", "");
endPointUrl = endPointUrl.replace("_", "/");
ArrayList<String> sbjAuthorities = new ArrayList<String>();
String queryString = getFedSumSbjAuthLookupQuery(stmt, endPointUrl) ;
TupleQuery tupleQuery = FedSumConfig.con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
sbjAuthorities.add(result.next().getValue("sbjAuth").stringValue());
return sbjAuthorities;
}
示例6: getRankedSources
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
public static List<StatementSource> getRankedSources(Summary summary, String queryString, int k) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
List<StatementSource> rankedSources = new ArrayList<StatementSource>();
TupleQuery tupleQuery = summary.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, queryString);
//System.out.println(queryString);
TupleQueryResult result = tupleQuery.evaluate();
int count = 0 ;
while(result.hasNext() && count <k)
{
String endpoint = result.next().getValue("url").stringValue();
String id = "sparql_" + endpoint.replace("http://", "").replace("/", "_");
StatementSource src = new StatementSource(id, StatementSourceType.REMOTE);
rankedSources.add(src);
count++;
}
return rankedSources;
}
示例7: 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;
}
示例8: 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;
}
示例9: getFedSumDMatchingSbjAuthorities
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* Get matching Subject authorities from a specific source for a triple pattern
* @param stmt Triple pattern
* @param src Capable source
* @return List of authorities
*/
public ArrayList<String> getFedSumDMatchingSbjAuthorities(StatementPattern stmt, StatementSource src)
{
String endPointUrl = "http://" + src.getEndpointID().replace("sparql_", "");
endPointUrl = endPointUrl.replace("_", "/");
ArrayList<String> sbjAuthorities = new ArrayList<String>();
String queryString = getFedSumSbjAuthLookupQuery(stmt, endPointUrl) ;
TupleQuery tupleQuery = getSummaryConnection().prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext())
sbjAuthorities.add(result.next().getValue("sbjAuth").stringValue());
return sbjAuthorities;
}
示例10: getPredicates
import org.eclipse.rdf4j.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)
{
List<String> predLst = new ArrayList<String>();
String strQuery = getPredQury(graph);
SPARQLRepository repo = createSPARQLRepository(endPointUrl);
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);
}
res.close();
} finally {
conn.close();
}
return predLst;
}
示例11: mapObject
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
private Object mapObject(TupleEntity entity, ObjectProperty schema,
ValueContext valueContext) {
TupleQueryResult result = entity.getResult();
if (result.hasNext()) {
BindingSet bindingSet = result.next();
if (result.hasNext()) {
LOG.warn("TupleQueryResult yielded several bindingsets. Only parsing the first.");
}
return mapBindingSet(bindingSet, schema.getProperties(), valueContext);
} else {
throw new EntityMapperRuntimeException("TupleQueryResult did not yield any values.");
}
}
示例12: 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);
}
}
示例13: 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();
}
}
示例14: lookupFedSum
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* Search Quetzal index for the given triple pattern p with sbj authority and obj authority.
* Note: sa, oa can be null i.e. for unbound tuple
* @param stmt Statement pattern
* @param sa Subject authority
* @param p Predicate
* @param oa Object authority
*/
public void lookupFedSum(StatementPattern stmt, String sa, String p, String oa) {
String queryString = getFedSumLookupQuery(sa, p, oa) ;
TupleQuery tupleQuery = getSummaryConnection().prepareTupleQuery(QueryLanguage.SPARQL, queryString);
//System.out.println(queryString);
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
{
String endpoint = result.next().getValue("url").stringValue();
String id = "sparql_" + endpoint.replace("http://", "").replace("/", "_");
//System.out.println(stmt.getPredicateVar().getValue() + " source: " + id);
addSource(stmt, new StatementSource(id, StatementSourceType.REMOTE));
}
}
示例15: loadCommonPredList
import org.eclipse.rdf4j.query.TupleQueryResult; //导入方法依赖的package包/类
/**
* Load common predicate list using the threshold value specified as input
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public static void loadCommonPredList() throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String queryString = "Prefix ds:<http://aksw.org/fedsum/> "
+ "SELECT DISTINCT ?p "
+ " WHERE {?s ds:predicate ?p. }";
TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
ArrayList<String> FedSumPredicates = new ArrayList<String>();
while(result.hasNext())
{
FedSumPredicates.add(result.next().getValue("p").stringValue());
}
//---check each distinct
for(String predicate:FedSumPredicates)
{
int count = 0;
queryString = "Prefix ds:<http://aksw.org/fedsum/> "
+ "SELECT Distinct ?url "
+ " WHERE {?s ds:url ?url. "
+ " ?s ds:capability ?cap. "
+ " ?cap ds:predicate <" + predicate + "> }" ;
tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
result = tupleQuery.evaluate();
while(result.hasNext())
{
result.next();
count++;
}
double threshold = (double) count/dataSources.size();
if(threshold>=commonPredThreshold)
commonPredicates.add(predicate);
}
// System.out.println(commonPredicates);
}