Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Pause, resolving how to handle anonymous content

N10s.rdf.preview.fetch vs n10s.rdf.import.fetch



I'm trying to build a knowledge graph from Wikidata using the n10s library. When I run the following using n10s.rdf.preview.fetch I get a preview of the nodes and relationships which look correct:

WITH 'PREFIX wdt: <>
PREFIX wd: <>
PREFIX sch: <> 
PREFIX rdfs:  <> 
  ?band a sch:Band ; 
          sch:name ?bandName ; 
          wdt:P571 ?startYear . 
  ?member a sch:Musician ; 
            sch:name ?memberName ; 
            wdt:P463 ?band . 
  ?album a sch:Release ; 
           sch:name ?albumName ; 
           wdt:P175 ?band ; 
           wdt:P577 ?releaseDate . } 
  ?band wdt:P136 wd:Q49451. 
  ?band wdt:P495 ?country ; 
        wdt:P571 ?startYear ; 
        rdfs:label ?bandName . filter (lang(?bandName) = "en") . 
  ?album wdt:P175 ?band ; 
         wdt:P577 ?releaseDate ; 
         rdfs:label ?albumName . filter (lang(?albumName) = "en") . 
  OPTIONAL {?member wdt:P463 ?band ; 
          rdfs:label ?memberName . filter (lang(?memberName) = "en") . }
  FILTER(YEAR(?startYear) <= 1980 &&  ?country IN ( wd:Q145, wd:Q38 )). SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }}' AS sparql
CALL n10s.rdf.preview.fetch(
    '' + apoc.text.urlencode(sparql), "JSON-LD", { headerParams: { Accept: "application/ld+json"},
YIELD nodes, relationships
RETURN nodes, relationships

However, when I run the same code but using n10s.rdf.import.fetch I get terminationStatus: KO, triplesParsed: 0, triplesLoaded: 0

...same code...
CALL n10s.rdf.import.fetch(
    '' + apoc.text.urlencode(sparql), "JSON-LD", { headerParams: { Accept: "application/ld+json"},
YIELD terminationStatus, triplesLoaded, triplesParsed
RETURN terminationStatus, triplesLoaded, triplesParsed

Can anyone help explain why preview is returning the triples but import isn't doing anything?

I'm using:
Browser version: 4.3.5
Server version: 4.2.1




So after spending the past 48 hours trying to figure this out, and after posting my questions I finally stumbled across the answer so thought I would post back to the forum in case anyone else has the same question in future. I had not created a constraint prior to trying to run the import. Running the following code has solved my problem:

CREATE CONSTRAINT n10s_unique_uri ON (r:Resource) ASSERT r.uri IS UNIQUE

I'd been using resources from various sites and only just stumbled on this README from @jesus.barrasa .

Hey @Grant592 , sorry to hear it took so long to find the answer 😞

The required constraint is described in chapter 2 of the manual "Configuring Neo4j to use RDF data". Maybe it should go in a more prominent place in the manual?

The reason why you were not seeing a more informative output message is that the extraInfo field was excluded from the output of the n10s.rdf.import.* procedure. Notice below what the YIELD+RETURN part of your query would look like when including the extra fields,

YIELD terminationStatus, triplesLoaded, triplesParsed, namespaces, extraInfo
RETURN terminationStatus, triplesLoaded, triplesParsed, namespaces, extraInfo

Hope this helps.


Thanks for the reply. And having looked back, I can see the piece of info I needed was there at the start of the official Neosemantics docs but because I was using various different blogs/sources I hadn't noticed this was a prerequisite to use this procedure! My own fault really.

Just getting started with Neo4j and graph databases in general, so it's nice to see the forums are such a friendly and responsive place!

Nodes 2022
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online