从此thread继承而来,其中提到了“模板驱动提取”(TDE)作为从某个元素中检索值的一种方法。
当前,我正在尝试为某个路径一次创建多个TDE模板。我用来完成此操作的代码写在下面
xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde"
at "/MarkLogic/tde.xqy";
let $t1 :=
<template xmlns="http://marklogic.com/xdmp/tde">
<context>/question</context>
<vars>
<var>
<name>EX</name>
<val>""</val>
</var>
</vars>
<triples>
<triple>
<subject>
<val>sem:iri( $EX || name)</val>
</subject>
<predicate>
<val>sem:iri("/has_tags")</val>
</predicate>
<object>
<val>xs:dateTime( $EX || tags)</val>
</object>
</triple>
</triples>
</template>
let $t2 :=
<template xmlns="http://marklogic.com/xdmp/tde">
<context>/question</context>
<vars>
<var>
<name>EX</name>
<val>""</val>
</var>
</vars>
<triples>
<triple>
<subject>
<val>sem:iri( $EX || name)</val>
</subject>
<predicate>
<val>sem:iri("/date_posted")</val>
</predicate>
<object>
<val>xs:dateTime( $EX || date_posted)</val>
</object>
</triple>
</triples>
</template>
return(
tde:template-insert("question_has_tags.xml",$t1, (), "http://marklogic.com/xdmp/tde"),
tde:template-insert("question_date_posted.xml",$t2, (), "http://marklogic.com/xdmp/tde")
)
示例文档
<?xml version="1.0" encoding="UTF-8"?>
<question>
<tags>uifontweighttrait,spark-thriftserver,alarmmanager,recursive-type,string-iteration,security-trimming,google-earth</tags>
<date_posted>1978-06-23T22:22:43</date_posted>
<name>/question_on_forum</name>
</question>
模板已使用
进行了测试tde:node-data-extract(fn:doc("/question"));
导致错误的原因
[1.0-ml] TDE-EVALFAILED: tde:node-data-extract(fn:doc("/question/780989102826685")) -- Eval for Object='xs:dateTime( $EX || tags)' returns TDE-BADVALEXPRESSION: Invalid val expression: XDMP-CAST: (err:FORG0001) Invalid cast: "spotify,databags,laravel-horizon" cast as xs:dateTime
从我删除其中一个模板的那一刻起,此错误已解决
===========更新=========
使用以下代码尝试为每个模板创建多个三元组。但是,它也会导致相同的错误
xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde"
at "/MarkLogic/tde.xqy";
let $t2 :=
<template xmlns="http://marklogic.com/xdmp/tde">
<context>/question</context>
<triples>
<triple>
<subject>
<val>sem:iri( uri)</val>
</subject>
<predicate>
<val>sem:iri("/date_posted")</val>
</predicate>
<object>
<val>xs:dateTime(date_posted)</val>
</object>
</triple>
</triples>
<triples>
<triple>
<subject>
<val>sem:iri(uri)</val>
</subject>
<predicate>
<val>sem:iri("/has_tags")</val>
</predicate>
<object>
<val>tags</val>
</object>
</triple>
</triples>
</template>
return(
tde:template-insert("question_date_posted.xml",$t2, (), "http://marklogic.com/xdmp/tde")
)
节点提取以进行测试(这是发生错误的地方)
xquery version "1.0-ml";
tde:node-data-extract(fn:doc("/question"));
使用的示例文档
<?xml version="1.0" encoding="UTF-8"?>
<question>
<tags>jsondate,jmsserializerbundle,omnikey,eula,template-deduction,pyclipper,asyncpg,naming,kubeconfig,timer-trigger</tags>
<date_posted>1986-02-21T22:27:50</date_posted>
<uri>/question</uri>
</question>
答案 0 :(得分:0)
好的,我发现了问题所在。就我而言,这是一个小错误。该错误通过注释指出。
let $t2 :=
<template xmlns="http://marklogic.com/xdmp/tde">
<context>/question</context>
<triples>
<triple>
<subject>
<val>sem:iri( uri)</val>
</subject>
<predicate>
<val>sem:iri("/date_posted")</val>
</predicate>
<object>
<val>xs:dateTime(date_posted)</val>
</object>
</triple>
</triples>
<triples>
<triple>
<subject>
<val>sem:iri(uri)</val>
</subject>
<predicate>
<val>sem:iri("/has_tags")</val>
</predicate>
<object>
<val>xs:string(tags)</val> #needed to determine the variable type of tags object
</object>
</triple>
</triples>
</template>