Triples are not generated as expected from RDF file
Asked Answered
C

2

6

I am using MarkLogic 8.0-6.3

While generating triples from an RDF file using sem:rdf-load few of the triples are not created.

I have pasted the RDF file content, generated triples and the query which I am using to load the file.

RDF

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:skos="http://www.w3.org/2004/02/skos/core#"
         xmlns:skos-abc="http://www.abccustom.com#"
         xmlns:dc="http://purl.org/dc/elements/1.1/">
    <skos:Concept rdf:about="http://www.mla.com/work/W19622_2">
        <skos-abc:createdDate>5/10/2004 12:13:25 PM</skos-abc:createdDate>
        <skos-abc:classification>
            <skos-abc:literature>Netherlandic literature</skos-abc:literature>
            <skos-abc:timePeriod>1900-1999</skos-abc:timePeriod>
        </skos-abc:classification>
        <skos-abc:genreName>poetry</skos-abc:genreName>
    </skos:Concept>
</rdf:RDF>

Triples

<?xml version="1.0" encoding="UTF-8"?>
<sem:triples xmlns:sem="http://marklogic.com/semantics">
    <sem:triple>
        <sem:subject>http://www.mla.com/work/W19622_2</sem:subject>
        <sem:predicate>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</sem:predicate>
        <sem:object>http://www.w3.org/2004/02/skos/core#Concept</sem:object>
    </sem:triple>
    <sem:triple>
        <sem:subject>http://www.mla.com/work/W19622_2</sem:subject>
        <sem:predicate>http://www.abccustom.com#createdDate</sem:predicate>
        <sem:object datatype="http://www.w3.org/2001/XMLSchema#string">5/10/2004 12:13:25 PM</sem:object>
    </sem:triple>
    <sem:triple>
        <sem:subject>http://www.mla.com/work/W19622_2</sem:subject>
        <sem:predicate>http://www.abccustom.com#classification</sem:predicate>
        <sem:object>http://marklogic.com/semantics/blank/3225438043493348960</sem:object>
    </sem:triple>
    <sem:triple>
        <sem:subject>http://marklogic.com/semantics/blank/3225438043493348960</sem:subject>
        <sem:predicate>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</sem:predicate>
        <sem:object>http://www.abccustom.com#literature</sem:object>
    </sem:triple>
    <sem:triple>
        <sem:subject>http://www.mla.com/work/W19622_2</sem:subject>
        <sem:predicate>http://www.abccustom.com#classification</sem:predicate>
        <sem:object>http://marklogic.com/semantics/blank/6756667330843774627</sem:object>
    </sem:triple>
    <sem:triple>
        <sem:subject>http://marklogic.com/semantics/blank/6756667330843774627</sem:subject>
        <sem:predicate>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</sem:predicate>
        <sem:object>http://www.abccustom.com#timePeriod</sem:object>
    </sem:triple>
    <sem:triple>
        <sem:subject>http://www.mla.com/work/W19622_2</sem:subject>
        <sem:predicate>http://www.abccustom.com#genreName</sem:predicate>
        <sem:object datatype="http://www.w3.org/2001/XMLSchema#string">poetry</sem:object>
    </sem:triple>
</sem:triples>

Query

sem:rdf-load("D:\Projects\MLA\SKOS sample\work1.rdf", ("graph=thesaurus-work1"));

Triples aren't generated for below part

<skos-abc:classification>
    <skos-abc:literature>Netherlandic literature</skos-abc:literature>
    <skos-abc:timePeriod>1900-1999</skos-abc:timePeriod>
</skos-abc:classification>

I was expecting below triples as well in the output.

Sub: http://marklogic.com/semantics/blank/3225438043493348960
Pred: literature
Obj: Netherlandic literature
--------------------------------------
Sub: http://marklogic.com/semantics/blank/6756667330843774627
Pred: timePeriod
Obj: 1900-1999

Please help me in finding the problem in RDF.

Cancer answered 15/6, 2018 at 13:34 Comment(4)
The blank node was added, but wasn't called 'Blank_node'. Instead it got the subject iri http://marklogic.com/semantics/blank/3225438043493348960 as you can see from the sem:triples output that you shared..Selenaselenate
here I meant 'Blank_node' as the actual IRI. I have modified the question a bit. Please have a look at it now, why the expected triples were not generated as mentioned in the question.Cancer
Right, I see, they are returned as _:bnode4688104443361939814, not as http://marklogic.com/semantics/blank/4688104443361939814Selenaselenate
Okay got your point. But please help me in why the two triples(as mentioned in the question) are not created. Is @johns comment right that it's a but at MarkLogic side?Cancer
L
4

Could you take another look at your RDF to see if it correctly conveys your meaning? I think you want an anonymous node for the object of skos-abc:classification, with two properties, skos-abc:literature and skos-abs:classification. In that case, the RDF/XML serialization should be the following:

<?xml version="1.0"?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:skos-abc="http://www.abccustom.com#"
    xmlns:skos="http://www.w3.org/2004/02/skos/core#">
  <skos:Concept rdf:about="http://www.mla.com/work/W19622_2">
    <skos-abc:classification rdf:parseType="Resource">
      <skos-abc:literature>Netherlandic literature</skos-abc:literature>
      <skos-abc:timePeriod1>1900-1999</skos-abc:timePeriod1>
    </skos-abc:classification>
    <skos-abc:createdDate>5/10/2004 12:13:25 PM</skos-abc:createdDate>
  </skos:Concept>
