如何将TDE生成的非托管三元组存入特定图或集合?
将TDE生成的非托管三元组指定到特定图或集合的方法
当然可以,核心是通过调整TDE模板的配置来实现,以下是两种常用方式:
指定到特定图
在TDE模板中直接为生成的三元组绑定目标图,有两种实现形式:
- 给
<tde:triples>元素添加graph属性,静态指定图的URI:
<tde:template xmlns:tde="http://marklogic.com/xdmp/tde"> <tde:context>/root</tde:context> <tde:triples graph="http://example.com/my-target-graph"> <tde:triple> <tde:subject>http://example.com/entity/{id}</tde:subject> <tde:predicate>http://example.com/name</tde:predicate> <tde:object>{name}</tde:object> </tde:triple> </tde:triples> </tde:template>
- 使用
tde:graph()函数动态生成图URI(比如基于文档字段值):
<tde:template xmlns:tde="http://marklogic.com/xdmp/tde"> <tde:context>/root</tde:context> <tde:triples> <tde:triple> <tde:subject>http://example.com/entity/{id}</tde:subject> <tde:predicate>http://example.com/name</tde:predicate> <tde:object>{name}</tde:object> <tde:graph>{tde:graph(concat("http://example.com/graphs/", category))}</tde:graph> </tde:triple> </tde:triples> </tde:template>
指定到特定集合
通过tde:collection()函数在模板中为三元组绑定集合,支持静态或动态集合名:
<tde:template xmlns:tde="http://marklogic.com/xdmp/tde"> <tde:context>/root</tde:context> <tde:triples> <tde:triple> <tde:subject>http://example.com/entity/{id}</tde:subject> <tde:predicate>http://example.com/name</tde:predicate> <tde:object>{name}</tde:object> <tde:collection>{tde:collection("my-target-collection")}</tde:collection> </tde:triple> </tde:triples> </tde:template>
若需绑定多个集合,直接添加多个<tde:collection>元素即可。
注意:上述配置要求MarkLogic 9及以上版本支持。模板生效后,新提取的三元组会自动归属到指定的图或集合;已生成的非托管三元组需重新触发提取,或通过XQuery批量迁移至目标位置。
内容的提问来源于stack exchange,提问作者AkG
相关产品推荐
相关产品推荐

