本文整理汇总了Java中org.openrdf.query.algebra.Extension类的典型用法代码示例。如果您正苦于以下问题:Java Extension类的具体用法?Java Extension怎么用?Java Extension使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Extension类属于org.openrdf.query.algebra包,在下文中一共展示了Extension类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUnsupportedExtension
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Test
public void testUnsupportedExtension() throws Exception {
StatementPattern sp = new StatementPattern(new Var("x"), constant(TAKES), new Var("c"));
List<ExtensionElem> elements = Arrays.asList(new ExtensionElem(new Var("x"), "renamed"),
new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"),
new ExtensionElem(new ValueConstant(TAKES), "constant"));
Extension extensionNode = new Extension(sp, elements);
QueryRoot queryTree = new QueryRoot(extensionNode);
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof Extension);
Assert.assertEquals(elements, ((Extension) queryTree.getArg()).getElements());
TupleExpr innerQuery = ((Extension) queryTree.getArg()).getArg();
Assert.assertTrue(innerQuery instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) innerQuery;
Assert.assertEquals(Sets.newHashSet("x", "c"), pipelineNode.getAssuredBindingNames());
}
示例2: make
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
/**
* Make a {@link MultiProjectionEvaluator} that processes the logic of a {@link MultiProjection}.
*
* @param multiProjection - Defines the projections that will be processed. (not null)
* @param bNodeIdFactory - Creates the IDs for Blank Nodes. (not null)
* @return A {@link MultiProjectionEvaluator} for the provided {@link MultiProjection}.
*/
public static MultiProjectionEvaluator make(final MultiProjection multiProjection, final BNodeIdFactory bNodeIdFactory) {
requireNonNull(multiProjection);
// Figure out if there are extensions.
final TupleExpr arg = multiProjection.getArg();
final Optional<Extension> extension = (arg instanceof Extension) ? Optional.of((Extension)arg): Optional.empty();
// If there are, iterate through them and find any blank node source names.
final Set<String> blankNodeSourceNames = new HashSet<>();
if(extension.isPresent()) {
for(final ExtensionElem elem : extension.get().getElements()) {
if(elem.getExpr() instanceof BNodeGenerator) {
blankNodeSourceNames.add( elem.getName() );
}
}
}
// Create a ProjectionEvaluator for each projection that is part of the multi.
final Set<ProjectionEvaluator> projections = new HashSet<>();
for(final ProjectionElemList projectionElemList : multiProjection.getProjections()) {
projections.add( new ProjectionEvaluator(projectionElemList, extension) );
}
return new MultiProjectionEvaluator(projections, blankNodeSourceNames, bNodeIdFactory);
}
示例3: meet
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Override
public void meet(Extension node) {
Set<String> argBindings = node.getArg().getBindingNames();
if (typeRequirement != null) {
node.getElements().removeIf(elem -> {
if (varName.equals(elem.getName())) {
ValueExpr expr = elem.getExpr();
if (expr == null) {
return true;
}
else if (expr instanceof Var) {
String fromName = ((Var) expr).getName();
if (getVarValue((Var) expr) == null && !argBindings.contains(fromName)) {
return true;
}
}
}
return false;
});
meetUnaryTupleOperator(node);
}
}
示例4: testConcreteSP
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Test
public void testConcreteSP() {
Extension extension = new Extension(new SingletonSet(),
new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"),
new ExtensionElem(new ValueConstant(RDF.TYPE), "y"),
new ExtensionElem(new ValueConstant(OWL.CLASS), "z"));
Projection projection = new Projection(extension, new ProjectionElemList(
new ProjectionElem("x", "subject"),
new ProjectionElem("y", "predicate"),
new ProjectionElem("z", "object")));
ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
projection.visit(visitor);
Set<StatementPattern> expected = Sets.newHashSet(
new StatementPattern(s(FOAF.PERSON), p(RDF.TYPE), o(OWL.CLASS)));
Assert.assertEquals(expected, visitor.getConsequents());
}
示例5: meet
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Override
public void meet(final Projection node) throws TopologyBuilderException {
final String id = PROJECTION_PREFIX + UUID.randomUUID();
final Optional<Side> side = getSide(node);
// If the arg is an Extension, there are rebindings that need to be
// ignored since they do not have a processor node.
TupleExpr downstreamNode = node.getArg();
if (downstreamNode instanceof Extension) {
downstreamNode = ((Extension) downstreamNode).getArg();
}
final ProjectionProcessorSupplier supplier = new ProjectionProcessorSupplier(
ProjectionEvaluator.make(node),
result -> getResult(side, result));
entries.add(new ProcessorEntry(node, id, side, supplier, Lists.newArrayList(downstreamNode)));
idMap.put(node, id);
super.meet(node);
}
示例6: meet
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Override
public void meet(final Extension n) {
emit(n.getArg());
if (!(n.getArg() instanceof SingletonSet)) {
newline();
}
boolean first = true;
for (final ExtensionElem e : n.getElements()) {
final ValueExpr expr = e.getExpr();
if (!(expr instanceof Var) || !((Var) expr).getName().equals(e.getName())) {
if (!first) {
newline();
}
emit("BIND (").emit(expr).emit(" AS ?").emit(e.getName()).emit(")");
first = false;
}
}
}
示例7: extractExtensions
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
private static Map<String, ExtensionElem> extractExtensions(final TupleExpr rootNode) {
final Map<String, ExtensionElem> map = Maps.newHashMap();
for (final UnaryTupleOperator node : extractQueryNodes(rootNode, true)) {
if (node instanceof Extension) {
for (final ExtensionElem elem : ((Extension) node).getElements()) {
final String variable = elem.getName();
final ValueExpr expression = elem.getExpr();
if (!(expression instanceof Var)
|| !((Var) expression).getName().equals(variable)) {
map.put(variable, elem);
}
}
}
}
return map;
}
示例8: testPropertyPattern_constantSubj
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Test
public void testPropertyPattern_constantSubj() throws Exception {
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
final Set<Resource> loveTypes = new HashSet<>();
loveTypes.add(narcissist);
when(inferenceEngine.getHasSelfImplyingProperty(love)).thenReturn(loveTypes);
final Var subj = new Var("s", self);
subj.setConstant(true);
final Var obj = new Var("o");
final Var pred = new Var("p", love);
pred.setConstant(true);
final Projection query = new Projection(new StatementPattern(subj, pred, obj),
new ProjectionElemList(new ProjectionElem("s", "subject")));
query.visit(new HasSelfVisitor(conf, inferenceEngine));
Assert.assertTrue(query.getArg() instanceof Union);
final Union union = (Union) query.getArg();
Assert.assertTrue(union.getRightArg() instanceof StatementPattern);
Assert.assertTrue(union.getLeftArg() instanceof Extension);
final StatementPattern expectedRight = new StatementPattern(subj, pred, obj);
final Extension expectedLeft = new Extension(
new StatementPattern(subj, new Var(RDF.TYPE.stringValue(), RDF.TYPE), new Var("urn:Narcissist", narcissist)),
new ExtensionElem(subj, "o"));
Assert.assertEquals(expectedLeft, union.getLeftArg());
Assert.assertEquals(expectedRight, union.getRightArg());
}
示例9: testPropertyPattern_constantObj
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Test
public void testPropertyPattern_constantObj() throws Exception {
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
final Set<Resource> loveTypes = new HashSet<>();
loveTypes.add(narcissist);
when(inferenceEngine.getHasSelfImplyingProperty(love)).thenReturn(loveTypes);
final Var subj = new Var("s");
final Var obj = new Var("o", self);
obj.setConstant(true);
final Var pred = new Var("p", love);
pred.setConstant(true);
final Projection query = new Projection(new StatementPattern(subj, pred, obj),
new ProjectionElemList(new ProjectionElem("s", "subject")));
query.visit(new HasSelfVisitor(conf, inferenceEngine));
Assert.assertTrue(query.getArg() instanceof Union);
final Union union = (Union) query.getArg();
Assert.assertTrue(union.getRightArg() instanceof StatementPattern);
Assert.assertTrue(union.getLeftArg() instanceof Extension);
final StatementPattern expectedRight = new StatementPattern(subj, pred, obj);
final Extension expectedLeft = new Extension(
new StatementPattern(obj, new Var(RDF.TYPE.stringValue(), RDF.TYPE), new Var("urn:Narcissist", narcissist)),
new ExtensionElem(obj, "s"));
Assert.assertEquals(expectedLeft, union.getLeftArg());
Assert.assertEquals(expectedRight, union.getRightArg());
}
示例10: meet
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Override
public void meet(Extension extensionNode) throws Exception {
extensionNode.visitChildren(this);
if (extensionNode.getArg() instanceof AggregationPipelineQueryNode && extensionNode.getParentNode() != null) {
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) extensionNode.getArg();
if (pipelineNode.extend(extensionNode.getElements())) {
extensionNode.replaceWith(pipelineNode);
}
}
}
示例11: testExtension
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Test
public void testExtension() throws Exception {
QueryRoot queryTree = new QueryRoot(new Extension(
new StatementPattern(new Var("x"), constant(TAKES), new Var("c")),
new ExtensionElem(new Var("x"), "renamed"),
new ExtensionElem(new ValueConstant(TAKES), "constant")));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
Assert.assertEquals(Sets.newHashSet("x", "c", "renamed", "constant"), pipelineNode.getAssuredBindingNames());
}
示例12: make
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
/**
* Make a {@link ProjectionEvaluator} that processes the logic of a {@link Projection}.
*
* @param projection - Defines the projection that will be processed. (not null)
* @return A {@link ProjectionEvaluator} for the provided {@link Projection}.
*/
public static ProjectionEvaluator make(final Projection projection) {
requireNonNull(projection);
final ProjectionElemList projectionElems = projection.getProjectionElemList();
final TupleExpr arg = projection.getArg();
final Optional<Extension> extension = arg instanceof Extension ? Optional.of((Extension)arg) : Optional.empty();
return new ProjectionEvaluator(projectionElems, extension);
}
示例13: makeId
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
private String makeId(final QueryModelNode node) {
checkNotNull(node);
// Create the prefix of the id. This makes it a little bit more human readable.
String prefix;
if (node instanceof StatementPattern) {
prefix = SP_PREFIX;
} else if (node instanceof Filter) {
prefix = FILTER_PREFIX;
} else if (node instanceof Join || node instanceof LeftJoin) {
prefix = JOIN_PREFIX;
} else if (node instanceof Projection) {
prefix = PROJECTION_PREFIX;
} else if(node instanceof Extension) {
prefix = AGGREGATION_PREFIX;
} else if (node instanceof Reduced) {
prefix = CONSTRUCT_PREFIX;
} else if(node instanceof PeriodicQueryNode) {
prefix = PERIODIC_QUERY_PREFIX;
} else {
throw new IllegalArgumentException("Node must be of type {StatementPattern, Join, Filter, Extension, Projection} but was " + node.getClass());
}
final String unique = UUID.randomUUID().toString().replaceAll("-", "");
// Put them together to create the Node ID.
return prefix + "_" + unique;
}
示例14: meet
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Override
public void meet(Projection projection) {
if (projection.getArg() instanceof Extension) {
recordConsequent(projection.getProjectionElemList(),
((Extension) projection.getArg()).getElements());
}
else {
recordConsequent(projection.getProjectionElemList(), Arrays.asList());
}
}
示例15: testGenericSP
import org.openrdf.query.algebra.Extension; //导入依赖的package包/类
@Test
public void testGenericSP() {
Extension extension = new Extension(new SingletonSet(),
new ExtensionElem(new Var("z"), "z"));
Projection projection = new Projection(extension, new ProjectionElemList(
new ProjectionElem("x", "subject"),
new ProjectionElem("y", "predicate"),
new ProjectionElem("z", "object")));
ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
projection.visit(visitor);
Set<StatementPattern> expected = Sets.newHashSet(
new StatementPattern(s(null), p(null), o(null)));
Assert.assertEquals(expected, visitor.getConsequents());
}