</rdf:RDF>

Note the use of rdf:parseType for creating the anonymous node.

An additional caveat: RDF/XML is notoriously difficult to get correct. There are lots of non-RDF concepts embedded in the language to turn trees into graphs, etc. Even if that serialization is required (a standards-compliance bug in and of itself), I'd suggest using Turtle, N-triples, or JSON-LD. Here's the example in Turtle:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix skos-abc: <http://www.abccustom.com#> .
<http://www.mla.com/work/W19622_2>
  rdf:type skos:Concept ;
  skos-abc:classification [
      skos-abc:literature "Netherlandic literature" ;
      skos-abc:timePeriod1 "1900-1999" ;
    ] ;
  skos-abc:createdDate "5/10/2004 12:13:25 PM" ;
.

JSON-LD also makes the anonymous node explicit, which helps understand the underlying data structure:

{
  "@graph" : [ {
    "@id" : "_:b0",
    "literature" : "Netherlandic literature",
    "timePeriod1" : "1900-1999"
  }, {
    "@id" : "http://www.mla.com/work/W19622_2",
    "@type" : "skos:Concept",
    "classification" : "_:b0",
    "createdDate" : "5/10/2004 12:13:25 PM"
  } ],
  "@context" : {
    "literature" : {
      "@id" : "http://www.abccustom.com#literature"
    },
    "timePeriod1" : {
      "@id" : "http://www.abccustom.com#timePeriod1"
    },
    "classification" : {
      "@id" : "http://www.abccustom.com#classification",
      "@type" : "@id"
    },
    "createdDate" : {
      "@id" : "http://www.abccustom.com#createdDate"
    },
    "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    "skos-abc" : "http://www.abccustom.com#",
    "dcterms" : "http://purl.org/dc/terms/",
    "skos" : "http://www.w3.org/2004/02/skos/core#"
  }
}

...just some suggestions that may prove useful over time.

Legging answered 18/6, 2018 at 20:23 Comment(1)
Thanks scotthenninger, now the triples are generated as expected.Cancer
C
4

I agree that your RDF/XML data is not being parsed correctly by MarkLogic. Please contact MarkLogic support to create a bug report for this issue.

Catherine answered 18/6, 2018 at 10:58 Comment(1)
Actually scotthenninger is more familiar with RDF/XML than me, so you should maybe look into his answer.Catherine
L
4

Could you take another look at your RDF to see if it correctly conveys your meaning? I think you want an anonymous node for the object of skos-abc:classification, with two properties, skos-abc:literature and skos-abs:classification. In that case, the RDF/XML serialization should be the following:

<?xml version="1.0"?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:skos-abc="http://www.abccustom.com#"
    xmlns:skos="http://www.w3.org/2004/02/skos/core#">
  <skos:Concept rdf:about="http://www.mla.com/work/W19622_2">
    <skos-abc:classification rdf:parseType="Resource">
      <skos-abc:literature>Netherlandic literature</skos-abc:literature>
      <skos-abc:timePeriod1>1900-1999</skos-abc:timePeriod1>
    </skos-abc:classification>
    <skos-abc:createdDate>5/10/2004 12:13:25 PM</skos-abc:createdDate>
  </skos:Concept>
</rdf:RDF>

Note the use of rdf:parseType for creating the anonymous node.

An additional caveat: RDF/XML is notoriously difficult to get correct. There are lots of non-RDF concepts embedded in the language to turn trees into graphs, etc. Even if that serialization is required (a standards-compliance bug in and of itself), I'd suggest using Turtle, N-triples, or JSON-LD. Here's the example in Turtle:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix skos-abc: <http://www.abccustom.com#> .
<http://www.mla.com/work/W19622_2>
  rdf:type skos:Concept ;
  skos-abc:classification [
      skos-abc:literature "Netherlandic literature" ;
      skos-abc:timePeriod1 "1900-1999" ;
    ] ;
  skos-abc:createdDate "5/10/2004 12:13:25 PM" ;
.

JSON-LD also makes the anonymous node explicit, which helps understand the underlying data structure:

{
  "@graph" : [ {
    "@id" : "_:b0",
    "literature" : "Netherlandic literature",
    "timePeriod1" : "1900-1999"
  }, {
    "@id" : "http://www.mla.com/work/W19622_2",
    "@type" : "skos:Concept",
    "classification" : "_:b0",
    "createdDate" : "5/10/2004 12:13:25 PM"
  } ],
  "@context" : {
    "literature" : {
      "@id" : "http://www.abccustom.com#literature"
    },
    "timePeriod1" : {
      "@id" : "http://www.abccustom.com#timePeriod1"
    },
    "classification" : {
      "@id" : "http://www.abccustom.com#classification",
      "@type" : "@id"
    },
    "createdDate" : {
      "@id" : "http://www.abccustom.com#createdDate"
    },
    "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    "skos-abc" : "http://www.abccustom.com#",
    "dcterms" : "http://purl.org/dc/terms/",
    "skos" : "http://www.w3.org/2004/02/skos/core#"
  }
}

...just some suggestions that may prove useful over time.

Legging answered 18/6, 2018 at 20:23 Comment(1)
Thanks scotthenninger, now the triples are generated as expected.Cancer

© 2022 - 2024 — McMap. All rights reserved.