继承自这个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当我删除其中一个模板时,这个错误就解决了
=UPDATE=
以下代码用于尝试为每个模板创建多个三元组。但是,它也会导致相同的错误
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>发布于 2019-03-18 14:49:00
好了,我已经找到问题所在了。这是我的一个小错误。错误由一条注释指出。
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>https://stackoverflow.com/questions/55179369
复制相似问题