本文整理汇总了Java中org.openrdf.model.vocabulary.RDF.TYPE属性的典型用法代码示例。如果您正苦于以下问题:Java RDF.TYPE属性的具体用法?Java RDF.TYPE怎么用?Java RDF.TYPE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.openrdf.model.vocabulary.RDF
的用法示例。
在下文中一共展示了RDF.TYPE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSomeValuesFromDisabled
@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);
}
示例2: testTypePattern
@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());
}
示例3: testOneOfDisabled
@Test
public void testOneOfDisabled() throws Exception {
// Configure a mock instance engine with an ontology:
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
when(inferenceEngine.isEnumeratedType(SUITS)).thenReturn(true);
when(inferenceEngine.getEnumeration(SUITS)).thenReturn(CARD_SUIT_ENUMERATION);
when(inferenceEngine.isEnumeratedType(RANKS)).thenReturn(true);
when(inferenceEngine.getEnumeration(RANKS)).thenReturn(CARD_RANK_ENUMERATION);
// Query for a Suits and rewrite using the visitor:
final Projection query = new Projection(
new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", SUITS)),
new ProjectionElemList(new ProjectionElem("s", "subject")));
final AccumuloRdfConfiguration disabledConf = conf.clone();
disabledConf.setInferOneOf(false);
query.visit(new OneOfVisitor(disabledConf, inferenceEngine));
// Expected structure: the original statement:
assertTrue(query.getArg() instanceof StatementPattern);
final StatementPattern actualCardSuitSp = (StatementPattern) query.getArg();
final StatementPattern expectedCardSuitSp = new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", SUITS));
assertEquals(expectedCardSuitSp, actualCardSuitSp);
}
示例4: testConcreteSP
@Test
public void testConcreteSP() {
Extension extension = new Extension(new SingletonSet(),
new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"),
new ExtensionElem(new ValueConstant(RDF.TYPE), "y"),
new ExtensionElem(new ValueConstant(OWL.CLASS), "z"));
Projection projection = new Projection(extension, new ProjectionElemList(
new ProjectionElem("x", "subject"),
new ProjectionElem("y", "predicate"),
new ProjectionElem("z", "object")));
ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
projection.visit(visitor);
Set<StatementPattern> expected = Sets.newHashSet(
new StatementPattern(s(FOAF.PERSON), p(RDF.TYPE), o(OWL.CLASS)));
Assert.assertEquals(expected, visitor.getConsequents());
}
示例5: queryIsPartEntityandExtra
@Test()
public void queryIsPartEntityandExtra() throws Exception {
// A pattern that has two different subjects.
final String query = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:SSN:111-11-1111> <urn:age> ?age . " +
"<urn:SSN:222-22-2222> <urn:age> ?age . " +
"<urn:SSN:222-22-2222> <urn:eye> ?eye . " +
"<urn:SSN:222-22-2222> <urn:name> ?name . " +
"}";
final String expectedQuery = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:SSN:111-11-1111> <urn:age> ?age . " +
"}";
final EntityQueryNode expected = new EntityQueryNode(PERSON_TYPE, getSPs(expectedQuery), entityStorage);
assertOptimizer(query, expected);
}
示例6: queryIsFullEntityWithExtra
@Test()
public void queryIsFullEntityWithExtra() throws Exception {
// A pattern that has two different subjects.
final String query = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:SSN:111-11-1111> <urn:age> ?age . " +
"<urn:SSN:111-11-1111> <urn:eye> ?eye . " +
"<urn:SSN:111-11-1111> <urn:name> ?name . " +
"<urn:SSN:222-22-2222> <urn:age> ?age . " +
"<urn:SSN:222-22-2222> <urn:eye> ?eye . " +
"<urn:SSN:222-22-2222> <urn:name> ?name . " +
"}";
final String expectedQuery = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:SSN:111-11-1111> <urn:age> ?age . " +
"<urn:SSN:111-11-1111> <urn:eye> ?eye . " +
"<urn:SSN:111-11-1111> <urn:name> ?name . " +
"}";
final EntityQueryNode expected = new EntityQueryNode(PERSON_TYPE, getSPs(expectedQuery), entityStorage);
assertOptimizer(query, expected);
}
示例7: queryIsFullEntityWithOptional
@Test()
public void queryIsFullEntityWithOptional() throws Exception {
// A pattern that has two different subjects.
final String query = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:SSN:111-11-1111> <urn:age> ?age . " +
"<urn:SSN:111-11-1111> <urn:eye> ?eye . " +
"<urn:SSN:111-11-1111> <urn:name> ?name . " +
" OPTIONAL{" +
" <urn:SSN:222-22-2222> <urn:age> ?age . " +
" <urn:SSN:222-22-2222> <urn:eye> ?eye . " +
" <urn:SSN:222-22-2222> <urn:name> ?name . " +
" } . " +
"}";
final String expectedQuery = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:SSN:111-11-1111> <urn:age> ?age . " +
"<urn:SSN:111-11-1111> <urn:eye> ?eye . " +
"<urn:SSN:111-11-1111> <urn:name> ?name . " +
"}";
final EntityQueryNode expected = new EntityQueryNode(PERSON_TYPE, getSPs(expectedQuery), entityStorage);
assertOptimizer(query, expected);
}
示例8: queryIsSplitEntityWithOptional
@Test()
public void queryIsSplitEntityWithOptional() throws Exception {
// A pattern that has two different subjects.
final String query = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:SSN:111-11-1111> <urn:age> ?age . " +
"<urn:SSN:111-11-1111> <urn:eye> ?eye . " +
" OPTIONAL{" +
" <urn:SSN:111-11-1111> <urn:name> ?name . " +
" } . " +
"}";
final String expectedQuery = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:SSN:111-11-1111> <urn:age> ?age . " +
"<urn:SSN:111-11-1111> <urn:eye> ?eye . " +
"}";
final EntityQueryNode expected = new EntityQueryNode(PERSON_TYPE, getSPs(expectedQuery), entityStorage);
assertOptimizer(query, expected);
}
示例9: queryEntityInOptional
@Test()
public void queryEntityInOptional() throws Exception {
// A pattern that has two different subjects.
final String query = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <urn:age> ?age . " +
"<urn:SSN:111-11-1111> <urn:eye> ?eye . " +
" OPTIONAL{" +
" <urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
" <urn:SSN:111-11-1111> <urn:name> ?name . " +
" } . " +
"}";
final String expectedQuery = "SELECT * WHERE { " +
"<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:SSN:111-11-1111> <urn:name> ?name . " +
"}";
final EntityQueryNode expected = new EntityQueryNode(PERSON_TYPE, getSPs(expectedQuery), entityStorage);
assertOptimizer(query, expected);
}
示例10: partialQuery_Test
@Test
public void partialQuery_Test() throws Exception {
final Sail sail = RyaSailFactory.getInstance(conf);
SailRepositoryConnection conn = new SailRepository(sail).getConnection();
conn.begin();
try(MongoEntityIndexer indexer = new MongoEntityIndexer()) {
indexer.setConf(conf);
indexer.init();
setupTypes(indexer);
addStatements(conn);
conn.commit();
final String query = "SELECT * WHERE { " +
"<urn:george> <" + RDF.TYPE + "> <urn:person> ."+
"<urn:george> <urn:name> ?name . " +
"<urn:george> <urn:eye> ?eye . " +
"}";
final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
final Set<BindingSet> results = new HashSet<>();
while(rez.hasNext()) {
final BindingSet bs = rez.next();
System.out.println(bs);
results.add(bs);
}
final ValueFactory vf = ValueFactoryImpl.getInstance();
final MapBindingSet expected = new MapBindingSet();
//expected.addBinding("name", vf.createURI("http://www.w3.org/2001/SMLSchema#string", "George"));
expected.addBinding("name", vf.createLiteral("George"));
expected.addBinding("eye", vf.createLiteral("blue"));
assertEquals(1, results.size());
assertEquals(expected, results.iterator().next());
} finally {
conn.close();
}
}
示例11: meetSP
/**
* 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));
}
}
}
示例12: meetSP
/**
* 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));
}
}
}
示例13: testMissingVariables
@Test
public void testMissingVariables() {
Extension extension = new Extension(new SingletonSet(),
new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"),
new ExtensionElem(new ValueConstant(RDF.TYPE), "y"));
Projection projection = new Projection(extension, new ProjectionElemList(
new ProjectionElem("x", "s"),
new ProjectionElem("y", "predicate"),
new ProjectionElem("z", "object")));
ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
projection.visit(visitor);
Set<StatementPattern> expected = Sets.newHashSet(
new StatementPattern(s(null), p(RDF.TYPE), o(null)));
Assert.assertEquals(expected, visitor.getConsequents());
}
示例14: testJoins
@Test
public void testJoins() {
// match { ?s ex:likes ?o. ?o a ex:Person } : 1 result
StatementPattern sp1 = new StatementPattern(new Var("o"), new Var("p1", RDF.TYPE), new Var("type", PERSON));
StatementPattern sp2 = new StatementPattern(new Var("s"), new Var("p2", LIKES), new Var("o"));
Join join = new Join(sp1, sp2);
bindings = QueryExecutor.eval(evalStrategy, join);
Assert.assertNotNull(bindings);
Assert.assertEquals(bindings.size(), 1);
Assert.assertTrue(ALICE.equals(bindings.get(0).getValue("s")));
Assert.assertTrue(BOB.equals(bindings.get(0).getValue("o")));
// match { ?s a ex:Person; ex:likes ?o. ?o a ex:Person } : 1 result
StatementPattern sp3 = new StatementPattern(new Var("s"), new Var("p1", RDF.TYPE), new Var("type1", PERSON));
StatementPattern sp4 = new StatementPattern(new Var("o"), new Var("p2", RDF.TYPE), new Var("type2", PERSON));
StatementPattern sp5 = new StatementPattern(new Var("s"), new Var("p3", LIKES), new Var("o"));
Join join1 = new Join(sp4, sp5);
Join join2 = new Join(sp3, join1);
bindings = QueryExecutor.eval(evalStrategy, join2);
Assert.assertNotNull(bindings);
Assert.assertEquals(bindings.size(), 1);
Assert.assertTrue(ALICE.equals(bindings.get(0).getValue("s")));
Assert.assertTrue(BOB.equals(bindings.get(0).getValue("o")));
}
示例15: testMultiProjection
@Test
public void testMultiProjection() {
Extension extension = new Extension(new SingletonSet(),
new ExtensionElem(new ValueConstant(RDF.TYPE), "rdftype"),
new ExtensionElem(new ValueConstant(OWL.OBJECTPROPERTY), "owlprop"),
new ExtensionElem(new ValueConstant(OWL.EQUIVALENTCLASS), "owleqcls"),
new ExtensionElem(new ValueConstant(OWL.CLASS), "owlclass"));
MultiProjection projection = new MultiProjection(extension, Arrays.asList(
new ProjectionElemList(
new ProjectionElem("cls", "subject"),
new ProjectionElem("rdftype", "predicate"),
new ProjectionElem("owlclass", "object")),
new ProjectionElemList(
new ProjectionElem("prop", "subject"),
new ProjectionElem("rdftype", "predicate"),
new ProjectionElem("owlprop", "object")),
new ProjectionElemList(
new ProjectionElem("owleqcls", "predicate"),
new ProjectionElem("cls", "object"))));
ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
projection.visit(visitor);
Set<StatementPattern> expected = Sets.newHashSet(
new StatementPattern(s(null), p(RDF.TYPE), o(OWL.CLASS)),
new StatementPattern(s(null), p(RDF.TYPE), o(OWL.OBJECTPROPERTY)),
new StatementPattern(s(null), p(OWL.EQUIVALENTCLASS), o(null)));
Assert.assertEquals(expected, visitor.getConsequents());
}