diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java index 18e96508b..ec5af9468 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/inference/InferenceEngine.java @@ -193,6 +193,7 @@ public void refreshGraph() throws InferenceEngineException { iter.close(); } } + subClassOfGraph = graph; //TODO: Should this be synchronized? graph = TinkerGraph.open(); @@ -267,7 +268,7 @@ public void refreshGraph() throws InferenceEngineException { // 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 orderedProperties = new TreeMap(); + final TreeMap orderedProperties = new TreeMap<>(); // TODO refactor this. Wish I could execute sparql try { while (iter.hasNext()){ @@ -324,7 +325,7 @@ public void refreshGraph() throws InferenceEngineException { iter.close(); } } - final List properties = new ArrayList(); + final List properties = new ArrayList<>(); for (final Map.Entry entry : orderedProperties.entrySet()){ properties.add(entry.getValue()); } @@ -339,7 +340,7 @@ public void refreshGraph() throws InferenceEngineException { CloseableIteration iter2 = RyaDAOHelper.query(ryaDAO, propertyChainPropertiesToBNodes.get(propertyChainProperty), RDF.FIRST, null, conf); - final List properties = new ArrayList(); + final List properties = new ArrayList<>(); URI previousBNode = propertyChainPropertiesToBNodes.get(propertyChainProperty); if (iter2.hasNext()) { Statement iter2Statement = iter2.next(); @@ -753,20 +754,12 @@ public void handleStatement(final Statement statement) throws RDFHandlerExceptio otherKeys.remove(type); for (final Resource otherKey : otherKeys) { if (intersectionsProp.get(otherKey).contains(intersection)) { - for (final URI superClass : superClasses) { - addSubClassOf(otherKey, superClass); - } + addSubClassOf(otherKey, type); + addSubClassOf(type, otherKey); } } } } - for (final Entry>> entry : intersectionsProp.entrySet()) { - final Resource type = entry.getKey(); - final List> intersectionList = entry.getValue(); - for (final Set intersection : intersectionList) { - addIntersection(intersection, type); - } - } } /** @@ -961,7 +954,7 @@ public Set findTransitiveProperty(final Resource subj, final URI prop * TODO: This chaining can be slow at query execution. the other option is to perform this in the query itself, but that will be constrained to how many levels we decide to go */ public Set findSameAs(final Resource value, final Resource... contxts) throws InferenceEngineException{ - final Set sameAs = new HashSet(); + final Set sameAs = new HashSet<>(); sameAs.add(value); findSameAsChaining(value, sameAs, contxts); return sameAs; diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java index 2bacbf461..10edf4925 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java @@ -406,14 +406,17 @@ public void testIntersectionOf() throws Exception { Assert.assertEquals(intersectionsImplyingFather, inferenceEngine.getIntersectionsImplying(father)); // Check that Mother is a subclassOf Parent and Woman and - // ImmediateFamilyMember and Relative + // ImmediateFamilyMember and Relative. Also, Mother is a subclassOf + // Mother and Mom through inferring equivalentClass. final Set motherSuperClassUris = inferenceEngine.getSuperClasses(mother); Assert.assertNotNull(motherSuperClassUris); - Assert.assertEquals(4, motherSuperClassUris.size()); + Assert.assertEquals(6, motherSuperClassUris.size()); Assert.assertTrue(motherSuperClassUris.contains(parent)); Assert.assertTrue(motherSuperClassUris.contains(woman)); Assert.assertTrue(motherSuperClassUris.contains(immediateFamilyMember)); Assert.assertTrue(motherSuperClassUris.contains(relative)); + Assert.assertTrue(motherSuperClassUris.contains(mother)); + Assert.assertTrue(motherSuperClassUris.contains(mom)); // Check that Father is a subclassOf Parent and Man final Set fatherSuperClassUris = inferenceEngine.getSuperClasses(father); Assert.assertNotNull(fatherSuperClassUris); @@ -423,13 +426,16 @@ public void testIntersectionOf() throws Exception { // Check that Mom is a subclassOf Parent and Woman and // ImmediateFamilyMember and Relative. The last 2 should be inferred - // from having the same intersection as Mother. + // from having the same intersection as Mother. Also, Mom is a + // subclassOf Mother and Mom through inferring equivalentClass. final Set momSuperClassUris = inferenceEngine.getSuperClasses(mom); Assert.assertNotNull(momSuperClassUris); - Assert.assertEquals(4, momSuperClassUris.size()); + Assert.assertEquals(6, momSuperClassUris.size()); Assert.assertTrue(momSuperClassUris.contains(parent)); Assert.assertTrue(momSuperClassUris.contains(woman)); Assert.assertTrue(momSuperClassUris.contains(immediateFamilyMember)); Assert.assertTrue(momSuperClassUris.contains(relative)); + Assert.assertTrue(momSuperClassUris.contains(mother)); + Assert.assertTrue(momSuperClassUris.contains(mom)); } }