本文整理汇总了Java中org.openrdf.query.algebra.Union类的典型用法代码示例。如果您正苦于以下问题:Java Union类的具体用法?Java Union怎么用?Java Union使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Union类属于org.openrdf.query.algebra包,在下文中一共展示了Union类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
}
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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());
}
示例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());
}
示例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);
}