[ https://issues.apache.org/jira/browse/RYA-292?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16128084#comment-16128084 ]
ASF GitHub Bot commented on RYA-292: ------------------------------------ Github user jessehatfield commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/206#discussion_r133311778 --- Diff: sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java --- @@ -220,163 +229,163 @@ public void refreshGraph() throws InferenceEngineException { } } inverseOfMap = invProp; - - ValueFactory vf = ValueFactoryImpl.getInstance(); - iter = RyaDAOHelper.query(ryaDAO, null, - vf.createURI("http://www.w3.org/2002/07/owl#propertyChainAxiom"), - null, conf); - Map<URI,URI> propertyChainPropertiesToBNodes = new HashMap<URI, URI>(); - propertyChainPropertyToChain = new HashMap<URI, List<URI>>(); + + final ValueFactory vf = ValueFactoryImpl.getInstance(); + iter = RyaDAOHelper.query(ryaDAO, null, + vf.createURI("http://www.w3.org/2002/07/owl#propertyChainAxiom"), + null, conf); + final Map<URI,URI> propertyChainPropertiesToBNodes = new HashMap<>(); + propertyChainPropertyToChain = new HashMap<>(); try { - while (iter.hasNext()){ - Statement st = iter.next(); - propertyChainPropertiesToBNodes.put((URI)st.getSubject(), (URI)st.getObject()); - } + while (iter.hasNext()){ + final Statement st = iter.next(); + propertyChainPropertiesToBNodes.put((URI)st.getSubject(), (URI)st.getObject()); + } } finally { if (iter != null) { iter.close(); } } // now for each property chain bNode, get the indexed list of properties associated with that chain - for (URI propertyChainProperty : propertyChainPropertiesToBNodes.keySet()){ - URI bNode = propertyChainPropertiesToBNodes.get(propertyChainProperty); - // query for the list of indexed properties - iter = RyaDAOHelper.query(ryaDAO, bNode, vf.createURI("http://www.w3.org/2000/10/swap/list#index"), - null, conf); - TreeMap<Integer, URI> orderedProperties = new TreeMap<Integer, URI>(); - // TODO refactor this. Wish I could execute sparql - try { - while (iter.hasNext()){ - Statement st = iter.next(); - String indexedElement = st.getObject().stringValue(); - System.out.println(indexedElement); - CloseableIteration<Statement, QueryEvaluationException> iter2 = RyaDAOHelper.query(ryaDAO, vf.createURI(st.getObject().stringValue()), RDF.FIRST, - null, conf); - String integerValue = ""; - Value anonPropNode = null; - Value propURI = null; - if (iter2 != null){ - while (iter2.hasNext()){ - Statement iter2Statement = iter2.next(); - integerValue = iter2Statement.getObject().stringValue(); - break; - } - iter2.close(); - } - iter2 = RyaDAOHelper.query(ryaDAO, vf.createURI(st.getObject().stringValue()), RDF.REST, - null, conf); - if (iter2 != null){ - while (iter2.hasNext()){ - Statement iter2Statement = iter2.next(); - anonPropNode = iter2Statement.getObject(); - break; - } - iter2.close(); - if (anonPropNode != null){ - iter2 = RyaDAOHelper.query(ryaDAO, vf.createURI(anonPropNode.stringValue()), RDF.FIRST, - null, conf); - while (iter2.hasNext()){ - Statement iter2Statement = iter2.next(); - propURI = iter2Statement.getObject(); - break; - } - iter2.close(); - } - } - if (!integerValue.isEmpty() && propURI!=null) { - try { - int indexValue = Integer.parseInt(integerValue); - URI chainPropURI = vf.createURI(propURI.stringValue()); - orderedProperties.put(indexValue, chainPropURI); - } - catch (Exception ex){ - // TODO log an error here - - } - } - } - } finally{ - if (iter != null){ - iter.close(); - } - } - List<URI> properties = new ArrayList<URI>(); - for (Map.Entry<Integer, URI> entry : orderedProperties.entrySet()){ - properties.add(entry.getValue()); - } - propertyChainPropertyToChain.put(propertyChainProperty, properties); + for (final URI propertyChainProperty : propertyChainPropertiesToBNodes.keySet()){ + final URI bNode = propertyChainPropertiesToBNodes.get(propertyChainProperty); + // query for the list of indexed properties + iter = RyaDAOHelper.query(ryaDAO, bNode, vf.createURI("http://www.w3.org/2000/10/swap/list#index"), + null, conf); + final TreeMap<Integer, URI> orderedProperties = new TreeMap<Integer, URI>(); + // TODO refactor this. Wish I could execute sparql + try { + while (iter.hasNext()){ + final Statement st = iter.next(); + final String indexedElement = st.getObject().stringValue(); + log.info(indexedElement); + CloseableIteration<Statement, QueryEvaluationException> iter2 = RyaDAOHelper.query(ryaDAO, vf.createURI(st.getObject().stringValue()), RDF.FIRST, + null, conf); + String integerValue = ""; + Value anonPropNode = null; + Value propURI = null; + if (iter2 != null){ + while (iter2.hasNext()){ + final Statement iter2Statement = iter2.next(); + integerValue = iter2Statement.getObject().stringValue(); + break; + } + iter2.close(); + } + iter2 = RyaDAOHelper.query(ryaDAO, vf.createURI(st.getObject().stringValue()), RDF.REST, + null, conf); + if (iter2 != null){ + while (iter2.hasNext()){ + final Statement iter2Statement = iter2.next(); + anonPropNode = iter2Statement.getObject(); + break; + } + iter2.close(); + if (anonPropNode != null){ + iter2 = RyaDAOHelper.query(ryaDAO, vf.createURI(anonPropNode.stringValue()), RDF.FIRST, + null, conf); + while (iter2.hasNext()){ + final Statement iter2Statement = iter2.next(); + propURI = iter2Statement.getObject(); + break; + } + iter2.close(); + } + } + if (!integerValue.isEmpty() && propURI!=null) { + try { + final int indexValue = Integer.parseInt(integerValue); + final URI chainPropURI = vf.createURI(propURI.stringValue()); + orderedProperties.put(indexValue, chainPropURI); + } + catch (final Exception ex){ + // TODO log an error here + + } + } + } + } finally{ + if (iter != null){ + iter.close(); + } + } + final List<URI> properties = new ArrayList<URI>(); + for (final Map.Entry<Integer, URI> entry : orderedProperties.entrySet()){ + properties.add(entry.getValue()); + } + propertyChainPropertyToChain.put(propertyChainProperty, properties); } - + // could also be represented as a list of properties (some of which may be blank nodes) - for (URI propertyChainProperty : propertyChainPropertiesToBNodes.keySet()){ - List<URI> existingChain = propertyChainPropertyToChain.get(propertyChainProperty); - // if we didn't get a chain, try to get it through following the collection - if ((existingChain == null) || existingChain.isEmpty()) { - - CloseableIteration<Statement, QueryEvaluationException> iter2 = RyaDAOHelper.query(ryaDAO, propertyChainPropertiesToBNodes.get(propertyChainProperty), RDF.FIRST, - null, conf); - List<URI> properties = new ArrayList<URI>(); - URI previousBNode = propertyChainPropertiesToBNodes.get(propertyChainProperty); - if (iter2.hasNext()) { - Statement iter2Statement = iter2.next(); - Value currentPropValue = iter2Statement.getObject(); - while ((currentPropValue != null) && (!currentPropValue.stringValue().equalsIgnoreCase(RDF.NIL.stringValue()))){ - if (currentPropValue instanceof URI){ - iter2 = RyaDAOHelper.query(ryaDAO, vf.createURI(currentPropValue.stringValue()), RDF.FIRST, - null, conf); - if (iter2.hasNext()){ - iter2Statement = iter2.next(); - if (iter2Statement.getObject() instanceof URI){ - properties.add((URI)iter2Statement.getObject()); - } - } - // otherwise see if there is an inverse declaration - else { - iter2 = RyaDAOHelper.query(ryaDAO, vf.createURI(currentPropValue.stringValue()), OWL.INVERSEOF, - null, conf); - if (iter2.hasNext()){ - iter2Statement = iter2.next(); - if (iter2Statement.getObject() instanceof URI){ - properties.add(new InverseURI((URI)iter2Statement.getObject())); - } - } - } - // get the next prop pointer - iter2 = RyaDAOHelper.query(ryaDAO, previousBNode, RDF.REST, - null, conf); - if (iter2.hasNext()){ - iter2Statement = iter2.next(); - previousBNode = (URI)currentPropValue; - currentPropValue = iter2Statement.getObject(); - } - else { - currentPropValue = null; - } - } - else { - currentPropValue = null; - } - - } - propertyChainPropertyToChain.put(propertyChainProperty, properties); - } - } + for (final URI propertyChainProperty : propertyChainPropertiesToBNodes.keySet()){ + final List<URI> existingChain = propertyChainPropertyToChain.get(propertyChainProperty); + // if we didn't get a chain, try to get it through following the collection + if ((existingChain == null) || existingChain.isEmpty()) { + + CloseableIteration<Statement, QueryEvaluationException> iter2 = RyaDAOHelper.query(ryaDAO, propertyChainPropertiesToBNodes.get(propertyChainProperty), RDF.FIRST, + null, conf); + final List<URI> properties = new ArrayList<URI>(); + URI previousBNode = propertyChainPropertiesToBNodes.get(propertyChainProperty); + if (iter2.hasNext()) { --- End diff -- This block is still slightly offset > Implement owl:intersectionOf inference > -------------------------------------- > > Key: RYA-292 > URL: https://issues.apache.org/jira/browse/RYA-292 > Project: Rya > Issue Type: Sub-task > Components: sail > Reporter: Jesse Hatfield > Assignee: Eric White > > An *{{owl:intersectionOf}}* expression defines the set of resources who > belong to all of a particular set of classes. > A basic implementation, if the ontology states that {{:Mother}} is the > intersection of {{:Parent}} and {{:Woman}}, should cause the inference engine > to: > 1. Rewrite query patterns {{?x rdf:type :Mother}} (the intersection type) to > check for resources that have both types {{:Parent}} and {{:Woman}} (as well > as check for resources that are explicitly stated to be {{:Mother}} s) > 2. Rewrite query patterns {{?y rdf:type :Parent}} (one of the intersecting > sets) to check for resources that are stated to be either {{:Mother}} or > {{:Parent}} , since belonging to the intersection type implies membership in > the component types. (Equivalent logic applies to {{Woman}} ) -- This message was sent by Atlassian JIRA (v6.4.14#64029)