本文整理汇总了Java中org.openrdf.query.algebra.ProjectionElem类的典型用法代码示例。如果您正苦于以下问题:Java ProjectionElem类的具体用法?Java ProjectionElem怎么用?Java ProjectionElem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProjectionElem类属于org.openrdf.query.algebra包,在下文中一共展示了ProjectionElem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReflexiveProperty
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
@Test
public void testReflexiveProperty() throws Exception {
// Define a reflexive property
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
when(inferenceEngine.isReflexiveProperty(HAS_FAMILY)).thenReturn(true);
// Construct a query, then visit it
final StatementPattern sp = new StatementPattern(new Var("s", ALICE), new Var("p", HAS_FAMILY), new Var("o"));
final Projection query = new Projection(sp, new ProjectionElemList(new ProjectionElem("o", "member")));
query.visit(new ReflexivePropertyVisitor(conf, inferenceEngine));
// Expected structure after rewriting SP(:Alice :hasFamilyMember ?member):
//
// Union(
// originalSP(:Alice :hasFamilyMember ?member),
// ZeroLengthPath(:Alice, ?member)
// )
Assert.assertTrue(query.getArg() instanceof Union);
final TupleExpr left = ((Union) query.getArg()).getLeftArg();
final TupleExpr right = ((Union) query.getArg()).getRightArg();
Assert.assertEquals(sp, left);
Assert.assertTrue(right instanceof ZeroLengthPath);
Assert.assertEquals(sp.getSubjectVar(), ((ZeroLengthPath) right).getSubjectVar());
Assert.assertEquals(sp.getObjectVar(), ((ZeroLengthPath) right).getObjectVar());
}
示例2: testReflexivePropertyDisabled
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
@Test
public void testReflexivePropertyDisabled() throws Exception {
// Disable inference
final RdfCloudTripleStoreConfiguration disabledConf = conf.clone();
disabledConf.setInferReflexiveProperty(false);
// Define a reflexive property
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
when(inferenceEngine.isReflexiveProperty(HAS_FAMILY)).thenReturn(true);
// Construct a query, then make a copy and visit the copy
final Projection query = new Projection(
new StatementPattern(new Var("s", ALICE), new Var("p", HAS_FAMILY), new Var("o")),
new ProjectionElemList(new ProjectionElem("s", "subject")));
final Projection modifiedQuery = query.clone();
modifiedQuery.visit(new ReflexivePropertyVisitor(disabledConf, inferenceEngine));
// There should be no difference
Assert.assertEquals(query, modifiedQuery);
}
示例3: testSomeValuesFromDisabled
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
@Test
public void testSomeValuesFromDisabled() throws Exception {
// Disable someValuesOf inference
final AccumuloRdfConfiguration disabledConf = conf.clone();
disabledConf.setInferSomeValuesFrom(false);
// Configure a mock instance engine with an ontology:
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
Map<Resource, Set<URI>> personSVF = new HashMap<>();
personSVF.put(gradCourse, Sets.newHashSet(takesCourse));
personSVF.put(course, Sets.newHashSet(takesCourse));
personSVF.put(department, Sets.newHashSet(headOf));
personSVF.put(organization, Sets.newHashSet(worksFor, headOf));
when(inferenceEngine.getSomeValuesFromByRestrictionType(person)).thenReturn(personSVF);
// Query for a specific type visit -- should not change
StatementPattern originalSP = new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", person));
final Projection originalQuery = new Projection(originalSP, new ProjectionElemList(new ProjectionElem("s", "subject")));
final Projection modifiedQuery = originalQuery.clone();
modifiedQuery.visit(new SomeValuesFromVisitor(disabledConf, inferenceEngine));
Assert.assertEquals(originalQuery, modifiedQuery);
}
示例4: testTypePattern
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
@Test
public void testTypePattern() throws Exception {
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
final Set<URI> narcissistProps = new HashSet<>();
narcissistProps.add(love);
when(inferenceEngine.getHasSelfImplyingType(narcissist)).thenReturn(narcissistProps);
final Var subj = new Var("s");
final Var obj = new Var("o", narcissist);
obj.setConstant(true);
final Var pred = new Var("p", RDF.TYPE);
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 StatementPattern);
final StatementPattern expectedLeft = new StatementPattern(subj, pred, obj);
final StatementPattern expectedRight = new StatementPattern(subj, new Var("urn:love", love), subj);
Assert.assertEquals(expectedLeft, union.getLeftArg());
Assert.assertEquals(expectedRight, union.getRightArg());
}
示例5: testOneOfDisabled
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
@Test
public void testOneOfDisabled() throws Exception {
// Configure a mock instance engine with an ontology:
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
when(inferenceEngine.isEnumeratedType(SUITS)).thenReturn(true);
when(inferenceEngine.getEnumeration(SUITS)).thenReturn(CARD_SUIT_ENUMERATION);
when(inferenceEngine.isEnumeratedType(RANKS)).thenReturn(true);
when(inferenceEngine.getEnumeration(RANKS)).thenReturn(CARD_RANK_ENUMERATION);
// Query for a Suits and rewrite using the visitor:
final Projection query = new Projection(
new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", SUITS)),
new ProjectionElemList(new ProjectionElem("s", "subject")));
final AccumuloRdfConfiguration disabledConf = conf.clone();
disabledConf.setInferOneOf(false);
query.visit(new OneOfVisitor(disabledConf, inferenceEngine));
// Expected structure: the original statement:
assertTrue(query.getArg() instanceof StatementPattern);
final StatementPattern actualCardSuitSp = (StatementPattern) query.getArg();
final StatementPattern expectedCardSuitSp = new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", SUITS));
assertEquals(expectedCardSuitSp, actualCardSuitSp);
}
示例6: testProjection
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
@Test
public void testProjection() throws Exception {
StatementPattern isUndergrad = new StatementPattern(new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD));
StatementPattern isCourse = new StatementPattern(new Var("course"), constant(RDF.TYPE), constant(COURSE));
StatementPattern hasEdge = new StatementPattern(new Var("x"), new Var("p"), new Var("course"));
ProjectionElemList projectionElements = new ProjectionElemList(
new ProjectionElem("p", "relation"),
new ProjectionElem("course"));
QueryRoot queryTree = new QueryRoot(new Projection(
new Join(new Join(isCourse, hasEdge), isUndergrad),
projectionElements));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
Assert.assertEquals(Sets.newHashSet("relation", "course"), pipelineNode.getAssuredBindingNames());
}
示例7: testMultiProjection
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
@Test
public void testMultiProjection() throws Exception {
StatementPattern isUndergrad = new StatementPattern(new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD));
StatementPattern isCourse = new StatementPattern(new Var("course"), constant(RDF.TYPE), constant(COURSE));
StatementPattern hasEdge = new StatementPattern(new Var("x"), new Var("p"), new Var("course"));
ProjectionElemList courseHasRelation = new ProjectionElemList(
new ProjectionElem("p", "relation"),
new ProjectionElem("course"));
ProjectionElemList studentHasRelation = new ProjectionElemList(
new ProjectionElem("p", "relation"),
new ProjectionElem("x", "student"));
QueryRoot queryTree = new QueryRoot(new MultiProjection(
new Join(new Join(isCourse, hasEdge), isUndergrad),
Arrays.asList(courseHasRelation, studentHasRelation)));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
Assert.assertEquals(Sets.newHashSet("relation"), pipelineNode.getAssuredBindingNames());
Assert.assertEquals(Sets.newHashSet("relation", "course", "student"), pipelineNode.getBindingNames());
}
示例8: testConcreteSP
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的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());
}
示例9: meet
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
@Override
public void meet(final ProjectionElem n) {
final String source = n.getSourceName();
final String target = n.getTargetName();
final ValueExpr expr = n.getSourceExpression() == null ? null : n
.getSourceExpression().getExpr();
if (target.startsWith("-")) {
if (expr != null) {
emit("(").emit(expr).emit(" AS ?").emit(sanitize(target)).emit(")");
}
} else if (expr != null) {
emit("(").emit(expr).emit(" AS ?").emit(target).emit(")");
} else if (!equalOrNull(source, target)) {
emit("(?").emit(source).emit(" AS ?").emit(target).emit(")");
} else {
emit("?").emit(target);
}
}
示例10: extractConstructVar
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
private static Var extractConstructVar(final Map<String, ExtensionElem> extensions,
final ProjectionElem projection) {
final ExtensionElem extension = extensions.get(projection.getSourceName());
String name = projection.getSourceName();
if (name.startsWith("-anon-")) {
name += "-construct";
}
if (extension == null || extension.getExpr() instanceof BNodeGenerator) {
final Var var = new Var(name);
var.setAnonymous(name.startsWith("-anon-"));
return var;
} else if (extension.getExpr() instanceof ValueConstant) {
final ValueConstant constant = (ValueConstant) extension.getExpr();
return new Var(name, constant.getValue());
} else {
throw new UnsupportedOperationException(
"Unsupported extension in construct query: " + extension);
}
}
示例11: SQLSubQuery
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
public SQLSubQuery(String alias, Projection query, BindingSet bindings, Dataset dataset, ValueConverter converter, KiWiDialect dialect, Set<String> parentProjectedVars) throws UnsatisfiableQueryException {
super(alias);
Set<String> projectedVars = new HashSet<>(parentProjectedVars);
// count projected variables
for(ProjectionElem elem : query.getProjectionElemList().getElements()) {
projectedVars.add(elem.getSourceName());
}
// we build a full subquery for each of the UNION's arguments
builder = new SQLBuilder(query.getArg(), bindings, dataset, converter, dialect, projectedVars);
for(SQLVariable svl : builder.getVariables().values()) {
if(projectedVars.contains(svl.getSparqlName())) {
variables.add(svl);
}
}
}
示例12: testPropertyPattern_constantSubj
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的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());
}
示例13: testPropertyPattern_constantObj
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的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());
}
示例14: testOneOf
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
@Test
public void testOneOf() throws Exception {
// Configure a mock instance engine with an ontology:
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
when(inferenceEngine.isEnumeratedType(SUITS)).thenReturn(true);
when(inferenceEngine.getEnumeration(SUITS)).thenReturn(CARD_SUIT_ENUMERATION);
when(inferenceEngine.isEnumeratedType(RANKS)).thenReturn(true);
when(inferenceEngine.getEnumeration(RANKS)).thenReturn(CARD_RANK_ENUMERATION);
// Query for a Suits and rewrite using the visitor:
final Projection query = new Projection(
new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", SUITS)),
new ProjectionElemList(new ProjectionElem("s", "subject")));
query.visit(new OneOfVisitor(conf, inferenceEngine));
// Expected structure: BindingSetAssignment containing the enumeration:
// BindingSetAssignment(CLUBS, DIAMONDS, HEARTS, SPADES)
// Collect the arguments to the BindingSetAssignment:
assertTrue(query.getArg() instanceof BindingSetAssignment);
final BindingSetAssignment bsa = (BindingSetAssignment) query.getArg();
final Iterable<BindingSet> iterable = bsa.getBindingSets();
final Iterator<BindingSet> iter = iterable.iterator();
assertBindingSet(iter, CARD_SUIT_ENUMERATION.iterator());
// Query for a Ranks and rewrite using the visitor:
final Projection query2 = new Projection(
new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", RANKS)),
new ProjectionElemList(new ProjectionElem("s", "subject")));
query2.visit(new OneOfVisitor(conf, inferenceEngine));
// Expected structure: BindingSetAssignment containing the enumeration:
// BindingSetAssignment(ACE, 2, 3, 4, 5, 6, 7, 8, 9, 10, JACK, QUEEN, KING)
// Collect the arguments to the BindingSetAssignment:
assertTrue(query2.getArg() instanceof BindingSetAssignment);
final BindingSetAssignment bsa2 = (BindingSetAssignment) query2.getArg();
final Iterable<BindingSet> iterable2 = bsa2.getBindingSets();
final Iterator<BindingSet> iter2 = iterable2.iterator();
assertBindingSet(iter2, CARD_RANK_ENUMERATION.iterator());
}
示例15: project
import org.openrdf.query.algebra.ProjectionElem; //导入依赖的package包/类
/**
* Applies the projection to a value. If the result has a blank node whose ID is not mapped to a value in
* {@code blankNodes}, then a random UUID will be used.
*
* @param bs - The value the projection will be applied to. (not null)
* @param blankNodes - A map from node source names to the blank nodes that will be used for those names. (not null)
* @return A new value that is the result of the projection.
*/
public VisibilityBindingSet project(final VisibilityBindingSet bs, final Map<String, BNode> blankNodes) {
requireNonNull(bs);
requireNonNull(blankNodes);
// Apply the projection elements against the original binding set.
final MapBindingSet result = new MapBindingSet();
for (final ProjectionElem elem : projectionElems.getElements()) {
final String sourceName = elem.getSourceName();
Value value = null;
// If the binding set already has the source name, then use the target name.
if (bs.hasBinding(sourceName)) {
value = bs.getValue(elem.getSourceName());
}
// If the source name represents a constant value, then use the constant.
else if(constantSources.containsKey(sourceName)) {
value = constantSources.get(sourceName);
}
// If the source name represents an anonymous value, then create a Blank Node.
else if(anonymousSources.contains(sourceName)) {
if(blankNodes.containsKey(sourceName)) {
value = blankNodes.get(sourceName);
} else {
value = vf.createBNode( UUID.randomUUID().toString() );
}
}
// Only add the value if there is one. There may not be one if a binding is optional.
if(value != null) {
result.addBinding(elem.getTargetName(), value);
}
}
return new VisibilityBindingSet(result, bs.getVisibility());
}