Skip to content

Commit ee61af0

Browse files
committed
fixed test on streamRDF error reporting
1 parent ac5bf43 commit ee61af0

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

docs/asciidoc/_import.adoc

+26-26
Original file line numberDiff line numberDiff line change
@@ -559,66 +559,66 @@ We obviously need a query producing RDF so we can import it into Neo4j. I'm usin
559559

560560
[source,cypher]
561561
----
562-
CALL semantics.importRDF("http://bnb.data.bl.uk/sparql","Turtle",{ handleVocabUris: "IGNORE", headerParams: { Accept: "application/turtle"}, payload: "query=DESCRIBE <http://bnb.data.bl.uk/id/resource/018212405>" })
562+
CALL semantics.importRDF("https://bnb.data.bl.uk/sparql","Turtle",{ handleVocabUris: "IGNORE", headerParams: { Accept: "application/turtle"}, payload: "query=" + apoc.text.urlencode("DESCRIBE <http://bnb.data.bl.uk/id/resource/018212405>") })
563563
----
564564

565-
After running this you get a pretty poor graph, because the DESCRIBE query only returns the statements having 'The world of yesterday' (`<http://bnb.data.bl.uk/id/resource/018212405>`) as subject. But we can enrich it a bit by re-running it for every single URI connected to our book as follows:
565+
Notice that the Bristish Library service requires you to encode the SPARQL query. We do this with https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_overview_text_functions[APOC's apoc.text.urlencode function]. After running this you get a pretty poor graph, because the
566+
DESCRIBE query only returns the statements having 'The world of yesterday' (`<http://bnb.data.bl.uk/id/resource/018212405>`) as subject or object.
567+
But we can enrich it a bit by re-running it for a all of the URIs connected to our book as follows:
566568

567569
[source,cypher]
568570
----
569-
MATCH (:Book)-->(t) WITH t
570-
CALL semantics.importRDF("http://bnb.data.bl.uk/sparql","Turtle",{ handleVocabUris: "IGNORE", headerParams: { Accept: "application/turtle"}, payload: "query=DESCRIBE <" + t.uri + ">"}) yield triplesLoaded
571-
return t.uri, triplesLoaded
571+
MATCH (:Book)-->(t) WITH DISTINCT t
572+
CALL semantics.importRDF("https://bnb.data.bl.uk/sparql","Turtle",{ handleVocabUris: "IGNORE", headerParams: { Accept: "application/turtle"}, payload: "query=" + apoc.text.urlencode("CONSTRUCT {<" + t.uri + "> ?p ?o } { <" + t.uri + "> ?p ?o } LIMIT 10 ")}) yield triplesLoaded
573+
return t.uri, triplesLoaded
572574
----
573575

576+
574577
Which returns:
575578

576579
[source,cypher]
577580
----
578581
╒══════════════════════════════════════════════════════════════════════╤═══════════════╕
579582
│"t.uri" │"triplesLoaded"│
580583
╞══════════════════════════════════════════════════════════════════════╪═══════════════╡
581-
│"http://bnb.data.bl.uk/id/concept/ddc/e22/838.91209" │6 │
582-
├──────────────────────────────────────────────────────────────────────┼───────────────┤
583-
│"http://rdaregistry.info/termList/RDAMediaType/1003" │3 │
584+
│"http://bnb.data.bl.uk/id/person/ZweigStefan1881-1942" │5 │
584585
├──────────────────────────────────────────────────────────────────────┼───────────────┤
585-
│"http://bnb.data.bl.uk/id/person/ZweigStefan1881-1942" │132
586+
│"http://rdaregistry.info/termList/RDACarrierType/1018" │1
586587
├──────────────────────────────────────────────────────────────────────┼───────────────┤
587-
│"http://bnb.data.bl.uk/id/concept/person/lcsh/ZweigStefan1881-1942" │10
588+
│"http://bnb.data.bl.uk/id/concept/place/lcsh/Europe" │4
588589
├──────────────────────────────────────────────────────────────────────┼───────────────┤
589-
│"http://bnb.data.bl.uk/id/place/Europe" │9
590+
│"http://bnb.data.bl.uk/id/concept/lcsh/EuropeCivilization20thcentury" │5
590591
├──────────────────────────────────────────────────────────────────────┼───────────────┤
591-
│"http://rdaregistry.info/termList/RDACarrierType/1018" │3 │
592-
├──────────────────────────────────────────────────────────────────────┼───────────────┤
593-
│"http://bnb.data.bl.uk/id/resource/018212405/publicationevent/Placeofp│4 │
594-
│ublicationnotidentifiedPushkinPress2009" │ │
592+
│"http://bnb.data.bl.uk/id/resource/GBB721847" │1 │
595593
├──────────────────────────────────────────────────────────────────────┼───────────────┤
596-
│"http://bnb.data.bl.uk/id/person/ZweigStefan1881-1942" │132
594+
│"http://bnb.data.bl.uk/id/place/Europe" │3
597595
├──────────────────────────────────────────────────────────────────────┼───────────────┤
598-
│"http://rdaregistry.info/termList/RDAContentType/1020" │3
596+
│"http://lexvo.org/id/iso639-3/eng" │0
599597
├──────────────────────────────────────────────────────────────────────┼───────────────┤
600-
│"http://bnb.data.bl.uk/id/resource/GBB721847" │1
598+
│"http://bnb.data.bl.uk/id/concept/lcsh/WorldWar1914-1918Influence" │5
601599
├──────────────────────────────────────────────────────────────────────┼───────────────┤
602-
│"http://bnb.data.bl.uk/id/concept/lcsh/WorldWar1914-1918Influence" │10
600+
│"http://rdaregistry.info/termList/RDAMediaType/1003" │1
603601
├──────────────────────────────────────────────────────────────────────┼───────────────┤
604-
│"http://bnb.data.bl.uk/id/concept/place/lcsh/Europe" │18 │
602+
│"http://bnb.data.bl.uk/id/concept/lcsh/AuthorsAustrian20thcenturyBiogr│5 │
603+
│aphy" │ │
605604
├──────────────────────────────────────────────────────────────────────┼───────────────┤
606-
│"http://bnb.data.bl.uk/id/resource/GBB721847" │1 │
605+
│"http://bnb.data.bl.uk/id/resource/018212405/publicationevent/Placeofp│4 │
606+
│ublicationnotidentifiedPushkinPress2009" │ │
607607
├──────────────────────────────────────────────────────────────────────┼───────────────┤
608-
│"http://lexvo.org/id/iso639-3/eng" │0
608+
│"http://rdaregistry.info/termList/RDAContentType/1020" │1
609609
├──────────────────────────────────────────────────────────────────────┼───────────────┤
610-
│"http://bnb.data.bl.uk/id/concept/lcsh/EuropeCivilization20thcentury" │10
610+
│"http://bnb.data.bl.uk/id/concept/ddc/e22/838.91209" │3
611611
├──────────────────────────────────────────────────────────────────────┼───────────────┤
612-
│"http://bnb.data.bl.uk/id/concept/lcsh/AuthorsAustrian20thcenturyBiogr│5 │
613-
│aphy" │ │
612+
│"http://bnb.data.bl.uk/id/concept/person/lcsh/ZweigStefan1881-1942" │5 │
614613
└──────────────────────────────────────────────────────────────────────┴───────────────┘
615614
----
616615

617616
And produces this graph:
618617

619618
image::worldofyesterday.png[Graph resulting of importing the data in the British National Library on 'The world of yesterday' by Stefan Zweig]
620619

621-
Of course you could do achieve this -or something similar- in different ways, the most obvious one would be using a SPARQL CONSTRUCT query, but I leave that to the interested (and SPARQL savvy) reader.
620+
Of course you could do achieve this -or something similar- in different ways, in this case we are using a SPARQL CONSTRUCT query in order to be able to limit
621+
the number of triples returned for each resource as some of them are pretty dense.
622622

623623
[#custom_ns]
624624
=== Defining custom prefixes for namespaces

docs/asciidoc/_inference.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ inferences whatever the modeling approach you follow from the ones described bef
5151
==== semantics.inference.nodesLabelled
5252

5353
Let's look at the first way of annotating individuals. This script creates a few publications (books) from the
54-
http://British National Library catalog[British National Library catalog] sets a label
54+
https://bnb.data.bl.uk/[British National Library catalog] sets a label
5555
on each of them. The labels match categories defined before.
5656

5757
[source,Cypher]

src/test/java/semantics/RDFImportTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,13 @@ public void testStreamFromBadUriFileFail() throws Exception {
11671167
= session.run("CALL semantics.streamRDF('" +
11681168
RDFImportTest.class.getClassLoader().getResource("badUri.ttl")
11691169
.toURI() + "','Turtle',{})");
1170-
assertFalse(importResults
1170+
assertTrue(importResults
11711171
.hasNext());
1172+
Record next = importResults.next();
1173+
assertEquals("neo4j://error", next.get("subject").asString());
1174+
assertEquals("neo4j://message", next.get("predicate").asString());
1175+
assertTrue(next.get("object").asString().startsWith("Illegal percent encoding"));
1176+
assertEquals(true, next.get("isLiteral").asBoolean());
11721177
}
11731178
}
11741179

0 commit comments

Comments
 (0)