[ https://issues.apache.org/jira/browse/RYA-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16120060#comment-16120060 ]
ASF GitHub Bot commented on RYA-293: ------------------------------------ Github user meiercaleb commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/180#discussion_r132213500 --- Diff: sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java --- @@ -142,6 +143,53 @@ public void refreshGraph() throws InferenceEngineException { } } + // Add unions to the subclass graph: if c owl:unionOf LIST(c1, c2, ... cn), then any + // instances of c1, c2, ... or cn are also instances of c, meaning c is a superclass + // of all the rest. + // (In principle, an instance of c is likewise implied to be at least one of the other + // types, but this fact is ignored for now to avoid nondeterministic reasoning.) + iter = RyaDAOHelper.query(ryaDAO, null, OWL.UNIONOF, null, conf); + try { + while (iter.hasNext()) { + Statement st = iter.next(); + Value unionType = st.getSubject(); + // Traverse the list of types constituting the union + Value current = st.getObject(); + while (current instanceof Resource && !RDF.NIL.equals(current)) { + Resource listNode = (Resource) current; + CloseableIteration<Statement, QueryEvaluationException> listIter = RyaDAOHelper.query(ryaDAO, + listNode, RDF.FIRST, null, conf); + try { + if (listIter.hasNext()) { + Statement firstStatement = listIter.next(); + if (firstStatement.getObject() instanceof Resource) { + Resource subclass = (Resource) firstStatement.getObject(); + Statement subclassStatement = vf.createStatement(subclass, RDFS.SUBCLASSOF, unionType); + addStatementEdge(graph, RDFS.SUBCLASSOF.stringValue(), subclassStatement); + } + } + } finally { + listIter.close(); + } + listIter = RyaDAOHelper.query(ryaDAO, listNode, RDF.REST, null, conf); + try { + if (listIter.hasNext()) { + current = listIter.next().getObject(); --- End diff -- Trying to follow the general logic here: Each list has an RDF.FIRST and RDF.RESET property, where FIRST is a resource and REST is of type list. So if the list has more than one element, current is set to the list obtained by the RDF.REST query and we go through the loop again. Is this how all of the SUBCLASSOF statements are created for the union? > Implement owl:unionOf inference > ------------------------------- > > Key: RYA-293 > URL: https://issues.apache.org/jira/browse/RYA-293 > Project: Rya > Issue Type: Sub-task > Components: sail > Reporter: Jesse Hatfield > Assignee: Jesse Hatfield > > An *{{owl:unionOf}}* expression defines one type to be equivalent to the > union of another set of types. If the ontology states that {{:Parent}} is the > union of {{:Mother}} and {{:Father}}, then the inference engine should > rewrite statement patterns of the form {{?x rdf:type :Parent}} to check for > resources that are stated to be any of the types {{:Mother}}, {{:Father}}, or > {{:Parent}}. -- This message was sent by Atlassian JIRA (v6.4.14#64029)