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


Java StatementPattern类代码示例

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


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

示例1: meet

import org.openrdf.query.algebra.StatementPattern; //导入依赖的package包/类
/**
 * Visits a statement pattern and tries to transform using all rules
 * in the given rule set.
 * 
 * Tries to apply a rule from the rule set. If it is applicable
 * it will recurse using the visitor pattern to the nodes returned
 * from the rule after application.
 * @param node
 * @throws RuntimeException 
 */
@Override
public void meet(StatementPattern node) throws RuntimeException {
	// get a list of rules that may be applicable
	ArrayList<Rule> toApply = new ArrayList<>(getRules(node));
	for (Rule r : toApply) {
		// if a rule can be applied
		if (r.canApply(node)) {
			// apply the rule
			List<QueryModelNode> next = r.apply(node);
			// visit all nodes that the rule returned
			for (QueryModelNode toVisit : next) {
				removeRule(toApply, toVisit, r);
				toVisit.visit(this);
			}
			// halt execution, because the rule transformed the original
			// node and this visit can't transform further. Remaining rules
			// are applied in the recursion (see above).
			break;
		}
	}
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:32,代码来源:RuleTransformationVisitor.java

示例2: 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

示例3: 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

示例4: 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

示例5: meet

import org.openrdf.query.algebra.StatementPattern; //导入依赖的package包/类
public void meet(StatementPattern node) throws Exception
{
  if (node.getParentNode() instanceof Service && node.getSubjectVar().getName().equals("-const-http://www.bigdata.com/rdf#serviceParam-uri") && node.getPredicateVar().getName().equals("-const-http://wikiba.se/ontology#language-uri")) {
    this.add("LangService");

    // save first asked language
    String value = node.getObjectVar().getValue().stringValue();
    int index = value.indexOf(",");
    if (index != -1) {
      this.primaryLanguage = value.substring(0, index);
    } else {
      this.primaryLanguage = value;
    }
  }
  super.meetNode(node);
}
 
开发者ID:Wikidata,项目名称:QueryAnalysis,代码行数:17,代码来源:TupleExprSparqlStatisticsCollector.java

示例6: 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

示例7: getReplaceJoin

import org.openrdf.query.algebra.StatementPattern; //导入依赖的package包/类
private InferJoin getReplaceJoin(Set<Resource> uris, boolean subSubj, Var subjVar, Var objVar, Var predVar, Var cntxtVar){
    String s = UUID.randomUUID().toString();
    Var dummyVar = new Var(s);
    StatementPattern origStatement;
    Var subVar;
    if (subSubj){
    	subVar = subjVar;
    	origStatement = new DoNotExpandSP(dummyVar, predVar, objVar, cntxtVar);
    }
    else {
    	subVar = objVar;
    	origStatement = new DoNotExpandSP(subjVar, predVar, dummyVar, cntxtVar);
   }
    FixedStatementPattern fsp = new FixedStatementPattern(dummyVar, new Var("c-" + s, OWL.SAMEAS), subVar, cntxtVar);
    for (Resource sameAs : uris){
		NullableStatementImpl newStatement = new NullableStatementImpl(sameAs, OWL.SAMEAS, (Resource)subVar.getValue(), getVarValue(cntxtVar));
        fsp.statements.add(newStatement);        		
	}
    InferJoin join = new InferJoin(fsp, origStatement);
    join.getProperties().put(InferConstants.INFERRED, InferConstants.TRUE);
   return join;
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:23,代码来源:SameAsVisitor.java

示例8: buildQuery

import org.openrdf.query.algebra.StatementPattern; //导入依赖的package包/类
private void buildQuery(final TupleExpr tupleExpr, final StatementPattern matchStatement) {
    //If our IndexerExpr (to be) is the rhs-child of LeftJoin, we can safely make that a Join:
    //  the IndexerExpr will (currently) not return results that can deliver unbound variables.
    //This optimization should probably be generalized into a LeftJoin -> Join optimizer under certain conditions. Until that
    //  has been done, this code path at least takes care of queries generated by OpenSahara SparqTool that filter on OPTIONAL
    //  projections. E.g. summary~'full text search' (summary is optional). See #379
    if (matchStatement.getParentNode() instanceof LeftJoin) {
        final LeftJoin leftJoin = (LeftJoin)matchStatement.getParentNode();
        if (leftJoin.getRightArg() == matchStatement && leftJoin.getCondition() == null) {
            matchStatement.getParentNode().replaceWith(new Join(leftJoin.getLeftArg(), leftJoin.getRightArg()));
        }
    }
    final FilterFunction fVisitor = new FilterFunction(matchStatement.getObjectVar().getName());
    tupleExpr.visit(fVisitor);
    final List<IndexingExpr> results = Lists.newArrayList();
    for(int i = 0; i < fVisitor.func.size(); i++){
        results.add(new IndexingExpr(fVisitor.func.get(i), matchStatement, fVisitor.args.get(i)));
    }
    removeMatchedPattern(tupleExpr, matchStatement, new IndexerExprReplacer(results));
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:21,代码来源:FilterFunctionOptimizer.java

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

示例10: meet

import org.openrdf.query.algebra.StatementPattern; //导入依赖的package包/类
@Override
public void meet(final Filter node) throws Exception {
    super.meet(node);

    final ValueExpr condition = node.getCondition();
    final TupleExpr arg = node.getArg();
    if (!(arg instanceof Join)) {
        return;
    }

    final Join join = (Join) arg;
    final TupleExpr leftArg = join.getLeftArg();
    final TupleExpr rightArg = join.getRightArg();

    if (leftArg instanceof StatementPattern && rightArg instanceof StatementPattern) {
        final Filter left = new Filter(leftArg, condition);
        final Filter right = new Filter(rightArg, condition);
        node.replaceWith(new Join(left, right));
    }

}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:22,代码来源:SeparateFilterJoinsVisitor.java

示例11: getCardinality

import org.openrdf.query.algebra.StatementPattern; //导入依赖的package包/类
@Override
public double getCardinality(final StatementPattern node) {

    cardinality = super.getCardinality(node);

    // If sp contains all variables or is EmptyRDFtype, assign
    // cardinality
    // equal to table size
    if (cardinality == Double.MAX_VALUE || cardinality == Double.MAX_VALUE - 1) {
        try {
            cardinality = selectEvalStatsDAO.getTableSize(config);
        } catch (final Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return cardinality;
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:20,代码来源:RdfCloudTripleStoreSelectivityEvaluationStatistics.java

示例12: getBGP

import org.openrdf.query.algebra.StatementPattern; //导入依赖的package包/类
private static List<StatementPattern> getBGP(final QueryModelNode n) {
    if (n instanceof StatementPattern) {
        return Collections.singletonList((StatementPattern) n);
    } else if (!(n instanceof Join)) {
        return null;
    }
    final Join j = (Join) n;
    final List<StatementPattern> l = getBGP(j.getLeftArg());
    final List<StatementPattern> r = getBGP(j.getRightArg());
    if (l == null || r == null) {
        return null;
    }
    if (l.isEmpty()) {
        return r;
    } else if (r.isEmpty()) {
        return l;
    } else if (!equalOrNull(l.get(0).getContextVar(), r.get(0).getContextVar())) {
        return null;
    } else {
        final List<StatementPattern> s = new ArrayList<StatementPattern>(l.size() + r.size());
        s.addAll(l);
        s.addAll(r);
        return s;
    }
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:26,代码来源:SPARQLRenderer.java

示例13: testReflexiveProperty

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

示例14: testReflexivePropertyDisabled

import org.openrdf.query.algebra.StatementPattern; //导入依赖的package包/类
@Test
public void testReflexivePropertyDisabled() throws Exception {
    // Disable inference
    final RdfCloudTripleStoreConfiguration disabledConf = conf.clone();
    disabledConf.setInferReflexiveProperty(false);
    // Define a reflexive property
    final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
    when(inferenceEngine.isReflexiveProperty(HAS_FAMILY)).thenReturn(true);
    // Construct a query, then make a copy and visit the copy
    final Projection query = new Projection(
            new StatementPattern(new Var("s", ALICE), new Var("p", HAS_FAMILY), new Var("o")),
            new ProjectionElemList(new ProjectionElem("s", "subject")));
    final Projection modifiedQuery = query.clone();
    modifiedQuery.visit(new ReflexivePropertyVisitor(disabledConf, inferenceEngine));
    // There should be no difference
    Assert.assertEquals(query, modifiedQuery);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:18,代码来源:ReflexivePropertyVisitorTest.java

示例15: testSomeValuesFromDisabled

import org.openrdf.query.algebra.StatementPattern; //导入依赖的package包/类
@Test
public void testSomeValuesFromDisabled() throws Exception {
    // Disable someValuesOf inference
    final AccumuloRdfConfiguration disabledConf = conf.clone();
    disabledConf.setInferSomeValuesFrom(false);
    // 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 visit -- should not change
    StatementPattern originalSP = new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", person));
    final Projection originalQuery = new Projection(originalSP, new ProjectionElemList(new ProjectionElem("s", "subject")));
    final Projection modifiedQuery = originalQuery.clone();
    modifiedQuery.visit(new SomeValuesFromVisitor(disabledConf, inferenceEngine));
    Assert.assertEquals(originalQuery, modifiedQuery);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:21,代码来源:SomeValuesFromVisitorTest.java


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