In TDE Marklogic how to escape null value triples?

試著忘記壹切 提交于 2019-12-11 04:31:14

问题


<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.


回答1:


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!



来源:https://stackoverflow.com/questions/56766731/in-tde-marklogic-how-to-escape-null-value-triples

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!