本文整理汇总了Java中org.openrdf.query.parser.ParsedGraphQuery类的典型用法代码示例。如果您正苦于以下问题:Java ParsedGraphQuery类的具体用法?Java ParsedGraphQuery怎么用?Java ParsedGraphQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParsedGraphQuery类属于org.openrdf.query.parser包,在下文中一共展示了ParsedGraphQuery类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: SpinConstructRule
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
/**
* Instantiate a SPIN construct rule given its associated type, URI or bnode
* identifier, and construct query tree. Modifies the query tree to
* incorporate the fact that ?this must belong to the associated type, and
* traverses the modified tree to find antecedent and consequent triple
* patterns.
* @param type This rule applies to objects of this type. Should not be
* null. If the type is owl:Thing or rdfs:Resource, it will be applied to
* any objects. Otherwise, a statement pattern will be added that
* effectively binds ?this to members of the type. Therefore, passing
* owl:Thing or rdfs:Resource yields the intended behavior of
* sp:thisUnbound.
* @param ruleId The Resource representing this rule in the RDF data;
* should not be null.
* @param graphQuery The query tree corresponding to the "construct" text;
* should not be null.
*/
public SpinConstructRule(Resource type, Resource ruleId,
ParsedGraphQuery graphQuery) {
Preconditions.checkNotNull(type);
Preconditions.checkNotNull(ruleId);
Preconditions.checkNotNull(graphQuery);
this.ruleId = ruleId;
this.graphQuery = graphQuery;
// Add the type requirement: ?this must belong to the type
graphQuery.getTupleExpr().visit(new TypeRequirementVisitor("this", type));
// Find all statement patterns that could trigger this rule
AntecedentVisitor aVisitor = new AntecedentVisitor();
graphQuery.getTupleExpr().visit(aVisitor);
antecedentStatementPatterns = aVisitor.getAntecedents();
// Construct statement patterns for all possible conclusions of this rule
ConstructConsequentVisitor cVisitor = new ConstructConsequentVisitor();
graphQuery.getTupleExpr().visit(cVisitor);
consequentStatementPatterns = cVisitor.getConsequents();
}
开发者ID:apache,项目名称:incubator-rya,代码行数:36,代码来源:SpinConstructRule.java
示例2: testGeneralConsequent
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
@Test
public void testGeneralConsequent() throws Exception {
String text = "CONSTRUCT {\n"
+ " ?x ?p2 ?y"
+ "} WHERE {\n"
+ " ?x ?p1 ?y .\n"
+ " ?p1 rdfs:subPropertyOf ?p2 .\n"
+ "}";
ParsedGraphQuery query = (ParsedGraphQuery) PARSER.parseQuery(text, null);
SpinConstructRule rule = new SpinConstructRule(OWL.THING, RL_PRP_SPO1, query);
Multiset<StatementPattern> expectedAntecedents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("p1"), ac(RDFS.SUBPROPERTYOF), new Var("p2")),
new StatementPattern(new Var("x"), new Var("p1"), new Var("y"))));
Multiset<StatementPattern> expectedConsequents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("subject"), new Var("predicate"), new Var("object"))));
Assert.assertEquals(expectedAntecedents, HashMultiset.create(rule.getAntecedentPatterns()));
Assert.assertEquals(expectedConsequents, HashMultiset.create(rule.getConsequentPatterns()));
Assert.assertFalse(rule.hasAnonymousConsequent());
// Basic pattern matches
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("a"), new Var("b"), new Var("c"))));
// Narrower patterns match (constants in place of variables)
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(RDFS.SUBPROPERTYOF), c(OWL.THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), new Var("prop"), c(OWL.THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(FOAF.PERSON), c(RDFS.SUBCLASSOF), new Var("x"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), c(RDFS.SUBCLASSOF), c(FOAF.PERSON))));
}
开发者ID:apache,项目名称:incubator-rya,代码行数:27,代码来源:SpinConstructRuleTest.java
示例3: getQueryTask
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
public QueryTask getQueryTask(QueryDefinition query,
WriterConfig config, OutputStream out)
throws MalformedQueryException, RepositoryException {
QueryParser parser = new SPARQLParserFactory().getParser();
ParsedQuery parsedQuery = parser.parseQuery(query.getQuery(),
config.getBaseUri());
RepositoryConnection conn = cf.getConnection();
try {
if (parsedQuery instanceof ParsedTupleQuery) {
return new TupleQueryTask(conn, query, config, out);
} else if (parsedQuery instanceof ParsedBooleanQuery) {
return new AskQueryTask(conn, query, config, out);
} else if (parsedQuery instanceof ParsedGraphQuery) {
return new GraphQueryTask(conn, query, config, out);
}
} finally {
// conn.close();
}
throw new MalformedQueryException("Unknown query type: "
+ ParsedQuery.class.getName());
}
开发者ID:erfgoed-en-locatie,项目名称:artsholland-platform,代码行数:22,代码来源:QueryService.java
示例4: prepareQuery
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
@Override
public Query prepareQuery(QueryLanguage ql, String query, String baseURI)
throws RepositoryException, MalformedQueryException
{
validateQueryLanguage(ql);
ParsedQuery parsedQuery = QueryParserUtil.parseQuery(QueryLanguage.SPARQL, query, baseURI);
if (parsedQuery instanceof ParsedTupleQuery) {
return prepareTupleQuery(ql, query, baseURI);
}
else if (parsedQuery instanceof ParsedBooleanQuery) {
return prepareBooleanQuery(ql, query, baseURI);
}
else if (parsedQuery instanceof ParsedGraphQuery) {
return prepareGraphQuery(ql, query, baseURI);
}
throw new MalformedQueryException("Unrecognized query type:\n" + query); //$NON-NLS-1$
}
开发者ID:obidea,项目名称:semantika-endpoint,代码行数:19,代码来源:SemantikaRepositoryConnection.java
示例5: getExprQuery
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
/**
* Creates a new query based on a tuple expression and original query. The
* new query will have the same type null
* ({@link org.openrdf.query.TupleQuery},
* {@link org.openrdf.query.GraphQuery} or
* {@link org.openrdf.query.BooleanQuery}) as the given original query.
*
* @param orig the original query
* @param expr the expression used for the new query
* @return new query based on expression
*/
protected Query getExprQuery(ParsedQuery orig, TupleExpr expr) {
if (orig instanceof ParsedTupleQuery) {
return new SailTupleExprQuery(
new ParsedTupleQuery(expr), conn);
} else if (orig instanceof ParsedGraphQuery) {
return new SailGraphExprQuery(
new ParsedGraphQuery(expr), conn);
} else {
return new SailBooleanExprQuery(
new ParsedBooleanQuery(expr), conn);
}
}
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:24,代码来源:QueryRewriter.java
示例6: testEmptyWhere
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
@Test
public void testEmptyWhere() throws Exception {
String text = "CONSTRUCT {\n"
+ " ?this a <" + LIVING_THING.stringValue() + "> .\n"
+ "} WHERE { }";
ParsedGraphQuery query = (ParsedGraphQuery) PARSER.parseQuery(text, null);
SpinConstructRule rule = new SpinConstructRule(FOAF.PERSON, VF.createURI("urn:person-is-living"), query);
Multiset<StatementPattern> expectedAntecedents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("this"), c(RDF.TYPE), c(FOAF.PERSON))));
Multiset<StatementPattern> expectedConsequents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("subject"), new Var("predicate", RDF.TYPE), new Var("object", LIVING_THING))));
Assert.assertEquals(expectedAntecedents, HashMultiset.create(rule.getAntecedentPatterns()));
Assert.assertEquals(expectedConsequents, HashMultiset.create(rule.getConsequentPatterns()));
Assert.assertFalse(rule.hasAnonymousConsequent());
// Basic pattern matches
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(RDF.TYPE), c(LIVING_THING))));
// Broader patterns match (variables in place of constants)
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(RDF.TYPE), new Var("y"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), new Var("y"), c(LIVING_THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("a"), new Var("b"), new Var("c"))));
// Narrower patterns match (constants in place of variables)
Assert.assertTrue(rule.canConclude(new StatementPattern(c(RDF.TYPE), c(RDF.TYPE), c(LIVING_THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(FOAF.MBOX), c(RDF.TYPE), new Var("y"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(RDF.ALT), new Var("y"), c(LIVING_THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(RDF.BAG), new Var("b"), new Var("c"))));
// Incompatible patterns don't match (different constants)
Assert.assertFalse(rule.canConclude(new StatementPattern(new Var("x"), c(RDFS.SUBCLASSOF), new Var("y"))));
Assert.assertFalse(rule.canConclude(new StatementPattern(new Var("x"), new Var("y"), c(FOAF.PERSON))));
Assert.assertFalse(rule.canConclude(new StatementPattern(c(RDF.TYPE), c(RDF.TYPE), c(RDF.TYPE))));
}
开发者ID:apache,项目名称:incubator-rya,代码行数:31,代码来源:SpinConstructRuleTest.java
示例7: testThisUnbound
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
@Test
public void testThisUnbound() throws Exception {
String text = "CONSTRUCT {\n"
+ " ?ind a ?superclass .\n"
+ "} WHERE {\n"
+ " ?ind a ?subclass .\n"
+ " ?subclass rdfs:subClassOf ?superclass .\n"
+ "}";
ParsedGraphQuery query = (ParsedGraphQuery) PARSER.parseQuery(text, null);
SpinConstructRule rule = new SpinConstructRule(OWL.THING, RL_CAX_SCO, query);
Multiset<StatementPattern> expectedAntecedents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("subclass"), ac(RDFS.SUBCLASSOF), new Var("superclass")),
new StatementPattern(new Var("ind"), ac(RDF.TYPE), new Var("subclass"))));
Multiset<StatementPattern> expectedConsequents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("subject"), new Var("predicate", RDF.TYPE), new Var("object"))));
Assert.assertEquals(expectedAntecedents, HashMultiset.create(rule.getAntecedentPatterns()));
Assert.assertEquals(expectedConsequents, HashMultiset.create(rule.getConsequentPatterns()));
Assert.assertFalse(rule.hasAnonymousConsequent());
// Basic pattern matches
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(RDF.TYPE), new Var("y"))));
// Broader patterns match (variables in place of constants)
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("a"), new Var("b"), new Var("c"))));
// Narrower patterns match (constants in place of variables)
Assert.assertTrue(rule.canConclude(new StatementPattern(c(RDF.TYPE), c(RDF.TYPE), c(RDF.TYPE))));
// Incompatible patterns don't match (different constants)
Assert.assertFalse(rule.canConclude(new StatementPattern(new Var("x"), c(RDFS.SUBCLASSOF), new Var("y"))));
}
开发者ID:apache,项目名称:incubator-rya,代码行数:28,代码来源:SpinConstructRuleTest.java
示例8: testMultipleConsequents
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
@Test
public void testMultipleConsequents() throws Exception {
String text = "CONSTRUCT {\n"
// actual rule is "?this subClassOf ?this", but reflexive construct patterns produce
// bnodes due to an openrdf bug, resulting in incorrect matches
+ " ?this rdfs:subClassOf ?something .\n"
+ " ?this owl:equivalentClass ?something .\n"
+ " ?this rdfs:subClassOf owl:Thing .\n"
+ " owl:Nothing rdfs:subClassOf ?this .\n"
+ "} WHERE { }";
ParsedGraphQuery query = (ParsedGraphQuery) PARSER.parseQuery(text, null);
SpinConstructRule rule = new SpinConstructRule(OWL.CLASS, RL_SCM_CLS, query);
Multiset<StatementPattern> expectedAntecedents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("this"), c(RDF.TYPE), c(OWL.CLASS))));
Multiset<StatementPattern> expectedConsequents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("subject"), new Var("predicate", RDFS.SUBCLASSOF), new Var("object")),
new StatementPattern(new Var("subject"), new Var("predicate", OWL.EQUIVALENTCLASS), new Var("object")),
new StatementPattern(new Var("subject"), new Var("predicate", RDFS.SUBCLASSOF), new Var("object", OWL.THING)),
new StatementPattern(new Var("subject", OWL.NOTHING), new Var("predicate", RDFS.SUBCLASSOF), new Var("object"))));
Assert.assertEquals(expectedAntecedents, HashMultiset.create(rule.getAntecedentPatterns()));
Assert.assertEquals(expectedConsequents, HashMultiset.create(rule.getConsequentPatterns()));
// Basic pattern matches
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(RDFS.SUBCLASSOF), new Var("y"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(OWL.EQUIVALENTCLASS), new Var("y"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(RDFS.SUBCLASSOF), c(OWL.THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), c(RDFS.SUBCLASSOF), new Var("y"))));
// Broader patterns match (variables in place of constants)
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("a"), new Var("b"), new Var("c"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("a"), new Var("b"), c(OWL.THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), new Var("b"), new Var("c"))));
// Narrower patterns match (constants in place of variables)
Assert.assertTrue(rule.canConclude(new StatementPattern(c(FOAF.PERSON), c(RDFS.SUBCLASSOF), new Var("x"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(FOAF.PERSON), c(OWL.EQUIVALENTCLASS), c(FOAF.PERSON))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), c(RDFS.SUBCLASSOF), c(FOAF.PERSON))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), c(OWL.EQUIVALENTCLASS), c(FOAF.PERSON))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), c(OWL.EQUIVALENTCLASS), c(OWL.THING))));
// Incompatible patterns don't match (different constants)
Assert.assertFalse(rule.canConclude(new StatementPattern(new Var("x"), c(RDFS.SUBPROPERTYOF), c(OWL.THING))));
}
开发者ID:apache,项目名称:incubator-rya,代码行数:40,代码来源:SpinConstructRuleTest.java
示例9: testAnonymousConsequent
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
@Test
public void testAnonymousConsequent() throws Exception {
String text = "CONSTRUCT {\n"
+ " ?x ?p2 _:something"
+ "} WHERE {\n"
+ " ?x ?p1 ?y .\n"
+ " ?p1 rdfs:subPropertyOf ?p2 .\n"
+ "}";
ParsedGraphQuery query = (ParsedGraphQuery) PARSER.parseQuery(text, null);
SpinConstructRule rule = new SpinConstructRule(OWL.THING, RL_PRP_SPO1, query);
Multiset<StatementPattern> expectedAntecedents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("p1"), ac(RDFS.SUBPROPERTYOF), new Var("p2")),
new StatementPattern(new Var("x"), new Var("p1"), new Var("y"))));
Assert.assertEquals(expectedAntecedents, HashMultiset.create(rule.getAntecedentPatterns()));
// should have detected anonymous node
Assert.assertTrue(rule.hasAnonymousConsequent());
Var anonymousObject = new Var("object");
anonymousObject.setAnonymous(true);
Multiset<StatementPattern> expectedConsequents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("subject"), new Var("predicate"), anonymousObject)));
Assert.assertEquals(expectedConsequents, HashMultiset.create(rule.getConsequentPatterns()));
// Pattern matches should be unaffected by anonymous node status
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("a"), new Var("b"), new Var("c"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(RDFS.SUBPROPERTYOF), c(OWL.THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), new Var("prop"), c(OWL.THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(FOAF.PERSON), c(RDFS.SUBCLASSOF), new Var("x"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), c(RDFS.SUBCLASSOF), c(FOAF.PERSON))));
}
开发者ID:apache,项目名称:incubator-rya,代码行数:29,代码来源:SpinConstructRuleTest.java
示例10: getQueryType
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
public QueryType getQueryType(ParsedQuery parsedQuery) {
if (parsedQuery instanceof ParsedTupleQuery) {
return QueryType.SELECT;
} else if (parsedQuery instanceof ParsedBooleanQuery) {
return QueryType.ASK;
} else if (parsedQuery instanceof ParsedGraphQuery) {
return QueryType.CONSTRUCT;
} else {
return null;
}
}
开发者ID:erfgoed-en-locatie,项目名称:artsholland-platform,代码行数:12,代码来源:QueryService.java
示例11: SailGraphExprQuery
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
public SailGraphExprQuery(ParsedGraphQuery graphQuery, SailRepositoryConnection sailConnection) {
super(graphQuery, sailConnection);
}
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:4,代码来源:SailGraphExprQuery.java
示例12: getQuery
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
@Override
public ParsedGraphQuery getQuery() {
return graphQuery;
}
开发者ID:apache,项目名称:incubator-rya,代码行数:5,代码来源:SpinConstructRule.java
示例13: isGraphQuery
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
public boolean isGraphQuery() {
return query instanceof ParsedGraphQuery;
}
开发者ID:anno4j,项目名称:anno4j,代码行数:4,代码来源:SparqlQuery.java
示例14: getQuery
import org.openrdf.query.parser.ParsedGraphQuery; //导入依赖的package包/类
/**
* Get the query tree corresponding to this construct rule.
* @return The query algebra representation of this rule.
*/
public abstract ParsedGraphQuery getQuery();
开发者ID:apache,项目名称:incubator-rya,代码行数:6,代码来源:AbstractConstructRule.java
注:本文中的org.openrdf.query.parser.ParsedGraphQuery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论