本文整理汇总了Java中org.openrdf.query.algebra.Union类的典型用法代码示例。如果您正苦于以下问题:Java Union类的具体用法?Java Union怎么用?Java Union使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Union类属于org.openrdf.query.algebra包,在下文中一共展示了Union类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: apply
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
/**
* Transform a statement pattern according to OWL-2 subclass axiom.
*
* @param node the node to transform
* @return list of nodes to visit next
*/
@Override
public List<QueryModelNode> apply(StatementPattern node) {
List<QueryModelNode> next = newNextList();
StatementPattern left = node.clone();
// replace the object with the subclass
StatementPattern right
= new StatementPattern(
node.getSubjectVar(),
node.getPredicateVar(),
new ConstVar(vf.createURI(ce1)),
node.getContextVar());
node.replaceWith(
new Union(left, right));
next.add(left);
next.add(right);
return next;
}
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:24,代码来源:SubClassOf.java
示例2: apply
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
/**
* Transform a statement pattern according to OWL-2 subproperty axiom.
*
* @param node the node to transform
* @return list of nodes to visit next
*/
@Override
public List<QueryModelNode> apply(StatementPattern node) {
List<QueryModelNode> next = newNextList();
StatementPattern left = node.clone();
// replace the predicate with the subproperty
StatementPattern right
= new StatementPattern(
node.getSubjectVar(),
new ConstVar(vf.createURI(op1)),
node.getObjectVar(),
node.getContextVar());
node.replaceWith(
new Union(left, right));
next.add(left);
next.add(right);
return next;
}
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:24,代码来源:SubPropertyOf.java
示例3: apply
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
/**
* Transform a statement pattern according to OWL-2 inverse properties
* axiom.
*
* @param node the node to transform
* @return list of nodes to visit next
*/
@Override
public List<QueryModelNode> apply(StatementPattern node) {
List<QueryModelNode> next = newNextList();
Var s = node.getSubjectVar();
Var p = node.getPredicateVar();
Var o = node.getObjectVar();
Var c = node.getContextVar();
URI uri = (URI) p.getValue();
String op = uri.stringValue();
Var p2;
// check if need to replace with op1 or op2
if (op.equals(op1)) {
p2 = new ConstVar(vf.createURI(op2));
} else {
p2 = new ConstVar(vf.createURI(op1));
}
StatementPattern left = node.clone();
// switch subject and object and replace predicate
StatementPattern right = new StatementPattern(o, p2, s, c);
node.replaceWith(new Union(left, right));
next.add(left);
next.add(right);
return next;
}
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:32,代码来源:InverseObjectProperties.java
示例4: testReflexiveProperty
import org.openrdf.query.algebra.Union; //导入依赖的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());
}
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:ReflexivePropertyVisitorTest.java
示例5: testTypePattern
import org.openrdf.query.algebra.Union; //导入依赖的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());
}
开发者ID:apache,项目名称:incubator-rya,代码行数:26,代码来源:HasSelfVisitorTest.java
示例6: meet
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
public void meet(final Union union) {
boolean filterMoved = false;
if (Sets.intersection(union.getRightArg().getBindingNames(), filterVars).size() > 0) {
relocate(filter, union.getRightArg());
filterMoved = true;
}
if (Sets.intersection(union.getLeftArg().getBindingNames(), filterVars).size() > 0) {
if (filterMoved) {
final Filter clone = new Filter(filter.getArg(), filter.getCondition().clone());
relocate(clone, union.getLeftArg());
} else {
relocate(filter, union.getLeftArg());
}
}
}
开发者ID:apache,项目名称:incubator-rya,代码行数:18,代码来源:PCJOptimizerUtilities.java
示例7: meet
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
public void meet(final Union n) {
final TupleExpr l = n.getLeftArg();
final TupleExpr r = n.getRightArg();
final ZeroLengthPath p = l instanceof ZeroLengthPath ? (ZeroLengthPath) l
: r instanceof ZeroLengthPath ? (ZeroLengthPath) r : null;
if (p == null) {
emit(l, !(l instanceof Union)).emit(" UNION ").emit(r, !(r instanceof Union));
} else {
final Var s = p.getSubjectVar();
final Var o = p.getObjectVar();
final Var c = p.getContextVar();
if (c != null) {
emit("GRAPH ").emit(c).emit(" ").openBrace();
}
emit(s).emit(" ").emitPropertyPath(n, s, o).emit(" ").emit(o);
if (c != null) {
closeBrace();
}
}
}
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:22,代码来源:SPARQLRenderer.java
示例8: apply
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
/**
* Transform a statement pattern to infer triples for a predicate variable.
*
* @param node the node to transform
* @return list of nodes to visit next
*/
@Override
public List<QueryModelNode> apply(StatementPattern node) {
List<QueryModelNode> next = newNextList();
StatementPattern left = node.clone();
next.add(left);
TupleExpr right = assignPredicates(predicates, node.clone(), next);
node.replaceWith(new Union(left, right));
return next;
}
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:16,代码来源:PredicateVariable.java
示例9: apply
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
/**
* Transform a statement pattern according to OWL-2 property chain
* axiom.
*
* @param node the node to transform
* @return list of nodes to visit next
*/
@Override
public List<QueryModelNode> apply(StatementPattern node) {
List<QueryModelNode> next = newNextList();
Var s = node.getSubjectVar();
Var o = node.getObjectVar();
Var c = node.getContextVar();
TupleExpr left = node.clone();
TupleExpr right = getChain(s, o, c);
node.replaceWith(new Union(left, right));
next.add(left);
next.add(right);
return next;
}
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:21,代码来源:ObjectPropertyChain.java
示例10: meetSP
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
protected void meetSP(StatementPattern node) throws Exception {
StatementPattern sp = node.clone();
final Var predVar = sp.getPredicateVar();
URI pred = (URI) predVar.getValue();
String predNamespace = pred.getNamespace();
final Var objVar = sp.getObjectVar();
final Var cntxtVar = sp.getContextVar();
if (objVar != null &&
!RDF.NAMESPACE.equals(predNamespace) &&
!SESAME.NAMESPACE.equals(predNamespace) &&
!RDFS.NAMESPACE.equals(predNamespace)
&& !EXPANDED.equals(cntxtVar)) {
/**
*
* { ?a ?pred ?b .}\n" +
" UNION " +
" { ?b ?pred ?a }
*/
URI predUri = (URI) predVar.getValue();
URI invPropUri = inferenceEngine.findInverseOf(predUri);
if (invPropUri != null) {
Var subjVar = sp.getSubjectVar();
Union union = new InferUnion();
union.setLeftArg(sp);
union.setRightArg(new StatementPattern(objVar, new Var(predVar.getName(), invPropUri), subjVar, cntxtVar));
node.replaceWith(union);
}
}
}
开发者ID:apache,项目名称:incubator-rya,代码行数:34,代码来源:InverseOfVisitor.java
示例11: meetSP
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
protected void meetSP(final StatementPattern node) throws Exception {
final StatementPattern currentNode = node.clone();
final Var subVar = node.getSubjectVar();
final Var predVar = node.getPredicateVar();
final Var objVar = node.getObjectVar();
final Var conVar = node.getContextVar();
if (predVar != null && objVar != null && objVar.getValue() != null && RDF.TYPE.equals(predVar.getValue()) && !EXPANDED.equals(conVar)) {
final List<Set<Resource>> intersections = inferenceEngine.getIntersectionsImplying((URI) objVar.getValue());
if (intersections != null && !intersections.isEmpty()) {
final List<TupleExpr> joins = new ArrayList<>();
for (final Set<Resource> intersection : intersections) {
final Set<Resource> sortedIntersection = new TreeSet<>(new ResourceComparator());
sortedIntersection.addAll(intersection);
// Create a join tree of all statement patterns in the
// current intersection.
final TupleExpr joinTree = createJoinTree(new ArrayList<>(sortedIntersection), subVar, conVar);
if (joinTree != null) {
joins.add(joinTree);
}
}
if (!joins.isEmpty()) {
// Combine all the intersection join trees for the type
// together into a union tree. This will be a join tree if
// only one intersection exists.
final TupleExpr unionTree = createUnionTree(joins);
// Union the above union tree of intersections with the
// original node.
final Union union = new InferUnion(unionTree, currentNode);
node.replaceWith(union);
log.trace("Replacing node with inferred intersection union: " + union);
}
}
}
}
开发者ID:apache,项目名称:incubator-rya,代码行数:38,代码来源:IntersectionOfVisitor.java
示例12: meetSP
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
protected void meetSP(StatementPattern node) throws Exception {
StatementPattern sp = node.clone();
final Var predVar = sp.getPredicateVar();
URI pred = (URI) predVar.getValue();
String predNamespace = pred.getNamespace();
final Var objVar = sp.getObjectVar();
final Var cntxtVar = sp.getContextVar();
if (objVar != null &&
!RDF.NAMESPACE.equals(predNamespace) &&
!SESAME.NAMESPACE.equals(predNamespace) &&
!RDFS.NAMESPACE.equals(predNamespace)
&& !EXPANDED.equals(cntxtVar)) {
/**
*
* { ?a ?pred ?b .}\n" +
" UNION " +
" { ?b ?pred ?a }
*/
URI symmPropUri = (URI) predVar.getValue();
if(inferenceEngine.isSymmetricProperty(symmPropUri)) {
Var subjVar = sp.getSubjectVar();
Union union = new InferUnion();
union.setLeftArg(sp);
union.setRightArg(new StatementPattern(objVar, predVar, subjVar, cntxtVar));
node.replaceWith(union);
}
}
}
开发者ID:apache,项目名称:incubator-rya,代码行数:33,代码来源:SymmetricPropertyVisitor.java
示例13: testPropertyPattern_constantSubj
import org.openrdf.query.algebra.Union; //导入依赖的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());
}
开发者ID:apache,项目名称:incubator-rya,代码行数:28,代码来源:HasSelfVisitorTest.java
示例14: testPropertyPattern_constantObj
import org.openrdf.query.algebra.Union; //导入依赖的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());
}
开发者ID:apache,项目名称:incubator-rya,代码行数:28,代码来源:HasSelfVisitorTest.java
示例15: meetNode
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
public void meetNode(final QueryModelNode node) {
if (!(node instanceof Join || node instanceof LeftJoin
|| node instanceof StatementPattern || node instanceof Var
|| node instanceof Union || node instanceof Filter || node instanceof Projection)) {
isValid = false;
return;
}
super.meetNode(node);
}
开发者ID:apache,项目名称:incubator-rya,代码行数:11,代码来源:PCJOptimizerUtilities.java
示例16: meet
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
public void meet(Union node) throws RuntimeException {
setSeen(node);
super.meet(node);
}
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:6,代码来源:SeenVisitor.java
示例17: meet
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
public void meet(Union node) throws RuntimeException {
check(node);
super.meet(node);
}
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:6,代码来源:ConsistencyVisitor.java
示例18: meet
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
public void meet(Union node) throws Exception {
// if (!(node instanceof InferUnion))
super.meet(node);
}
开发者ID:apache,项目名称:incubator-rya,代码行数:6,代码来源:AbstractInferVisitor.java
示例19: testSomeValuesFrom
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Test
public void testSomeValuesFrom() throws Exception {
// 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 and rewrite using the visitor:
StatementPattern originalSP = new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", person));
final Projection query = new Projection(originalSP, new ProjectionElemList(new ProjectionElem("s", "subject")));
query.visit(new SomeValuesFromVisitor(conf, inferenceEngine));
// Expected structure: a union of two elements: one is equal to the original statement
// pattern, and the other one joins a list of predicate/value type combinations
// with another join querying for any nodes who are the subject of a triple with that
// predicate and with an object of that type.
//
// Union(
// SP(?node a :impliedType),
// Join(
// FSP(<?property someValuesFrom ?valueType> {
// takesCourse/Course;
// takesCourse/GraduateCourse;
// headOf/Department;
// headOf/Organization;
// worksFor/Organization;
// }),
// Join(
// SP(_:object a ?valueType),
// SP(?node ?property _:object)
// )
// )
Assert.assertTrue(query.getArg() instanceof Union);
TupleExpr left = ((Union) query.getArg()).getLeftArg();
TupleExpr right = ((Union) query.getArg()).getRightArg();
Assert.assertEquals(originalSP, left);
Assert.assertTrue(right instanceof Join);
final Join join = (Join) right;
Assert.assertTrue(join.getLeftArg() instanceof FixedStatementPattern);
Assert.assertTrue(join.getRightArg() instanceof Join);
FixedStatementPattern fsp = (FixedStatementPattern) join.getLeftArg();
left = ((Join) join.getRightArg()).getLeftArg();
right = ((Join) join.getRightArg()).getRightArg();
Assert.assertTrue(left instanceof StatementPattern);
Assert.assertTrue(right instanceof StatementPattern);
// Verify expected predicate/type pairs
Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(takesCourse, OWL.SOMEVALUESFROM, course)));
Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(takesCourse, OWL.SOMEVALUESFROM, gradCourse)));
Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(headOf, OWL.SOMEVALUESFROM, department)));
Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(headOf, OWL.SOMEVALUESFROM, organization)));
Assert.assertTrue(fsp.statements.contains(new NullableStatementImpl(worksFor, OWL.SOMEVALUESFROM, organization)));
Assert.assertEquals(5, fsp.statements.size());
// Verify pattern for matching instances of each pair: a Join of <_:x rdf:type ?t> and
// <?s ?p _:x> where p and t are the predicate/type pair and s is the original subject
// variable.
StatementPattern leftSP = (StatementPattern) left;
StatementPattern rightSP = (StatementPattern) right;
Assert.assertEquals(rightSP.getObjectVar(), leftSP.getSubjectVar());
Assert.assertEquals(RDF.TYPE, leftSP.getPredicateVar().getValue());
Assert.assertEquals(fsp.getObjectVar(), leftSP.getObjectVar());
Assert.assertEquals(originalSP.getSubjectVar(), rightSP.getSubjectVar());
Assert.assertEquals(fsp.getSubjectVar(), rightSP.getPredicateVar());
}
开发者ID:apache,项目名称:incubator-rya,代码行数:66,代码来源:SomeValuesFromVisitorTest.java
示例20: meet
import org.openrdf.query.algebra.Union; //导入依赖的package包/类
@Override
public void meet(Union node) {
nodes.add(node);
}
开发者ID:apache,项目名称:incubator-rya,代码行数:5,代码来源:OptionalJoinSegmentPCJMatcherTest.java
注:本文中的org.openrdf.query.algebra.Union类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论