In TDE Marklogic how to escape null value triples?

2019-08-12 15:25发布

<template xmlns="http://marklogic.com/xdmp/tde">
    <context>/test</context>
    <vars>
        <var>
            <name>subprefix</name>
            <val>"http://www.test.com/resource/test/"</val>
        </var>
    <var>
            <name>objprefix</name>
            <val>"http://www.test.com/resource/test/"</val>
        </var>
    </vars>
    <triples>
        <triple>
            <subject>
                <val>sem:iri($subprefix || ElemenetName)</val>
                <invalid-values>ignore</invalid-values>
            </subject>
            <predicate>
                <val>sem:iri('is')</val>
            </predicate>
            <object>
                <val>sem:iri($objprefix || FullName)</val>
                <invalid-values>ignore</invalid-values>
            </object>
        </triple>
    </triples>
</template>

I have created a Template to get triples out of XML.

But want to escape null value triples(s,p or o). I am using ignore, but this works only if there is not prefix in subject or object. If there is prefix it creates triples with null(only prefix).

Do we have any way to handle this in MarkLogic TDE?

Nullable object/subject issue.

PFB.

1条回答
你好瞎i
2楼-- · 2019-08-12 16:03

You can take more use from the context expression, particularly if you use sub-templates. Here a crude example showing a sub-template, applied to 3 example docs:

xquery version "1.0-ml";

let $tde :=
<template xmlns="http://marklogic.com/xdmp/tde">
  <context>/test</context>
  <vars>
    <var>
      <name>subprefix</name>
      <val>"http://www.test.com/resource/test/"</val>
    </var>
    <var>
      <name>objprefix</name>
      <val>"http://www.test.com/resource/test/"</val>
    </var>
  </vars>
  <templates>
    <template>
      <context>FullName</context>
      <triples>
        <triple>
            <subject>
                <val>sem:iri($subprefix || ../ElemenetName)</val>
                <invalid-values>ignore</invalid-values>
            </subject>
            <predicate>
                <val>sem:iri('is')</val>
            </predicate>
            <object>
                <val>sem:iri($objprefix || .)</val>
                <invalid-values>ignore</invalid-values>
            </object>
        </triple>
      </triples>
    </template>
  </templates>
</template>
let $xml1 := <test><ElemenetName>elem</ElemenetName><FullName>full</FullName></test>
let $xml2 := <test><ElemenetName>elem</ElemenetName></test>
let $xml3 := <test><FullName>full</FullName></test>
return tde:node-data-extract(($xml1, $xml2, $xml3), $tde)

Some more background on sub-templates can be found here:

https://docs.marklogic.com/guide/sql/creating-template-views#id_28999

HTH!

查看更多
登录 后发表回答