本文整理汇总了Java中org.eclipse.rdf4j.query.TupleQueryResult类的典型用法代码示例。如果您正苦于以下问题:Java TupleQueryResult类的具体用法?Java TupleQueryResult怎么用?Java TupleQueryResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TupleQueryResult类属于org.eclipse.rdf4j.query包,在下文中一共展示了TupleQueryResult类的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: aroundWriteTo_MapsEntity_ForTupleEntity
import org.eclipse.rdf4j.query.TupleQueryResult; //导入依赖的package包/类
@Test
public void aroundWriteTo_MapsEntity_ForTupleEntity() throws IOException {
// Arrange
TupleEntity entity = new TupleEntity(ImmutableMap.of(), mock(TupleQueryResult.class));
Object mappedEntity = ImmutableList.of();
when(contextMock.getEntity()).thenReturn(entity);
when(contextMock.getMediaType()).thenReturn(MediaType.APPLICATION_JSON_TYPE);
when(tupleEntityMapperMock.map(entity, MediaType.APPLICATION_JSON_TYPE)).thenReturn(
mappedEntity);
// Act
entityWriterInterceptor.aroundWriteTo(contextMock);
// Assert
verify(contextMock).setEntity(entityCaptor.capture());
verify(contextMock).proceed();
assertThat(entityCaptor.getValue(), equalTo(mappedEntity));
}
示例3: apply_ReturnsOkResponseWithEntityObject_ForTupleResult
import org.eclipse.rdf4j.query.TupleQueryResult; //导入依赖的package包/类
@Test
public void apply_ReturnsOkResponseWithEntityObject_ForTupleResult() {
// Arrange
UriInfo uriInfo = mock(UriInfo.class);
when(uriInfo.getPath()).thenReturn("/");
when(containerRequestContextMock.getUriInfo()).thenReturn(uriInfo);
TupleQueryResult result = mock(TupleQueryResult.class);
final Map<String, Property> schemaMap = ImmutableMap.of();
when(informationProductMock.getResult(ImmutableMap.of())).thenReturn(result);
when(informationProductMock.getResultType()).thenReturn(ResultType.TUPLE);
// Act
Response response = getRequestHandler.apply(containerRequestContextMock);
// Assert
assertThat(response.getStatus(), equalTo(Status.OK.getStatusCode()));
assertThat(response.getEntity(), instanceOf(TupleEntity.class));
assertThat(((TupleEntity) response.getEntity()).getResult(), equalTo(result));
assertThat(((TupleEntity) response.getEntity()).getSchemaMap(), equalTo(schemaMap));
}
示例4: 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);
}
示例5: apply
import org.eclipse.rdf4j.query.TupleQueryResult; //导入依赖的package包/类
@Override
public Response apply(ContainerRequestContext containerRequestContext) {
String path = containerRequestContext.getUriInfo().getPath();
LOG.debug("Handling GET request for path {}", path);
InformationProduct informationProduct = representation.getInformationProduct();
Map<String, String> parameterValues =
representationRequestParameterMapper.map(informationProduct, containerRequestContext);
representation.getParameterMappers().forEach(
parameterMapper -> parameterValues.putAll(parameterMapper.map(containerRequestContext)));
Object result = informationProduct.getResult(parameterValues);
if (ResultType.GRAPH.equals(informationProduct.getResultType())) {
return Response.ok(new GraphEntity((GraphQueryResult) result, representation)).build();
}
if (ResultType.TUPLE.equals(informationProduct.getResultType())) {
return Response.ok(new TupleEntity((TupleQueryResult) result, representation)).build();
}
throw new ConfigurationException(
String.format("Result type %s not supported for information product %s",
informationProduct.getResultType(), informationProduct.getIdentifier()));
}
示例6: apply_ReturnQueryRepresentation_WhenTupleQueryResult
import org.eclipse.rdf4j.query.TupleQueryResult; //导入依赖的package包/类
@Test
public void apply_ReturnQueryRepresentation_WhenTupleQueryResult() {
// Arrange
when(representation.getInformationProduct()).thenReturn(informationProduct);
TupleQueryResult queryResult = mock(TupleQueryResult.class);
when(informationProduct.getResult(ImmutableMap.of())).thenReturn(queryResult);
when(informationProduct.getResultType()).thenReturn(ResultType.TUPLE);
UriInfo uriInfo = mock(UriInfo.class);
when(containerRequestContext.getUriInfo()).thenReturn(uriInfo);
when(uriInfo.getPath()).thenReturn("/");
// Act
Response response = getRequestHandler.apply(containerRequestContext);
// Assert
assertThat(response.getStatus(), equalTo(200));
assertThat(response.getEntity(), instanceOf(TupleEntity.class));
TupleEntity entity = (TupleEntity) response.getEntity();
assertThat(entity.getQueryResult(), equalTo(queryResult));
assertThat(entity.getRepresentation(), equalTo(representation));
}
示例7: 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);
}
}
示例8: testSPARQLQueryCloseWait
import org.eclipse.rdf4j.query.TupleQueryResult; //导入依赖的package包/类
@Test
public void testSPARQLQueryCloseWait()
throws Exception {
try{
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 100";
MarkLogicTupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
for(int i=0; i<101; i++){
TupleQueryResult results = tupleQuery.evaluate(3,1);
// must close query result
results.close();
}
}
catch(Exception ex)
{
throw ex;
}
finally {
conn.close();
Thread.sleep(1000);
}
}
示例9: 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();
}
示例10: 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();
}
示例11: select
import org.eclipse.rdf4j.query.TupleQueryResult; //导入依赖的package包/类
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> select(Service service, Set<String> projectionVars, BindingSet bindings, String baseUri) throws QueryEvaluationException {
RepositoryConnection conn = endpoint.getConn();
try {
TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, service.getSelectQueryString(projectionVars), baseUri);
Iterator<Binding> bIter = bindings.iterator();
while (bIter.hasNext()) {
Binding b = bIter.next();
if (service.getServiceVars().contains(b.getName()))
query.setBinding(b.getName(), b.getValue());
}
TupleQueryResult qRes = query.evaluate();
return new InsertBindingsIteration(qRes, bindings);
} catch(Throwable e) {
throw new QueryEvaluationException(e);
} finally {
conn.close();
}
}
示例12: 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));
}
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}