Github user jessehatfield commented on a diff in the pull request:
https://github.com/apache/incubator-rya/pull/215#discussion_r135073684
--- Diff: extras/indexingExample/src/main/java/MongoRyaDirectExample.java
---
@@ -572,6 +573,108 @@ public static void testAllValuesFromInference(final
SailRepositoryConnection con
Validate.isTrue(resultHandler.getCount() == 2);
}
+ public static void testOneOfInference(final SailRepositoryConnection
conn, final Sail sail) throws MalformedQueryException, RepositoryException,
UpdateExecutionException, QueryEvaluationException,
TupleQueryResultHandlerException, InferenceEngineException {
+ log.info("Adding Data");
+ final String instances = "INSERT DATA"
+ + "{ GRAPH <http://updated/test> {\n"
+ + " <urn:FlopCard1> a <urn:Card> . \n"
+ + " <urn:FlopCard1> <urn:HasRank> <urn:Ace> . \n"
+ + " <urn:FlopCard1> <urn:HasSuit> <urn:Diamonds> . \n"
+ + " <urn:FlopCard2> a <urn:Card> . \n"
+ + " <urn:FlopCard2> <urn:HasRank> <urn:Ace> . \n"
+ + " <urn:FlopCard2> <urn:HasSuit> <urn:Hearts> . \n"
+ + " <urn:FlopCard3> a <urn:Card> . \n"
+ + " <urn:FlopCard3> <urn:HasRank> <urn:King> . \n"
+ + " <urn:FlopCard3> <urn:HasSuit> <urn:Spades> . \n"
+ + " <urn:TurnCard> a <urn:Card> . \n"
+ + " <urn:TurnCard> <urn:HasRank> <urn:10> . \n"
+ + " <urn:TurnCard> <urn:HasSuit> <urn:Clubs> . \n"
+ + " <urn:RiverCard> a <urn:Card> . \n"
+ + " <urn:RiverCard> <urn:HasRank> <urn:Queen> . \n"
+ + " <urn:RiverCard> <urn:HasSuit> <urn:Hearts> . \n"
+ + "}}";
+ Update update = conn.prepareUpdate(QueryLanguage.SPARQL,
instances);
+ update.execute();
+ final String explicitQuery = "select distinct ?card { GRAPH
<http://updated/test> {\n"
+ + " ?card a <urn:Card> . \n"
+ + " VALUES ?suit { <urn:Clubs> <urn:Diamonds>
<urn:Hearts> <urn:Spades> } . \n"
+ + " ?card <urn:HasSuit> ?suit . \n"
+ + "}}";
+ log.info("Running Explicit Query");
+ CountingResultHandler resultHandler = new CountingResultHandler();
+ TupleQuery tupleQuery =
conn.prepareTupleQuery(QueryLanguage.SPARQL, explicitQuery);
+ tupleQuery.evaluate(resultHandler);
+ log.info("Result count : " + resultHandler.getCount());
+ Validate.isTrue(resultHandler.getCount() == 5);
+ log.info("Adding owl:oneOf Schema");
+ // ONTOLOGY - :Suits oneOf (:Clubs, :Diamonds, :Hearts, :Spades)
+ // ONTOLOGY - :Ranks oneOf (:Ace, :1, :2, :3, :4, :5, :6, :7, :8,
:9, :10, :Jack, :Queen, :King)
+ final String ontology = "INSERT DATA { GRAPH <http://updated/test>
{\n"
+ + " <urn:Suits> owl:oneOf _:bnodeS1 . \n"
+ + " _:bnodeS1 rdf:first <urn:Clubs> . \n"
+ + " _:bnodeS1 rdf:rest _:bnodeS2 . \n"
+ + " _:bnodeS2 rdf:first <urn:Diamonds> . \n"
+ + " _:bnodeS2 rdf:rest _:bnodeS3 . \n"
+ + " _:bnodeS3 rdf:first <urn:Hearts> . \n"
+ + " _:bnodeS3 rdf:rest _:bnodeS4 . \n"
+ + " _:bnodeS4 rdf:first <urn:Spades> . \n"
+ + " _:bnodeS4 rdf:rest rdf:nil . \n"
+ + " <urn:Ranks> owl:oneOf _:bnodeR1 . \n"
+ + " _:bnodeR1 rdf:first <urn:Ace> . \n"
+ + " _:bnodeR1 rdf:rest _:bnodeR2 . \n"
+ + " _:bnodeR2 rdf:first <urn:2> . \n"
+ + " _:bnodeR2 rdf:rest _:bnodeR3 . \n"
+ + " _:bnodeR3 rdf:first <urn:3> . \n"
+ + " _:bnodeR3 rdf:rest _:bnodeR4 . \n"
+ + " _:bnodeR4 rdf:first <urn:4> . \n"
+ + " _:bnodeR4 rdf:rest _:bnodeR5 . \n"
+ + " _:bnodeR5 rdf:first <urn:5> . \n"
+ + " _:bnodeR5 rdf:rest _:bnodeR6 . \n"
+ + " _:bnodeR6 rdf:first <urn:6> . \n"
+ + " _:bnodeR6 rdf:rest _:bnodeR7 . \n"
+ + " _:bnodeR7 rdf:first <urn:7> . \n"
+ + " _:bnodeR7 rdf:rest _:bnodeR8 . \n"
+ + " _:bnodeR8 rdf:first <urn:8> . \n"
+ + " _:bnodeR8 rdf:rest _:bnodeR9 . \n"
+ + " _:bnodeR9 rdf:first <urn:9> . \n"
+ + " _:bnodeR9 rdf:rest _:bnodeR10 . \n"
+ + " _:bnodeR10 rdf:first <urn:10> . \n"
+ + " _:bnodeR10 rdf:rest _:bnodeR11 . \n"
+ + " _:bnodeR11 rdf:first <urn:Jack> . \n"
+ + " _:bnodeR11 rdf:rest _:bnodeR12 . \n"
+ + " _:bnodeR12 rdf:first <urn:Queen> . \n"
+ + " _:bnodeR12 rdf:rest _:bnodeR13 . \n"
+ + " _:bnodeR13 rdf:first <urn:King> . \n"
+ + " _:bnodeR13 rdf:rest rdf:nil . \n"
+ + " <urn:Card> rdfs:equivalentClass [\n"
+ + " owl:onProperty <urn:HasRank> ; owl:range
<urn:Ranks> ;\n"
+ + " owl:onProperty <urn:HasSuit> ; owl:range
<urn:Suits> ;\n"
+ + " ] . \n"
--- End diff --
Not sure what this :Card equivalentClass statement is meant to express, but
I don't think it's quite right. Looks like it doesn't affect the queries. But
if we want to keep it for example purposes:
1. onProperty doesn't interact with (rdfs:)range; range applies directly to
the property regardless of what type of object has it. If you want to tie it to
Card specifically, you could use owl:allValuesFrom, owl:someValuesFrom, or a
cardinality restriction (owl:cardinality, owl:qualifiedCardinality,
owl:minQualifiedCardinality, ...), depending on what you want to express. Or if
you want to make a more general statement you could say "<urn:hasRank>
rdfs:range <urn:Ranks>" (if anything has a rank, then the rank is a
urn:hasRank).
2. Two property restrictions in the same class won't really work like that,
since there's no way to make sure the right onProperty triple goes with the
right someValuesFrom/allValuesFrom/cardinality/etc triple.
So one alternative formulation might be:
```
<urn:Card> owl:intersectionOf (
[ owl:onProperty <urn:HasRank> ; owl:someValuesFrom <urn:Ranks> ]
[ owl:onProperty <urn:HasSuit> ; owl:someValuesFrom <urn:Suits> ]
)
```
That says a Card is anything with at least one Suits for hasSuit and at
least one Ranks for hasRank. (I don't think Rya will be able to apply that
inference right now since it relies on combining intersection and
someValuesFrom logic.)
Replace someValuesFrom with allValuesFrom and it says: Anything a Card has
for a hasSuit is a Suits, and anything a Card has for hasRank is a Ranks.
Or replace with something involving cardinality, or some combination of
expressions, or just the range expressions without restricting to Card.
But the simplest thing would be to remove it, and it looks like that would
be safe.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---