本文整理汇总了Java中org.openrdf.query.impl.MapBindingSet类的典型用法代码示例。如果您正苦于以下问题:Java MapBindingSet类的具体用法?Java MapBindingSet怎么用?Java MapBindingSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MapBindingSet类属于org.openrdf.query.impl包,在下文中一共展示了MapBindingSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Override
public void update(final AggregationElement aggregation, final AggregationState state, final VisibilityBindingSet childBindingSet) {
checkArgument(aggregation.getAggregationType() == AggregationType.MIN, "The MinFunction only accepts MIN AggregationElements.");
requireNonNull(state);
requireNonNull(childBindingSet);
// Only update the min if the child contains the binding that we are finding the min value for.
final String aggregatedName = aggregation.getAggregatedBindingName();
if(childBindingSet.hasBinding(aggregatedName)) {
final MapBindingSet result = state.getBindingSet();
final String resultName = aggregation.getResultBindingName();
final boolean newBinding = !result.hasBinding(resultName);
Value min;
if(newBinding) {
min = childBindingSet.getValue(aggregatedName);
} else {
final Value oldMin = result.getValue(resultName);
final Value chidlMin = childBindingSet.getValue(aggregatedName);
min = compare.compare(chidlMin, oldMin) < 0 ? chidlMin : oldMin;
}
result.addBinding(resultName, min);
}
}
示例2: update
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Override
public void update(final AggregationElement aggregation, final AggregationState state, final VisibilityBindingSet childBindingSet) {
checkArgument(aggregation.getAggregationType() == AggregationType.MAX, "The MaxFunction only accepts MAX AggregationElements.");
requireNonNull(state);
requireNonNull(childBindingSet);
// Only update the max if the child contains the binding that we are finding the max value for.
final String aggregatedName = aggregation.getAggregatedBindingName();
if(childBindingSet.hasBinding(aggregatedName)) {
final MapBindingSet result = state.getBindingSet();
final String resultName = aggregation.getResultBindingName();
final boolean newBinding = !result.hasBinding(resultName);
Value max;
if(newBinding) {
max = childBindingSet.getValue(aggregatedName);
} else {
final Value oldMax = result.getValue(resultName);
final Value childMax = childBindingSet.getValue(aggregatedName);
max = compare.compare(childMax, oldMax) > 0 ? childMax : oldMax;
}
result.addBinding(resultName, max);
}
}
示例3: update
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Override
public void update(final AggregationElement aggregation, final AggregationState state, final VisibilityBindingSet childBindingSet) {
checkArgument(aggregation.getAggregationType() == AggregationType.COUNT, "The CountFunction only accepts COUNT AggregationElements.");
requireNonNull(state);
requireNonNull(childBindingSet);
// Only add one to the count if the child contains the binding that we are counting.
final String aggregatedName = aggregation.getAggregatedBindingName();
if(childBindingSet.hasBinding(aggregatedName)) {
final MapBindingSet result = state.getBindingSet();
final String resultName = aggregation.getResultBindingName();
final boolean newBinding = !result.hasBinding(resultName);
if(newBinding) {
// Initialize the binding.
result.addBinding(resultName, new IntegerLiteralImpl(BigInteger.ONE));
} else {
// Update the existing binding.
final Literal count = (Literal) result.getValue(resultName);
final BigInteger updatedCount = count.integerValue().add( BigInteger.ONE );
result.addBinding(resultName, new IntegerLiteralImpl(updatedCount));
}
}
}
示例4: newLeftResult_noRightMatches
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void newLeftResult_noRightMatches() {
final IterativeJoin leftOuterJoin = new LeftOuterJoin();
// There is a new left result.
final MapBindingSet mapLeftResult = new MapBindingSet();
mapLeftResult.addBinding("name", vf.createLiteral("Bob"));
final VisibilityBindingSet newLeftResult = new VisibilityBindingSet(mapLeftResult);
// There are no right results that join with the left result.
final Iterator<VisibilityBindingSet> rightResults= new ArrayList<VisibilityBindingSet>().iterator();
// Therefore, the left result is a new join result.
final Iterator<VisibilityBindingSet> newJoinResultsIt = leftOuterJoin.newLeftResult(newLeftResult, rightResults);
final Set<BindingSet> newJoinResults = new HashSet<>();
while(newJoinResultsIt.hasNext()) {
newJoinResults.add( newJoinResultsIt.next() );
}
final Set<BindingSet> expected = Sets.<BindingSet>newHashSet( newLeftResult );
assertEquals(expected, newJoinResults);
}
示例5: changesNothing
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
/**
* This Projection enumerates all of the variables that were in the query, none of them are anonymous, and
* none of them insert constants.
*/
@Test
public void changesNothing() throws Exception {
// Read the projection object from a SPARQL query.
final Projection projection = getProjection(
"SELECT ?person ?employee ?business " +
"WHERE { " +
"?person <urn:talksTo> ?employee . " +
"?employee <urn:worksAt> ?business . " +
"}");
// Create a Binding Set that contains the result of the WHERE clause.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("employee", vf.createURI("urn:Bob"));
bs.addBinding("business", vf.createURI("urn:TacoJoint"));
final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
// Execute the projection.
final VisibilityBindingSet result = ProjectionEvaluator.make(projection).project(original);
assertEquals(original, result);
}
示例6: matches
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void matches() throws Exception {
// Read the filter object from a SPARQL query.
final Filter filter = getFilter(
"SELECT * " +
"WHERE { " +
"FILTER(?age < 10)" +
"?person <urn:age> ?age " +
"}");
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("age", vf.createLiteral(9));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bs);
// Test the evaluator.
assertTrue( FilterEvaluator.make(filter).filter(visBs) );
}
示例7: doesNotMatch
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void doesNotMatch() throws Exception {
// Read the filter object from a SPARQL query.
final Filter filter = getFilter(
"SELECT * " +
"WHERE { " +
"FILTER(?age < 10)" +
"?person <urn:age> ?age " +
"}");
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("age", vf.createLiteral(11));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bs);
// Test the evaluator.
assertFalse( FilterEvaluator.make(filter).filter(visBs) );
}
示例8: hashcode
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void hashcode() {
// Create a BindingSet, decorate it, and grab its hash code.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bSet = new MapBindingSet();
bSet.addBinding("name", vf.createLiteral("alice"));
final VisibilityBindingSet visSet = new VisibilityBindingSet(bSet);
final int origHash = visSet.hashCode();
// Add another binding to the binding set and grab the new hash code.
bSet.addBinding("age", vf.createLiteral(37));
final int updatedHash = visSet.hashCode();
// Show those hashes are different.
assertNotEquals(origHash, updatedHash);
}
示例9: unaryResult
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void unaryResult() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
bindingSet.addBinding("predicate", vf.createURI("urn:age"));
bindingSet.addBinding("object", vf.createLiteral(34));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final StatementOutputFormatter formatter = new StatementOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new UnaryResult(visBs)));
// Verify the mock was invoked with the expected output.
final VisibilityStatement expectedStmt = new VisibilityStatement(vf.createStatement(
vf.createURI("urn:Alice"),
vf.createURI("urn:age"),
vf.createLiteral(34)), "a");
verify(context, times(1)).forward(eq("key"), eq(expectedStmt));
}
示例10: min
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void min() throws Exception {
// A query that finds the minimum price for an item within the inventory.
final String sparql =
"SELECT (min(?price) as ?minPrice) { " +
"?item <urn:price> ?price . " +
"}";
// Create the Statements that will be loaded into Rya.
final ValueFactory vf = new ValueFactoryImpl();
final Collection<Statement> statements = Sets.newHashSet(
vf.createStatement(vf.createURI("urn:apple"), vf.createURI("urn:price"), vf.createLiteral(2.50)),
vf.createStatement(vf.createURI("urn:gum"), vf.createURI("urn:price"), vf.createLiteral(0.99)),
vf.createStatement(vf.createURI("urn:sandwich"), vf.createURI("urn:price"), vf.createLiteral(4.99)));
// Create the PCJ in Fluo and load the statements into Rya.
final String pcjId = loadDataAndCreateQuery(sparql, statements);
// Create the expected results of the SPARQL query once the PCJ has been computed.
final MapBindingSet expectedResult = new MapBindingSet();
expectedResult.addBinding("minPrice", vf.createLiteral(0.99));
// Ensure the last result matches the expected result.
final VisibilityBindingSet result = readLastResult(pcjId);
assertEquals(expectedResult, result);
}
示例11: max
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void max() throws Exception {
// A query that finds the maximum price for an item within the inventory.
final String sparql =
"SELECT (max(?price) as ?maxPrice) { " +
"?item <urn:price> ?price . " +
"}";
// Create the Statements that will be loaded into Rya.
final ValueFactory vf = new ValueFactoryImpl();
final Collection<Statement> statements = Sets.newHashSet(
vf.createStatement(vf.createURI("urn:apple"), vf.createURI("urn:price"), vf.createLiteral(2.50)),
vf.createStatement(vf.createURI("urn:gum"), vf.createURI("urn:price"), vf.createLiteral(0.99)),
vf.createStatement(vf.createURI("urn:sandwich"), vf.createURI("urn:price"), vf.createLiteral(4.99)));
// Create the PCJ in Fluo and load the statements into Rya.
final String pcjId = loadDataAndCreateQuery(sparql, statements);
// Create the expected results of the SPARQL query once the PCJ has been computed.
final MapBindingSet expectedResult = new MapBindingSet();
expectedResult.addBinding("maxPrice", vf.createLiteral(4.99));
// Ensure the last result matches the expected result.
final VisibilityBindingSet result = readLastResult(pcjId);
assertEquals(expectedResult, result);
}
示例12: sum
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void sum() throws Exception {
// A query that sums the counts of all of the items that are in the inventory.
final String sparql =
"SELECT (sum(?count) as ?itemSum) { " +
"?item <urn:count> ?count . " +
"}";
// Create the Statements that will be loaded into Rya.
final ValueFactory vf = new ValueFactoryImpl();
final Collection<Statement> statements = Sets.newHashSet(
vf.createStatement(vf.createURI("urn:apple"), vf.createURI("urn:count"), vf.createLiteral(5)),
vf.createStatement(vf.createURI("urn:gum"), vf.createURI("urn:count"), vf.createLiteral(7)),
vf.createStatement(vf.createURI("urn:sandwich"), vf.createURI("urn:count"), vf.createLiteral(2)));
// Create the PCJ in Fluo and load the statements into Rya.
final String pcjId = loadDataAndCreateQuery(sparql, statements);
// Create the expected results of the SPARQL query once the PCJ has been computed.
final MapBindingSet expectedResult = new MapBindingSet();
expectedResult.addBinding("itemSum", vf.createLiteral("14", XMLSchema.INTEGER));
// Ensure the last result matches the expected result.
final VisibilityBindingSet result = readLastResult(pcjId);
assertEquals(expectedResult, result);
}
示例13: average
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void average() throws Exception {
// A query that finds the average price for an item that is in the inventory.
final String sparql =
"SELECT (avg(?price) as ?averagePrice) { " +
"?item <urn:price> ?price . " +
"}";
// Create the Statements that will be loaded into Rya.
final ValueFactory vf = new ValueFactoryImpl();
final Collection<Statement> statements = Sets.newHashSet(
vf.createStatement(vf.createURI("urn:apple"), vf.createURI("urn:price"), vf.createLiteral(3)),
vf.createStatement(vf.createURI("urn:gum"), vf.createURI("urn:price"), vf.createLiteral(4)),
vf.createStatement(vf.createURI("urn:sandwich"), vf.createURI("urn:price"), vf.createLiteral(8)));
// Create the PCJ in Fluo and load the statements into Rya.
final String pcjId = loadDataAndCreateQuery(sparql, statements);
// Create the expected results of the SPARQL query once the PCJ has been computed.
final MapBindingSet expectedResult = new MapBindingSet();
expectedResult.addBinding("averagePrice", vf.createLiteral("5", XMLSchema.DECIMAL));
// Ensure the last result matches the expected result.
final VisibilityBindingSet result = readLastResult(pcjId);
assertEquals(expectedResult, result);
}
示例14: subjectWrongType
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
@Test
public void subjectWrongType() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createLiteral("Alice"));
bindingSet.addBinding("predicate", vf.createURI("urn:age"));
bindingSet.addBinding("object", vf.createLiteral(34));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final StatementOutputFormatter formatter = new StatementOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new UnaryResult(visBs)));
// Verify the mock was never invoked.
verify(context, times(0)).forward(any(), any());
}
示例15: readGroupedResults
import org.openrdf.query.impl.MapBindingSet; //导入依赖的package包/类
private Set<VisibilityBindingSet> readGroupedResults(final String pcjId, final VariableOrder groupByVars) {
requireNonNull(pcjId);
// Read the results from the Kafka topic. The last one for each set of Group By values is an aggregation result.
// The key in this map is a Binding Set containing only the group by variables.
final Map<BindingSet, VisibilityBindingSet> results = new HashMap<>();
try(final KafkaConsumer<String, VisibilityBindingSet> consumer = makeConsumer(pcjId)) {
final ConsumerRecords<String, VisibilityBindingSet> records = consumer.poll(5000);
final Iterator<ConsumerRecord<String, VisibilityBindingSet>> recordIterator = records.iterator();
while (recordIterator.hasNext()) {
final VisibilityBindingSet visBindingSet = recordIterator.next().value();
final MapBindingSet key = new MapBindingSet();
for(final String groupByBar : groupByVars) {
key.addBinding( visBindingSet.getBinding(groupByBar) );
}
results.put(key, visBindingSet);
}
}
return Sets.newHashSet( results.values() );
}