当前位置: 首页>>代码示例>>Java>>正文


Java StatementPattern.getContextVar方法代码示例

本文整理汇总了Java中org.openrdf.query.algebra.StatementPattern.getContextVar方法的典型用法代码示例。如果您正苦于以下问题:Java StatementPattern.getContextVar方法的具体用法?Java StatementPattern.getContextVar怎么用?Java StatementPattern.getContextVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openrdf.query.algebra.StatementPattern的用法示例。


在下文中一共展示了StatementPattern.getContextVar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的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.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;
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:24,代码来源:SubPropertyOf.java

示例3: 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;
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:32,代码来源:InverseObjectProperties.java

示例4: 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()));
        }
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:23,代码来源:TransitivePropertyVisitor.java

示例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;
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:21,代码来源:ObjectPropertyChain.java

示例6: meetSP

import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的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

示例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);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:38,代码来源:IntersectionOfVisitor.java

示例8: meetSP

import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的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

示例9: meetSP

import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
@Override
protected void meetSP(final StatementPattern node) throws Exception {
    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 && objVar.getValue() instanceof Resource && RDF.TYPE.equals(predVar.getValue()) && !EXPANDED.equals(conVar)) {
        final Resource object = (Resource) objVar.getValue();
        if (inferenceEngine.isEnumeratedType(object)) {
            final Set<BindingSet> solutions = new LinkedHashSet<>();
            final Set<Resource> enumeration = inferenceEngine.getEnumeration(object);
            for (final Resource enumType : enumeration) {
                final QueryBindingSet qbs = new QueryBindingSet();
                qbs.addBinding(subVar.getName(), enumType);
                solutions.add(qbs);
            }

            if (!solutions.isEmpty()) {
                final BindingSetAssignment enumNode = new BindingSetAssignment();
                enumNode.setBindingSets(solutions);

                node.replaceWith(enumNode);
                log.trace("Replacing node with inferred one of enumeration: " + enumNode);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:28,代码来源:OneOfVisitor.java

示例10: 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;
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:49,代码来源:AggregationPipelineQueryNode.java

示例11: getRange

import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
/**
 * Turn a single StatementPattern into a Range.
 * @param conf
 * @throws IOException if the range can't be resolved
 */
private Map.Entry<TABLE_LAYOUT, ByteRange> getRange(final StatementPattern sp) throws IOException {
    final Var context = sp.getContextVar();
    final Statement stmt = new NullableStatementImpl((Resource) sp.getSubjectVar().getValue(),
            (URI) sp.getPredicateVar().getValue(), sp.getObjectVar().getValue(),
            context == null ? null : (Resource) context.getValue());
    final RyaStatement rs = RdfToRyaConversions.convertStatement(stmt);
    final TriplePatternStrategy strategy = ryaContext.retrieveStrategy(rs);
    final Map.Entry<TABLE_LAYOUT, ByteRange> entry =
            strategy.defineRange(rs.getSubject(), rs.getPredicate(), rs.getObject(), rs.getContext(), conf);
    return entry;
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:17,代码来源:AccumuloQueryRuleset.java

示例12: meet

import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
@Override
public void meet(final StatementPattern pattern) {
	pattern.getSubjectVar().setValue(makeNativeValue(pattern.getSubjectVar().getValue()));
	pattern.getPredicateVar().setValue(makeNativeValue(pattern.getPredicateVar().getValue()));
	pattern.getObjectVar().setValue(makeNativeValue(pattern.getObjectVar().getValue()));
	
	if (pattern.getContextVar() != null) {
		pattern.getContextVar().setValue(makeNativeValue(pattern.getContextVar().getValue()));
	}
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:11,代码来源:CumulusQueryOptimizer.java

示例13: 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);
            }
        }
    }
 
开发者ID:apache,项目名称:incubator-rya,代码行数:71,代码来源:SubPropertyOfVisitor.java

示例14: 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 Var objVar = sp.getObjectVar();
        final Var conVar = sp.getContextVar();
        if (predVar != null && objVar != null && objVar.getValue() != null && RDF.TYPE.equals(predVar.getValue())
                && !EXPANDED.equals(conVar)) {
            /**
             * ?type sesame:directSubClassOf ub:Student . ?student rdf:type ?type +
             */
//            String s = UUID.randomUUID().toString();
//            Var typeVar = new Var(s);
//            StatementPattern subClassOf = new StatementPattern(typeVar, new Var("c-" + s, SESAME.DIRECTSUBCLASSOF), objVar, SUBCLASS_EXPANDED);
//            StatementPattern rdfType = new StatementPattern(sp.getSubjectVar(), sp.getPredicateVar(), typeVar, SUBCLASS_EXPANDED);
//            InferJoin join = new InferJoin(subClassOf, rdfType);
//            join.getProperties().put(InferConstants.INFERRED, InferConstants.TRUE);
//            node.replaceWith(join);

            final URI subclassof_uri = (URI) objVar.getValue();
            final Collection<URI> parents = InferenceEngine.findParents(inferenceEngine.getSubClassOfGraph(), subclassof_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.SUBCLASSOF), objVar, conVar);
                parents.add(subclassof_uri);
                for (final URI u : parents) {
                    fsp.statements.add(new NullableStatementImpl(u, RDFS.SUBCLASSOF, subclassof_uri));
                }

                final StatementPattern rdfType = new DoNotExpandSP(sp.getSubjectVar(), sp.getPredicateVar(), typeVar, conVar);
                final InferJoin join = new InferJoin(fsp, rdfType);
                join.getProperties().put(InferConstants.INFERRED, InferConstants.TRUE);
                node.replaceWith(join);
            }

