Help importing N-Quads (.nq) RDF file into Dgraph

Hi Dgraph community,

I’m trying to import a small RDF dataset (N-Quad format) into dgraph but it seems I’m doing something wrong, after importing the data I can see the schema, but no data is there.

This is the output of the import

root@2becbdb6014d:/# dgraph live -f small.nq --format=rdf -s schema.txt
[Decoder]: Using assembly version of decoder
I0104 11:17:40.690649     107 init.go:99]

Dgraph version   : v20.03.0
Dgraph SHA-256   : 07e63901be984bd20a3505a2ee5840bb8fc4f72cc7749c485f9f77db15b9b75a
Commit SHA-1     : 147c8df9
Commit timestamp : 2020-03-30 17:28:31 -0700
Branch           : HEAD
Go version       : go1.14.1

For Dgraph official documentation, visit https://docs.dgraph.io.
For discussions about Dgraph     , visit http://discuss.dgraph.io.
To say hi to the community       , visit https://dgraph.slack.com.

Licensed variously under the Apache Public License 2.0 and Dgraph Community License.
Copyright 2015-2020 Dgraph Labs, Inc.



Running transaction with dgraph endpoint: 127.0.0.1:9080

Processing schema file "schema.txt"
Processed schema file "schema.txt"

Found 1 data file(s) to process
Processing data file "small.nq"
Number of TXs run            : 1
Number of N-Quads processed  : 52
Time spent                   : 2.473998115s
N-Quads processed per second : 26
root@2becbdb6014d:/#

The query that I’m using to get data:

    {
      hasPrefLabel(func: has(<http://www.w3.org/2004/02/skos/core#prefLabel>)) {
        uid
      }
    }

My Schema:

<http://www.w3.org/2004/02/skos/core#prefLabel>: string @lang .
<http://purl.org/dc/terms/title>: string @lang @index(exact) .
<http://schema.semantic-web.at/ppt/history#affectedLiteral>:  string @lang @index(exact) .
<http://www.w3.org/2000/01/rdf-schema#label>: string @lang @index(exact) .
<http://www.w3.org/2004/02/skos/core#definition>: string @lang @index(term) .

I can’t upload the dataset (seems thats because I’m a new user), but the dataset looks like the following:

<https://comp.my.addr/fur/0> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#ConceptScheme> <https://comp.my.addr/fur/thesaurus> .
<https://comp.my.addr/fur/0> <http://purl.org/dc/terms/title> "Home"@en <https://comp.my.addr/fur/thesaurus> .
<https://comp.my.addr/fur/0> <http://purl.org/dc/terms/created> "2020-12-01T17:17:18.360Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> <https://comp.my.addr/fur/thesaurus> .
<https://comp.my.addr/fur/0> <http://purl.org/dc/terms/creator> <https://comp.my.addr/user/user> <https://comp.my.addr/fur/thesaurus> .
<https://comp.my.addr/fur/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> <https://comp.my.addr/fur/thesaurus> .
<https://comp.my.addr/fur/1> <http://www.w3.org/2004/02/skos/core#prefLabel> "Text Text F"@en <https://comp.my.addr/fur/thesaurus> .
<https://comp.my.addr/fur/0> <http://www.w3.org/2004/02/skos/core#hasTopConcept> <https://comp.my.addr/fur/1> <https://comp.my.addr/fur/thesaurus> .
<https://comp.my.addr/fur/1> <http://www.w3.org/2004/02/skos/core#topConceptOf> <https://comp.my.addr/fur/0> <https://comp.my.addr/fur/thesaurus> .

I tried tweaking the schema but the results were the same, do you have any other suggestions?

Thank you :slight_smile:

Welcome @JoaoRodrigues!
Please try this:

{
   query(func: has(<http://www.w3.org/2004/02/skos/core#hasTopConcept>)) {
        uid
        <http://purl.org/dc/terms/title>@en
        <http://purl.org/dc/terms/created>
        <http://purl.org/dc/terms/creator>
        <http://www.w3.org/2004/02/skos/core#hasTopConcept>{
          <http://www.w3.org/2004/02/skos/core#prefLabel>@en
    }
  }
}

You should get results like this:

{
  "data": {
    "query": [
      {
        "uid": "0x2",
        "http://purl.org/dc/terms/title@en": "Home",
        "http://purl.org/dc/terms/created": "2020-12-01T17:17:18.36Z",
        "http://www.w3.org/2004/02/skos/core#hasTopConcept": [
          {
            "http://www.w3.org/2004/02/skos/core#prefLabel@en": "Text Text F"
          }
        ]
      }
    ]
  }
}
1 Like

Thank you! Yes, I can confirm the data is there and I can read using the correct query syntax.

1 Like

Dgraph doesn’t support this type of RDF (W3C Nquads). Dgraph supports Triples only. You probably should sanitize this dataset before importing.

2 Likes