0

I need to create a Template using TDE in MarkLogic. And this template will generate triples from the exiting XML documents. Where the subject is the URI of the doc, the predicate is the name of the element and the Object is the value of the element.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Anuj Gupta
  • 31
  • 4

1 Answers1

2

The Semantics guide has examples. For what you ask, you could do something like this, but note that context paths like that could potentially degrade ingest performance considerably (depending on size of your input data):

<template xmlns="http://marklogic.com/xdmp/tde">
  <context>//*[text()]</context>
    <vars>
      <var>
        <name>EX</name>
        <val>"http://example.org/ex#"</val>
      </var>
    </vars>
  <triples>
    <triple>
      <subject>
        <val>sem:iri( fn:base-uri(.) )</val>
      </subject>
      <predicate>
        <val>sem:iri( $EX || fn:name(.) )</val>
      </predicate>
      <object>
        <val>fn:data( . )</val>
      </object>
    </triple>
  </triples>
</template>

HTH!

grtjn
  • 20,254
  • 1
  • 24
  • 35
  • It is not extracting any data from xml. – Anuj Gupta Jan 29 '18 at 06:31
  • Can you add more detail about what you tried with what results in the Question section? – grtjn Jan 29 '18 at 16:13
  • One more thing is there any way to get the triples in XML formats instead of JSON? Also can we use TDE to create and insert Triples XML in ML. – Anuj Gupta Jan 30 '18 at 11:58
  • Triples extracted with TDE are stored in the triple index only, not persisted on disk. They have neither XML nor JSON format. You can however run a SPARQL query, and then decide to save the result as persisted triples in the database, either as managed triples, or as embedded triples in JSON or XML documents. – grtjn Jan 30 '18 at 12:53
  • Thanks! So can you tell me how can we store the SPARQL query result in ML database as triples? – Anuj Gupta Jan 30 '18 at 14:11
  • With a SPARQL Update statement along the lines of `CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }`. – grtjn Jan 30 '18 at 18:55
  • Thanks! So which is better to use. In memory or indisk? – Anuj Gupta Jan 31 '18 at 07:29