Skip to content

Commit c968e28

Browse files
committed
enabled predicateExclusionList on rdf.stream procedures
1 parent 3301744 commit c968e28

File tree

3 files changed

+79
-7
lines changed

3 files changed

+79
-7
lines changed

src/main/java/n10s/rdf/stream/StatementStreamer.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ public void handleNamespace(String s, String s1) throws RDFHandlerException {
3939
@Override
4040
public void handleStatement(Statement st) throws RDFHandlerException {
4141
if (statements.size() < parserConfig.getStreamTripleLimit()) {
42-
Value object = st.getObject();
43-
StreamedStatement statement = new StreamedStatement(st.getSubject().stringValue(),
44-
st.getPredicate().stringValue(), object.stringValue(),
45-
(object instanceof Literal),
46-
((object instanceof Literal) ? ((Literal) object).getDatatype().stringValue() : null),
47-
(object instanceof Literal ? ((Literal) object).getLanguage().orElse(null) : null));
48-
statements.add(statement);
42+
if(parserConfig.getPredicateExclusionList() == null || !parserConfig
43+
.getPredicateExclusionList()
44+
.contains(st.getPredicate().stringValue())) {
45+
Value object = st.getObject();
46+
StreamedStatement statement = new StreamedStatement(st.getSubject().stringValue(),
47+
st.getPredicate().stringValue(), object.stringValue(),
48+
(object instanceof Literal),
49+
((object instanceof Literal) ? ((Literal) object).getDatatype().stringValue() : null),
50+
(object instanceof Literal ? ((Literal) object).getLanguage().orElse(null) : null));
51+
statements.add(statement);
52+
}
4953
} else {
5054
throw new TripleLimitReached(parserConfig.getStreamTripleLimit() + " triples streamed");
5155
}

src/test/java/n10s/RDFProceduresTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,50 @@ public void testStreamFromFileWithLimit() throws Exception {
20722072
}
20732073
}
20742074

2075+
@Test
2076+
public void testStreamFromFileWithExclusionList() throws Exception {
2077+
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(),
2078+
Config.builder().withoutEncryption().build()); Session session = driver.session()) {
2079+
2080+
String filteredPred = "http://schema.org/image";
2081+
2082+
Result importResults
2083+
= session.run("CALL n10s.rdf.stream.fetch('" +
2084+
RDFProceduresTest.class.getClassLoader().getResource("event.json")
2085+
.toURI() + "','JSON-LD')");
2086+
2087+
int tripleCount = 0;
2088+
int filteredPredicatesCount = 0;
2089+
while(importResults.hasNext()){
2090+
Record next = importResults.next();
2091+
if(next.get("predicate").asString().equals(filteredPred)){
2092+
filteredPredicatesCount++;
2093+
}
2094+
tripleCount++;
2095+
}
2096+
assertEquals(28,tripleCount);
2097+
assertEquals(3,filteredPredicatesCount);
2098+
2099+
2100+
importResults
2101+
= session.run("CALL n10s.rdf.stream.fetch('" +
2102+
RDFProceduresTest.class.getClassLoader().getResource("event.json")
2103+
.toURI() + "','JSON-LD',{ predicateExclusionList: ['" + filteredPred + "'] })");
2104+
2105+
tripleCount = 0;
2106+
filteredPredicatesCount = 0;
2107+
while(importResults.hasNext()){
2108+
Record next = importResults.next();
2109+
if(next.get("predicate").asString().equals(filteredPred)){
2110+
filteredPredicatesCount++;
2111+
}
2112+
tripleCount++;
2113+
}
2114+
assertEquals(25,tripleCount);
2115+
assertEquals(0,filteredPredicatesCount);
2116+
}
2117+
}
2118+
20752119
@Test
20762120
public void testStreamFromString() throws Exception {
20772121
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(),

src/test/java/n10s/endpoint/RDFEndpointTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,30 @@ public void testGetNodeById() throws Exception {
142142

143143
}
144144

145+
// @Test
146+
// public void testGetNodeByUriOnLPGGraph() throws Exception {
147+
// final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService();
148+
// try (Transaction tx = graphDatabaseService.beginTx()) {
149+
//
150+
// String dataInsertion = "create (:Person:Resource { name: \"JB\", uri: \"http://neo4j.paradise.icij.dataset/ind/JB\"})" +
151+
// "-[:KNOWS]->(:Person:Resource { name: \"CC\", uri: \"http://neo4j.paradise.icij.dataset/ind/CC\"})";
152+
// tx.execute(dataInsertion);
153+
// tx.commit();
154+
//
155+
// }
156+
//
157+
// // When
158+
// HTTP.Response response = HTTP.withHeaders("Accept", "application/ld+json").GET(
159+
// HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/describe/"
160+
// + URLEncoder.encode("http://neo4j.paradise.icij.dataset/ind/JB",StandardCharsets.UTF_8));
161+
//
162+
// String expected = "";
163+
// assertEquals(200, response.status());
164+
// System.out.println(response.rawContent());
165+
// assertTrue(ModelTestUtils
166+
// .compareModels(expected, RDFFormat.JSONLD, response.rawContent(), RDFFormat.JSONLD));
167+
//
168+
// }
145169

146170
@Test
147171
public void testGetNodeByIdFromRDFizedLPG() throws Exception {

0 commit comments

Comments
 (0)