本文整理汇总了Java中org.openrdf.query.algebra.StatementPattern.getObjectVar方法的典型用法代码示例。如果您正苦于以下问题:Java StatementPattern.getObjectVar方法的具体用法?Java StatementPattern.getObjectVar怎么用?Java StatementPattern.getObjectVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.query.algebra.StatementPattern
的用法示例。
在下文中一共展示了StatementPattern.getObjectVar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的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;
}
示例2: apply
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的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;
}
示例3: meetSP
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
@Override
protected void meetSP(final StatementPattern node) throws Exception {
final StatementPattern sp = node.clone();
final Var predVar = sp.getPredicateVar();
final URI pred = (URI) predVar.getValue();
final 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)) {
final URI transPropUri = (URI) predVar.getValue();
if (inferenceEngine.isTransitiveProperty(transPropUri)) {
node.replaceWith(new TransitivePropertySP(sp.getSubjectVar(), sp.getPredicateVar(), sp.getObjectVar(), sp.getContextVar()));
}
}
}
示例4: meet
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
@Override
public void meet(final StatementPattern node) throws Exception {
super.meet(node);
final Var subjectVar = node.getSubjectVar();
final RangeValue subjRange = rangeValues.get(subjectVar);
final Var predVar = node.getPredicateVar();
final RangeValue predRange = rangeValues.get(predVar);
final Var objVar = node.getObjectVar();
final RangeValue objRange = rangeValues.get(objVar);
if(subjRange != null) {
subjectVar.setValue(new RangeURI(subjRange));//Assumes no blank nodes can be ranges
}
if(predRange != null) {
predVar.setValue(new RangeURI(predRange));
}
if(objRange != null) {
objVar.setValue(objRange);
}
}
示例5: apply
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的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;
}
示例6: emit
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
private Rendering emit(final List<StatementPattern> bgp) {
if (bgp.isEmpty()) {
return this;
}
final Var c = bgp.get(0).getContextVar();
if (c != null) {
emit("GRAPH ").emit(c).emit(" ").openBrace();
}
StatementPattern l = null;
for (final StatementPattern n : bgp) {
final Var s = n.getSubjectVar();
final Var p = n.getPredicateVar();
final Var o = n.getObjectVar();
if (l == null) {
emit(s).emit(" ").emit(p).emit(" ").emit(o); // s p o
} else if (!l.getSubjectVar().equals(n.getSubjectVar())) {
emit(" .").newline().emit(s).emit(" ").emit(p).emit(" ").emit(o); // .\n s p o
} else if (!l.getPredicateVar().equals(n.getPredicateVar())) {
emit(" ;").newline().emit("\t").emit(p).emit(" ").emit(o); // ;\n\t p o
} else if (!l.getObjectVar().equals(n.getObjectVar())) {
emit(" , ").emit(o); // , o
}
l = n;
}
emit(" .");
if (c != null) {
closeBrace();
}
return this;
}
示例7: meetSP
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的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);
}
}
}
}
示例8: discoverPatterns
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
private void discoverPatterns(final StatementPattern pattern, final List<QueryModelNode> unmatched) {
final Var subj = pattern.getSubjectVar();
final Var objVar = pattern.getObjectVar();
patternMap.put(subj, pattern);
objectPatterns.put(objVar, pattern);
//check for existing filters.
if(unmatchedFilters.containsKey(objVar)) {
final Collection<FunctionCall> calls = unmatchedFilters.removeAll(objVar);
for(final FunctionCall call : calls) {
addFilter(call);
matchedFilters.put(objVar, call);
}
}
}
示例9: meetSP
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
/**
* Checks whether the StatementPattern is a type query whose solutions could be inferred by
* someValuesFrom inference, and if so, replaces the node with a union of itself and any
* possible inference.
*/
@Override
protected void meetSP(StatementPattern node) throws Exception {
final Var subjVar = node.getSubjectVar();
final Var predVar = node.getPredicateVar();
final Var objVar = node.getObjectVar();
// Only applies to type queries where the type is defined
if (predVar != null && RDF.TYPE.equals(predVar.getValue()) && objVar != null && objVar.getValue() instanceof Resource) {
final Resource typeToInfer = (Resource) objVar.getValue();
Map<Resource, Set<URI>> relevantSvfRestrictions = inferenceEngine.getSomeValuesFromByRestrictionType(typeToInfer);
if (!relevantSvfRestrictions.isEmpty()) {
// We can infer the queried type if it is to a someValuesFrom restriction (or a
// supertype of one), and the node in question (subjVar) is the subject of a triple
// whose predicate is the restriction's property and whose object is an arbitrary
// node of the restriction's value type.
final Var valueTypeVar = new Var("t-" + UUID.randomUUID());
final Var svfPredVar = new Var("p-" + UUID.randomUUID());
final Var neighborVar = new Var("n-" + UUID.randomUUID());
neighborVar.setAnonymous(true);
final StatementPattern membershipPattern = new DoNotExpandSP(neighborVar,
new Var(RDF.TYPE.stringValue(), RDF.TYPE), valueTypeVar);
final StatementPattern valuePattern = new StatementPattern(subjVar, svfPredVar, neighborVar);
final InferJoin svfPattern = new InferJoin(membershipPattern, valuePattern);
// Use a FixedStatementPattern to contain the appropriate (predicate, value type)
// pairs, and check each one against the general pattern.
final FixedStatementPattern svfPropertyTypes = new FixedStatementPattern(svfPredVar,
new Var(OWL.SOMEVALUESFROM.stringValue(), OWL.SOMEVALUESFROM), valueTypeVar);
for (Resource svfValueType : relevantSvfRestrictions.keySet()) {
for (URI svfProperty : relevantSvfRestrictions.get(svfValueType)) {
svfPropertyTypes.statements.add(new NullableStatementImpl(svfProperty,
OWL.SOMEVALUESFROM, svfValueType));
}
}
final InferJoin svfInferenceQuery = new InferJoin(svfPropertyTypes, svfPattern);
node.replaceWith(new InferUnion(node.clone(), svfInferenceQuery));
}
}
}
示例10: meetSP
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
/**
* Checks whether the StatementPattern is a type query whose solutions could be inferred
* by allValuesFrom inference, and if so, replaces the node with a union of itself and any
* possible inference.
*/
@Override
protected void meetSP(StatementPattern node) throws Exception {
final Var subjVar = node.getSubjectVar();
final Var predVar = node.getPredicateVar();
final Var objVar = node.getObjectVar();
// Only applies to type queries where the type is defined
if (predVar != null && RDF.TYPE.equals(predVar.getValue()) && objVar != null && objVar.getValue() instanceof Resource) {
final Resource typeToInfer = (Resource) objVar.getValue();
Map<Resource, Set<URI>> relevantAvfRestrictions = inferenceEngine.getAllValuesFromByValueType(typeToInfer);
if (!relevantAvfRestrictions.isEmpty()) {
// We can infer the queried type if, for an allValuesFrom restriction type
// associated with the queried type, some anonymous neighboring node belongs to the
// restriction type and has the node in question (subjVar) as a value for the
// restriction's property.
final Var avfTypeVar = new Var("t-" + UUID.randomUUID());
final Var avfPredVar = new Var("p-" + UUID.randomUUID());
final Var neighborVar = new Var("n-" + UUID.randomUUID());
neighborVar.setAnonymous(true);
final StatementPattern membershipPattern = new DoNotExpandSP(neighborVar,
new Var(RDF.TYPE.stringValue(), RDF.TYPE), avfTypeVar);
final StatementPattern valuePattern = new StatementPattern(neighborVar, avfPredVar, subjVar);
final InferJoin avfPattern = new InferJoin(membershipPattern, valuePattern);
// Use a FixedStatementPattern to contain the appropriate (restriction, predicate)
// pairs, and check each one against the general pattern.
final FixedStatementPattern avfPropertyTypes = new FixedStatementPattern(avfTypeVar,
new Var(OWL.ONPROPERTY.stringValue(), OWL.ONPROPERTY), avfPredVar);
for (Resource avfRestrictionType : relevantAvfRestrictions.keySet()) {
for (URI avfProperty : relevantAvfRestrictions.get(avfRestrictionType)) {
avfPropertyTypes.statements.add(new NullableStatementImpl(avfRestrictionType,
OWL.ONPROPERTY, avfProperty));
}
}
final InferJoin avfInferenceQuery = new InferJoin(avfPropertyTypes, avfPattern);
node.replaceWith(new InferUnion(node.clone(), avfInferenceQuery));
}
}
}
示例11: getMatchExpression
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
/**
* Given a StatementPattern, generate an object representing the arguments
* to a "$match" command that will find matching triples.
* @param sp The StatementPattern to search for
* @param path If given, specify the field that should be matched against
* the statement pattern, using an ordered list of field names for a nested
* field. E.g. to match records { "x": { "y": <statement pattern } }, pass
* "x" followed by "y".
* @return The argument of a "$match" query
*/
private static BasicDBObject getMatchExpression(StatementPattern sp, String ... path) {
final Var subjVar = sp.getSubjectVar();
final Var predVar = sp.getPredicateVar();
final Var objVar = sp.getObjectVar();
final Var contextVar = sp.getContextVar();
RyaURI s = null;
RyaURI p = null;
RyaType o = null;
RyaURI c = null;
if (subjVar != null && subjVar.getValue() instanceof Resource) {
s = RdfToRyaConversions.convertResource((Resource) subjVar.getValue());
}
if (predVar != null && predVar.getValue() instanceof URI) {
p = RdfToRyaConversions.convertURI((URI) predVar.getValue());
}
if (objVar != null && objVar.getValue() != null) {
o = RdfToRyaConversions.convertValue(objVar.getValue());
}
if (contextVar != null && contextVar.getValue() instanceof URI) {
c = RdfToRyaConversions.convertURI((URI) contextVar.getValue());
}
RyaStatement rs = new RyaStatement(s, p, o, c);
DBObject obj = strategy.getQuery(rs);
// Add path prefix, if given
if (path.length > 0) {
StringBuilder sb = new StringBuilder();
for (String str : path) {
sb.append(str).append(".");
}
String prefix = sb.toString();
Set<String> originalKeys = new HashSet<>(obj.keySet());
originalKeys.forEach(key -> {
Object value = obj.removeField(key);
obj.put(prefix + key, value);
});
}
return (BasicDBObject) obj;
}
示例12: toStatementPatternString
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
/**
* Provides a string representation of an SP which contains info about
* whether each component (subj, pred, obj) is constant and its data and
* data type if it is constant.
*
* @param sp - The statement pattern to convert. (not null)
* @return A String representation of the statement pattern that may be
* used to do triple matching.
*/
public static String toStatementPatternString(final StatementPattern sp) {
checkNotNull(sp);
final Var subjVar = sp.getSubjectVar();
String subj = subjVar.getName();
if(subjVar.getValue() != null) {
Value subjValue = subjVar.getValue();
if (subjValue instanceof BNode ) {
subj = subj + TYPE_DELIM + RyaSchema.BNODE_NAMESPACE + TYPE_DELIM + ((BNode) subjValue).getID();
} else {
subj = subj + TYPE_DELIM + URI_TYPE;
}
}
final Var predVar = sp.getPredicateVar();
String pred = predVar.getName();
if(predVar.getValue() != null) {
pred = pred + TYPE_DELIM + URI_TYPE;
}
final Var objVar = sp.getObjectVar();
String obj = objVar.getName();
if (objVar.getValue() != null) {
final RyaType rt = RdfToRyaConversions.convertValue(objVar.getValue());
obj = obj + TYPE_DELIM + rt.getDataType().stringValue();
}
return subj + DELIM + pred + DELIM + obj;
}
示例13: meet
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
@Override public void meet(final StatementPattern statement) {
final Var object = statement.getObjectVar();
if (propertyVars.contains(object)) {
if (usedVars.contains(object)) {
throw new IllegalArgumentException("Illegal search, variable is used multiple times as object: " + object.getName());
} else {
usedVars.add(object);
matchStatements.add(statement);
}
}
}
示例14: setStatementPatternAndProperties
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
/**
* Constructs a {@link StatementPattern} from the StatementPatterns
* representing a reified query. This StatementPattern has as a subject, the
* object of the StatementPattern containing the predicate
* {@link RDF#SUBJECT}. This StatementPattern has as predicate, the object
* of the StatementPattern containing the predicate {@link RDF#PREDICATE}.
* This StatementPattern has as an object, the object of the
* StatementPattern containing the predicate {@link RDF#OBJECT}. This method
* also builds a map between all predicates that are not of the above type
* and the object {@link Var}s they are associated with. This map contains
* the user specified metadata properties and is used for comparison with
* the metadata properties extracted from RyaStatements passed back by the
* {@link RyaQueryEngine}.
*
* @param patterns
* - collection of patterns representing a reified query
*/
private void setStatementPatternAndProperties(Collection<StatementPattern> patterns) {
StatementPattern sp = new StatementPattern();
Map<RyaURI, Var> properties = new HashMap<>();
for (final StatementPattern pattern : patterns) {
final RyaURI predicate = new RyaURI(pattern.getPredicateVar().getValue().toString());
if (!uriList.contains(predicate)) {
Var objVar = pattern.getObjectVar();
properties.put(predicate, objVar);
continue;
}
if (predicate.equals(SUBJ_ID_URI)) {
sp.setContextVar(pattern.getContextVar());
sp.setSubjectVar(pattern.getObjectVar());
}
if (predicate.equals(PRED_ID_URI)) {
sp.setPredicateVar(pattern.getObjectVar());
}
if (predicate.equals(OBJ_ID_URI)) {
sp.setObjectVar(pattern.getObjectVar());
}
}
this.statement = sp;
this.properties = properties;
}
示例15: meetSP
import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
@Override
protected void meetSP(final StatementPattern node) throws Exception {
final StatementPattern sp = node.clone();
final Var predVar = sp.getPredicateVar();
final URI pred = (URI) predVar.getValue();
final 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)) {
/**
*
* { ?subProp rdfs:subPropertyOf ub:worksFor . ?y ?subProp <http://www.Department0.University0.edu> }\n" +
" UNION " +
" { ?y ub:worksFor <http://www.Department0.University0.edu> }
*/
// String s = UUID.randomUUID().toString();
// Var subPropVar = new Var(s);
// StatementPattern subPropOf = new StatementPattern(subPropVar, new Var("c-" + s, SESAME.DIRECTSUBPROPERTYOF), predVar, EXPANDED);
// StatementPattern subPropOf2 = new StatementPattern(sp.getSubjectVar(), subPropVar, objVar, EXPANDED);
// InferJoin join = new InferJoin(subPropOf, subPropOf2);
// join.getProperties().put(InferConstants.INFERRED, InferConstants.TRUE);
// node.replaceWith(join);
// Collection<URI> parents = inferenceEngine.findParents(inferenceEngine.subPropertyOfGraph, (URI) predVar.getValue());
// if (parents != null && parents.size() > 0) {
// StatementPatterns statementPatterns = new StatementPatterns();
// statementPatterns.patterns.add(node);
// Var subjVar = node.getSubjectVar();
// for (URI u : parents) {
// statementPatterns.patterns.add(new StatementPattern(subjVar, new Var(predVar.getName(), u), objVar));
// }
// node.replaceWith(statementPatterns);
// }
// if (parents != null && parents.size() > 0) {
// VarCollection vc = new VarCollection();
// vc.setName(predVar.getName());
// vc.values.add(predVar);
// for (URI u : parents) {
// vc.values.add(new Var(predVar.getName(), u));
// }
// Var subjVar = node.getSubjectVar();
// node.replaceWith(new StatementPattern(subjVar, vc, objVar, node.getContextVar()));
// }
final URI subprop_uri = (URI) predVar.getValue();
final Set<URI> parents = InferenceEngine.findParents(inferenceEngine.getSubPropertyOfGraph(), subprop_uri);
if (parents != null && parents.size() > 0) {
final String s = UUID.randomUUID().toString();
final Var typeVar = new Var(s);
final FixedStatementPattern fsp = new FixedStatementPattern(typeVar, new Var("c-" + s, RDFS.SUBPROPERTYOF), predVar, cntxtVar);
// fsp.statements.add(new NullableStatementImpl(subprop_uri, RDFS.SUBPROPERTYOF, subprop_uri));
//add self
parents.add(subprop_uri);
for (final URI u : parents) {
fsp.statements.add(new NullableStatementImpl(u, RDFS.SUBPROPERTYOF, subprop_uri));
}
final StatementPattern rdfType = new DoNotExpandSP(sp.getSubjectVar(), typeVar, sp.getObjectVar(), cntxtVar);
final InferJoin join = new InferJoin(fsp, rdfType);
join.getProperties().put(InferConstants.INFERRED, InferConstants.TRUE);
node.replaceWith(join);
}
}
}