本文整理汇总了Java中org.eclipse.rdf4j.query.BindingSet类的典型用法代码示例。如果您正苦于以下问题:Java BindingSet类的具体用法?Java BindingSet怎么用?Java BindingSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BindingSet类属于org.eclipse.rdf4j.query包,在下文中一共展示了BindingSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的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.BindingSet; //导入依赖的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.BindingSet; //导入依赖的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.BindingSet; //导入依赖的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: select
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的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();
}
}
示例6: buildPrefixes
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的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();
}
示例7: mapBindingSet
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的package包/类
private ImmutableMap<String, Object> mapBindingSet(BindingSet bindingSet,
Map<String, Property> itemProperties, ValueContext valueContext) {
ImmutableMap.Builder<String, Object> itemBuilder = new ImmutableMap.Builder<>();
itemProperties.forEach((name, property) -> {
if (property.getRequired() && !bindingSet.hasBinding(name)) {
throw new EntityMapperRuntimeException(String.format("Property '%s' is required.", name));
}
if (!bindingSet.hasBinding(name)) {
itemBuilder.put(name, Optional.absent());
return;
}
ValueContext newValueContext =
valueContext.toBuilder().value(bindingSet.getValue(name)).build();
itemBuilder.put(name, schemaMapperAdapter.mapTupleValue(property, newValueContext));
});
return itemBuilder.build();
}
示例8: writeTo_SparqlResultJsonFormat_ForQueryResult
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的package包/类
@Test
public void writeTo_SparqlResultJsonFormat_ForQueryResult() throws IOException {
// Arrange
final SparqlResultsJsonTupleEntityWriter provider = new SparqlResultsJsonTupleEntityWriter();
when(tupleEntity.getQueryResult()).thenReturn(tupleQueryResult);
when(tupleQueryResult.getBindingNames()).thenReturn(asList("beer"));
when(tupleQueryResult.hasNext()).thenReturn(true, true, false);
BindingSet bindingSetHeineken = mock(BindingSet.class);
BindingSet bindingSetAmstel = mock(BindingSet.class);
when(tupleQueryResult.next()).thenReturn(bindingSetHeineken, bindingSetAmstel);
configureBindingSetWithValue(bindingSetHeineken, "Heineken");
configureBindingSetWithValue(bindingSetAmstel, "Amstel");
// Act
provider.writeTo(tupleEntity, null, null, null, null, null, outputStream);
// Assert
verify(outputStream).write(byteCaptor.capture(), anyInt(), anyInt());
String result = new String(byteCaptor.getValue());
assertThat(result, containsString("{\"head\":{\"vars\":[\"beer\"]}"));
assertThat(result,
containsString(
"{\"bindings\":" + "[{\"beer\":{\"type\":\"literal\",\"value\":\"Heineken\"}},"
+ "{\"beer\":{\"type\":\"literal\",\"value\":\"Amstel\"}}]}}"));
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:27,代码来源:SparqlResultsJsonTupleEntityWriterTest.java
示例9: writeTo_SparqlResultJsonFormat_ForQueryResult
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的package包/类
@Test
public void writeTo_SparqlResultJsonFormat_ForQueryResult() throws IOException, JSONException {
// Arrange
final JsonTupleEntityWriter provider = new JsonTupleEntityWriter();
when(tupleEntity.getQueryResult()).thenReturn(tupleQueryResult);
when(tupleQueryResult.hasNext()).thenReturn(true, true, false);
BindingSet bindingSetHeineken = mock(BindingSet.class);
BindingSet bindingSetAmstel = mock(BindingSet.class);
when(tupleQueryResult.next()).thenReturn(bindingSetHeineken, bindingSetAmstel);
configureBindingSetWithValue(bindingSetHeineken, "Heineken");
configureBindingSetWithValue(bindingSetAmstel, "Amstel");
// Act
provider.writeTo(tupleEntity, null, null, null, null, null, outputStream);
// Assert
verify(outputStream).write(byteCaptor.capture(), anyInt(), anyInt());
String result = new String(byteCaptor.getValue());
JSONArray expected = new JSONArray().put(new JSONObject().put("beer", "Heineken")).put(
new JSONObject().put("beer", "Amstel"));
JSONAssert.assertEquals(expected.toString(), result, true);
}
示例10: writeTo_XmlFormat_ForQueryResult
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的package包/类
@Test
public void writeTo_XmlFormat_ForQueryResult() throws IOException, JSONException {
// Arrange
final XmlTupleEntityWriter provider = new XmlTupleEntityWriter();
when(tupleEntity.getQueryResult()).thenReturn(tupleQueryResult);
when(tupleQueryResult.hasNext()).thenReturn(true, true, false);
BindingSet bindingSetHeineken = mock(BindingSet.class);
BindingSet bindingSetAmstel = mock(BindingSet.class);
when(tupleQueryResult.next()).thenReturn(bindingSetHeineken, bindingSetAmstel);
configureBindingSetWithValue(bindingSetHeineken, "Heineken");
configureBindingSetWithValue(bindingSetAmstel, "Amstel");
// Act
provider.writeTo(tupleEntity, null, null, null, null, null, outputStream);
// Assert
verify(outputStream).write(byteCaptor.capture(), anyInt(), anyInt());
String result = new String(byteCaptor.getValue());
assertThat(result, containsString("<results>"));
assertThat(result, containsString("</results>"));
assertThat(result, containsString("<result>"));
assertThat(result, containsString("<beer>Heineken</beer>"));
assertThat(result, containsString("<beer>Amstel</beer>"));
}
示例11: constructStatementCheckId
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的package包/类
/**
* Construct the statement string, i.e. "s p ?o_varID FILTER ?o_N=o ". This kind of statement
* pattern is necessary to later on identify available results.
*
* @param stmt
* @param varID
* @param varNames
* @param bindings
* @return
*/
protected static TupleExpr constructStatementCheckId(StatementPattern stmt, int varID, Set<String> varNames, BindingSet bindings) {
String _varID = Integer.toString(varID);
Var subj = appendVarId(stmt.getSubjectVar(), _varID, varNames, bindings);
Var pred = appendVarId(stmt.getPredicateVar(), _varID, varNames, bindings);
Var obj = new Var("o_" + _varID);
varNames.add("o_" + _varID);
Value objValue;
if (stmt.getObjectVar().hasValue()) {
objValue = stmt.getObjectVar().getValue();
} else if (bindings.hasBinding(stmt.getObjectVar().getName())){
objValue = bindings.getBinding(stmt.getObjectVar().getName()).getValue();
} else {
// just to make sure that we see an error, will be deleted soon
throw new RuntimeException("Unexpected.");
}
Compare cmp = new Compare(obj, new ValueConstant(objValue));
cmp.setOperator(CompareOp.EQ);
Filter filter = new Filter( new StatementPattern(subj, pred, obj), cmp);
return filter;
}
示例12: evaluateBinaryTupleOperator
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的package包/类
/**
* Evaluate {@link BinaryTupleOperator} query model nodes
* @param parent
* @param expr
* @param bindings
*/
private void evaluateBinaryTupleOperator(BindingSetPipe parent, BinaryTupleOperator expr, BindingSet bindings) {
if (expr instanceof Join) {
evaluateJoin(parent, (Join) expr, bindings);
} else if (expr instanceof LeftJoin) {
evaluateLeftJoin(parent, (LeftJoin) expr, bindings);
} else if (expr instanceof Union) {
evaluateUnion(parent, (Union) expr, bindings);
} else if (expr instanceof Intersection) {
evaluateIntersection(parent, (Intersection) expr, bindings);
} else if (expr instanceof Difference) {
evaluateDifference(parent, (Difference) expr, bindings);
} else if (expr == null) {
parent.handleException(new IllegalArgumentException("expr must not be null"));
} else {
parent.handleException(new QueryEvaluationException("Unsupported binary tuple operator type: " + expr.getClass()));
}
}
示例13: call
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的package包/类
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> call() throws Exception {
try {
TripleSource t = endpoint.getTripleSource();
RepositoryConnection conn = endpoint.getConn();
boolean hasResults = t.hasStatements(stmt, conn, EmptyBindingSet.getInstance());
CacheEntry entry = CacheUtils.createCacheEntry(endpoint, hasResults);
sourceSelection.cache.updateEntry( new SubQuery(stmt), entry);
if (hasResults)
sourceSelection.addSource(stmt, new StatementSource(endpoint.getId(), StatementSourceType.REMOTE));
return null;
} catch (Exception e) {
throw new OptimizationException("Error checking results for endpoint " + endpoint.getId() + ": " + e.getMessage(), e);
}
}
示例14: evaluateIndependentJoinGroup
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的package包/类
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluateIndependentJoinGroup(
IndependentJoinGroup joinGroup, BindingSet bindings)
{
String preparedQuery = QueryStringUtil.selectQueryStringIndependentJoinGroup(joinGroup, bindings);
try {
List<StatementSource> statementSources = joinGroup.getMembers().get(0).getStatementSources(); // TODO this is only correct for the prototype (=> different endpoints)
CloseableIteration<BindingSet, QueryEvaluationException> result = evaluateAtStatementSources(preparedQuery, statementSources, joinGroup.getQueryInfo());
// return only those elements which evaluated positively at the endpoint
result = new IndependentJoingroupBindingsIteration(result, bindings);
// in order to avoid licking http route while iteration
return new BufferedCloseableIterator<BindingSet, QueryEvaluationException>(result);
} catch (Exception e) {
throw new QueryEvaluationException(e);
}
}
示例15: evaluateTupleExpr
import org.eclipse.rdf4j.query.BindingSet; //导入依赖的package包/类
/**
* Switch logic appropriate for each type of {@link TupleExpr} query model node, sending each type to it's appropriate evaluation method. For example,
* {@code UnaryTupleOperator} is sent to {@link evaluateUnaryTupleOperator()}.
* @param parent
* @param expr
* @param bindings
*/
private void evaluateTupleExpr(BindingSetPipe parent, TupleExpr expr, BindingSet bindings) {
if (expr instanceof StatementPattern) {
statementEvaluation.evaluateStatementPattern(parent, (StatementPattern) expr, bindings);
} else if (expr instanceof UnaryTupleOperator) {
evaluateUnaryTupleOperator(parent, (UnaryTupleOperator) expr, bindings);
} else if (expr instanceof BinaryTupleOperator) {
evaluateBinaryTupleOperator(parent, (BinaryTupleOperator) expr, bindings);
} else if (expr instanceof SingletonSet) {
evaluateSingletonSet(parent, (SingletonSet) expr, bindings);
} else if (expr instanceof EmptySet) {
evaluateEmptySet(parent, (EmptySet) expr, bindings);
} else if (expr instanceof ExternalSet) {
evaluateExternalSet(parent, (ExternalSet) expr, bindings);
} else if (expr instanceof ZeroLengthPath) {
evaluateZeroLengthPath(parent, (ZeroLengthPath) expr, bindings);
} else if (expr instanceof ArbitraryLengthPath) {
evaluateArbitraryLengthPath(parent, (ArbitraryLengthPath) expr, bindings);
} else if (expr instanceof BindingSetAssignment) {
evaluateBindingSetAssignment(parent, (BindingSetAssignment) expr, bindings);
} else if (expr == null) {
parent.handleException(new IllegalArgumentException("expr must not be null"));
} else {
parent.handleException(new QueryEvaluationException("Unsupported tuple expr type: " + expr.getClass()));
}
}