Anuj Gupta
Anuj Gupta

Reputation: 31

How to create a Template using TDE in MarkLogic to generate Triples

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.

Upvotes: 0

Views: 367

Answers (1)

grtjn
grtjn

Reputation: 20414

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!

Upvotes: 2

Related Questions