Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fix bug with cache miss lookup for 'object' part of statement #39

Merged
merged 2 commits into from Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,6 @@ dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
*.iml
.classpath
.project
.settings/
2 changes: 1 addition & 1 deletion src/main/java/semantics/DirectStatementLoader.java
Expand Up @@ -262,7 +262,7 @@ public Node call() { //throws AnyException
final Node toNode = nodeCache.get(st.getObject().stringValue(), new Callable<Node>() {
@Override
public Node call() { //throws AnyException
return graphdb.findNode(RESOURCE, "uri", st.getSubject().stringValue());
return graphdb.findNode(RESOURCE, "uri", st.getObject().stringValue());
}
});

Expand Down
36 changes: 35 additions & 1 deletion src/test/java/semantics/RDFImportTest.java
Expand Up @@ -9,6 +9,8 @@
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.TestGraphDatabaseFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -103,7 +105,7 @@ public void testImportJSONLDShortening() throws Exception {
db.execute("MATCH (n) WHERE exists(n.ns0_modified) RETURN count(n) AS count")
.next().get("count"));

HashMap<String, String> expectedNamespaceDefs = new HashMap<String, String>();
HashMap<String, String> expectedNamespaceDefs = new HashMap<>();
expectedNamespaceDefs.put("baseName", "http://xmlns.com/foaf/0.1/");
expectedNamespaceDefs.put("prefix", "ns0");
assertEquals(expectedNamespaceDefs,
Expand Down Expand Up @@ -322,6 +324,30 @@ public void testImportTurtle() throws Exception {
assertEquals("http://www.opentox.org/example/1.1#phenol", compounds.next().get("compound"));

}

/**
* Can we populate the cache correctly when we have a miss?
*/
@Test
public void testImportTurtle02() throws Exception {
GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
((GraphDatabaseAPI)db).getDependencyResolver().resolveDependency(Procedures.class).registerProcedure(RDFImport.class);

createIndices(db);
db.execute("CREATE (rdf:NamespacePrefixDefinition {" +
" `http://www.example.com/ontology/1.0.0#`: 'ex'," +
" `http://www.w3.org/1999/02/22-rdf-syntax-ns#`: 'rdfs'})");
Result importResults = db.execute(String.format(
"CALL semantics.importRDF('%s','Turtle',{nodeCacheSize: 1})", file("myrdf/testImportTurtle02.ttl")));
assertEquals(5L, importResults.next().get("triplesLoaded"));

Result result = db.execute(
"MATCH (:ex_DISTANCEVALUE)-[:ex_units]->(mu) " +
"RETURN mu.uri AS unitsUri, mu.ex_name as unitsName");
Map<String, Object> first = result.next();
assertEquals("http://www.example.com/ontology/1.0.0/common#MEASUREMENTUNIT-T1510615421640", first.get("unitsUri"));
assertEquals("metres", first.get("unitsName"));
}

@Test
public void testPreviewFromSnippet() throws Exception {
Expand Down Expand Up @@ -397,4 +423,12 @@ private void createIndices(GraphDatabaseService db) {
db.execute("CREATE INDEX ON :Resource(uri)");
}

private static URI file(String path) {
try {
return RDFImportTest.class.getClassLoader().getResource(path).toURI();
} catch (URISyntaxException e) {
String msg = String.format("Failed to load the resource with path '%s'", path);
throw new RuntimeException(msg, e);
}
}
}
14 changes: 14 additions & 0 deletions src/test/resources/myrdf/testImportTurtle02.ttl
@@ -0,0 +1,14 @@
@prefix : <http://www.example.com/ontology/1.0.0#> .
@prefix common: <http://www.example.com/ontology/1.0.0/common#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix project: <http://www.example.com/ontology/1.0.0/project#> .

project:DISTANCEVALUE-A181457
a :DISTANCEVALUE ;
:units common:MEASUREMENTUNIT-T1510615421640 ;
:value 0.55 .

common:MEASUREMENTUNIT-T1510615421640
a :MEASUREMENTUNIT ;
:name "metres" .