我一直在尝试使用此查询在Marklogic中插入三元组
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
at "/MarkLogic/semantics.xqy";
declare variable $TRIPLE as xs:string external ;
declare variable $GRAPHNAME as xs:string external ;
let $TRIPLE:="sem:triple(sem:iri('http://smartlogic.com/document#testForTriples.xml'),sem:iri('http://www.smartlogic.com/schemas/docinfo.rdf#type'),'document')"
let $GRAPHNAME :="sem:iri('testGraph')"
let $r :=
sem:graph-insert($GRAPHNAME, $TRIPLE)
return <result>{$r}</result>
不幸的是,这会返回强制错误:
XDMP-AS: (err:XPTY0004) $graphname as sem:iri -- Invalid coercion: "sem:iri('testGraph')" as sem:iri
我做错了什么?
答案 0 :(得分:1)
你不应该在sem:triple
和sem:iri
附近加上引号,它们是类型转换函数:
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
at "/MarkLogic/semantics.xqy";
let $TRIPLE := sem:triple(sem:iri('http://smartlogic.com/document#testForTriples.xml'),sem:iri('http://www.smartlogic.com/schemas/docinfo.rdf#type'),'document')
let $GRAPHNAME := sem:iri('testGraph')
let $r := sem:graph-insert($GRAPHNAME, $TRIPLE)
return <result>{$r}</result>
如果您尝试动态创建三元组,请通过sem:triple或sem:iri来自外部的对象,或者传递字符串值,并将它们转换为代码。
HTH!