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


Java Var类代码示例

本文整理汇总了Java中org.openrdf.query.algebra.Var的典型用法代码示例。如果您正苦于以下问题:Java Var类的具体用法?Java Var怎么用?Java Var使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: apply

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

示例2: constructor_differentSubjects

import org.openrdf.query.algebra.Var; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void constructor_differentSubjects() throws Exception {
    final Var geoSubj = new Var("point");
    final Var geoPred = new Var("-const-http://www.opengis.net/ont/geosparql#asWKT", ValueFactoryImpl.getInstance().createURI("http://www.opengis.net/ont/geosparql#asWKT"));
    final Var geoObj = new Var("wkt");
    final StatementPattern geoSP = new StatementPattern(geoSubj, geoPred, geoObj);

    final Var timeSubj = new Var("time");
    final Var timePred = new Var("-const-http://www.w3.org/2006/time#inXSDDateTime", ValueFactoryImpl.getInstance().createURI("-const-http://www.w3.org/2006/time#inXSDDateTime"));
    final Var timeObj = new Var("time");
    final StatementPattern timeSP = new StatementPattern(timeSubj, timePred, timeObj);
    // This will fail.
    new EventQueryNode.EventQueryNodeBuilder()
        .setStorage(mock(EventStorage.class))
        .setGeoPattern(geoSP)
        .setTemporalPattern(timeSP)
        .setGeoFilters(new ArrayList<IndexingExpr>())
        .setTemporalFilters(new ArrayList<IndexingExpr>())
        .setUsedFilters(new ArrayList<>())
        .build();
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:22,代码来源:EventQueryNode2IT.java

示例3: meetSP

import org.openrdf.query.algebra.Var; //导入依赖的package包/类
/**
 * Check whether any solution for the {@link StatementPattern} could be derived from
 * reflexive property inference, and if so, replace the pattern with a union of itself and the
 * reflexive solution.
 */
@Override
protected void meetSP(StatementPattern node) throws Exception {
    // Only applies when the predicate is defined and reflexive
    final Var predVar = node.getPredicateVar();
    if (predVar.getValue() != null && inferenceEngine.isReflexiveProperty((URI) predVar.getValue())) {
        final StatementPattern originalSP = node.clone();
        // The reflexive solution is a ZeroLengthPath between subject and
        // object: they can be matched to one another, whether constants or
        // variables.
        final Var subjVar = node.getSubjectVar();
        final Var objVar = node.getObjectVar();
        final ZeroLengthPath reflexiveSolution = new ZeroLengthPath(subjVar, objVar);
        node.replaceWith(new InferUnion(originalSP, reflexiveSolution));
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:21,代码来源:ReflexivePropertyVisitor.java

示例4: extractConstructVar

import org.openrdf.query.algebra.Var; //导入依赖的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);
    }
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:20,代码来源:SPARQLRenderer.java

示例5: extractArguments

import org.openrdf.query.algebra.Var; //导入依赖的package包/类
private Value[] extractArguments(final String matchName, final FunctionCall call) {
    final Value args[] = new Value[call.getArgs().size() - 1];
    int argI = 0;
    for (int i = 0; i != call.getArgs().size(); ++i) {
        final ValueExpr arg = call.getArgs().get(i);
        if (argI == i && arg instanceof Var && matchName.equals(((Var)arg).getName())) {
            continue;
        }
        if (arg instanceof ValueConstant) {
            args[argI] = ((ValueConstant)arg).getValue();
        } else if (arg instanceof Var && ((Var)arg).hasValue()) {
            args[argI] = ((Var)arg).getValue();
        } else {
            throw new IllegalArgumentException("Query error: Found " + arg + ", expected a Literal, BNode or URI");
        }
        ++argI;
    }
    return args;
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:20,代码来源:FilterFunctionOptimizer.java

示例6: meet

import org.openrdf.query.algebra.Var; //导入依赖的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);
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:21,代码来源:FilterRangeVisitor.java

示例7: meet

import org.openrdf.query.algebra.Var; //导入依赖的package包/类
@Override
public void meet(final Extension n) {
    emit(n.getArg());
    if (!(n.getArg() instanceof SingletonSet)) {
        newline();
    }
    boolean first = true;
    for (final ExtensionElem e : n.getElements()) {
        final ValueExpr expr = e.getExpr();
        if (!(expr instanceof Var) || !((Var) expr).getName().equals(e.getName())) {
            if (!first) {
                newline();
            }
            emit("BIND (").emit(expr).emit(" AS ?").emit(e.getName()).emit(")");
            first = false;
        }
    }
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:19,代码来源:SPARQLRenderer.java

示例8: testReflexiveProperty

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

示例9: testTypePattern

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

示例10: getResultVarFromFunctionCall

import org.openrdf.query.algebra.Var; //导入依赖的package包/类
public static Var getResultVarFromFunctionCall(URI function, List<ValueExpr> args) {
    
    FUNCTION_TYPE type = SEARCH_FUNCTIONS.get(function);
    
    switch(type) {
    case GEO: 
        return findBinaryResultVar(args);
    case FREETEXT:
        return findLiteralResultVar(args);
    case TEMPORAL:
        return findBinaryResultVar(args);
    default:
        return null;
    }
    
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:17,代码来源:IndexingFunctionRegistry.java

示例11: testJoin

import org.openrdf.query.algebra.Var; //导入依赖的package包/类
@Test
public void testJoin() throws Exception {
    final AggregationPipelineQueryNode base = new AggregationPipelineQueryNode(
            collection,
            new LinkedList<>(),
            Sets.newHashSet("x", "y"),
            Sets.newHashSet("x", "y", "opt"),
            HashBiMap.create());
    // Join on one shared variable
    AggregationPipelineQueryNode node = base.clone();
    boolean success = node.joinWith(new StatementPattern(new Var("x"), constant(TAKES), new Var("c")));
    Assert.assertTrue(success);
    Assert.assertEquals(Sets.newHashSet("x", "y", "c", "opt"), node.getBindingNames());
    Assert.assertEquals(Sets.newHashSet("x", "y", "c"), node.getAssuredBindingNames());
    Assert.assertEquals(4, node.getPipeline().size());
    // Join on multiple shared variables
    node = base.clone();
    success = node.joinWith(new StatementPattern(new Var("x"), constant(TAKES), new Var("y")));
    Assert.assertTrue(success);
    Assert.assertEquals(Sets.newHashSet("x", "y", "opt"), node.getBindingNames());
    Assert.assertEquals(Sets.newHashSet("x", "y"), node.getAssuredBindingNames());
    Assert.assertEquals(5, node.getPipeline().size());
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:AggregationPipelineQueryNodeTest.java

示例12: testProjection

import org.openrdf.query.algebra.Var; //导入依赖的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());
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:18,代码来源:SparqlToPipelineTransformVisitorTest.java

示例13: testMultiProjection

import org.openrdf.query.algebra.Var; //导入依赖的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());
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:22,代码来源:SparqlToPipelineTransformVisitorTest.java

示例14: ConstructProjection

import org.openrdf.query.algebra.Var; //导入依赖的package包/类
public ConstructProjection(Var subjectVar, Var predicateVar, Var objectVar) {
    Preconditions.checkNotNull(subjectVar);
    Preconditions.checkNotNull(predicateVar);
    Preconditions.checkNotNull(objectVar);
    subjName = subjectVar.getName();
    predName = predicateVar.getName();
    objName = objectVar.getName();
    Preconditions.checkNotNull(subjName);
    Preconditions.checkNotNull(predName);
    Preconditions.checkNotNull(objName);
    this.subjVar = subjectVar;
    this.predVar = predicateVar;
    this.objVar = objectVar;
    if((subjVar.isAnonymous() || subjName.startsWith("-anon-")) && subjectVar.getValue() == null) {
        subjValue = Optional.of(new BNodeImpl(""));
    } else {
        subjValue = Optional.ofNullable(subjectVar.getValue());
    }
    predValue = Optional.ofNullable(predicateVar.getValue());
    objValue = Optional.ofNullable(objectVar.getValue());
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:22,代码来源:ConstructProjection.java

示例15: statementPatternToString

import org.openrdf.query.algebra.Var; //导入依赖的package包/类
@Test
public void statementPatternToString() throws MalformedQueryException {
       // Setup a StatementPattern that represents "?x <http://worksAt> <http://Chipotle>."
       final Var subject = new Var("x");
       final Var predicate = new Var("-const-http://worksAt", new URIImpl("http://worksAt"));
       predicate.setConstant(true);
       final Var object = new Var("-const-http://Chipotle", new URIImpl("http://Chipotle"));
       object.setConstant(true);
       final StatementPattern pattern = new StatementPattern(subject, predicate, object);

       // Convert the pattern to a String.
       final String spString = FluoStringConverter.toStatementPatternString(pattern);

       // Ensure it converted to the expected result.
       final String expected = "x:::" +
               "-const-http://worksAt<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" +
               "-const-http://Chipotle<<~>>http://www.w3.org/2001/XMLSchema#anyURI";

       assertEquals(spString, expected);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:21,代码来源:FluoStringConverterTest.java


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