//            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, predVar, new Var(objVar.getName(), u)));
//                }
//                node.replaceWith(statementPatterns);
//            }

//            if (parents != null && parents.size() > 0) {
//                VarCollection vc = new VarCollection();
//                vc.setName(objVar.getName());
//                vc.values.add(objVar);
//                for (URI u : parents) {
//                    vc.values.add(new Var(objVar.getName(), u));
//                }
//                Var subjVar = node.getSubjectVar();
//                node.replaceWith(new StatementPattern(subjVar, predVar, vc, node.getContextVar()));
//            }
        }
    }
 
开发者ID:apache,项目名称:incubator-rya,代码行数:59,代码来源:SubClassOfVisitor.java

示例15: isValidStarQuery

import org.openrdf.query.algebra.StatementPattern; //导入方法依赖的package包/类
public static boolean isValidStarQuery(final Collection<StatementPattern> nodes) {

        Set<String> bindings = null;
        boolean contextSet = false;
        Var context = null;

        if(nodes.size() < 2) {
            return false;
        }

        for(final StatementPattern sp: nodes) {

            final Var tempContext = sp.getContextVar();
            final Var predVar = sp.getPredicateVar();

            //does not support variable context
            if(tempContext != null && !tempContext.isConstant()) {
               return false;
            }
            if(!contextSet) {
                context = tempContext;
                contextSet = true;
            } else {

                if(context == null && tempContext != null) {
                    return false;
                } else if (context != null && !context.equals(tempContext)) {
                    return false;
                }
            }

            if(!predVar.isConstant()) {
                return false;
            }

            if(bindings == null ) {
                bindings = sp.getBindingNames();
                if(bindings.size() == 0) {
                    return false;
                }
            } else {
                bindings = Sets.intersection(bindings, sp.getBindingNames());
                if(bindings.size() == 0) {
                    return false;
                }
            }

        }


        return isBindingsetValid(bindings);
    }
 
开发者ID:apache,项目名称:incubator-rya,代码行数:53,代码来源:StarQuery.java


注:本文中的org.openrdf.query.algebra.StatementPattern.getContextVar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。