Marklogic Cts:用sparql

时间:2016-02-04 15:53:58

标签: marklogic marklogic-7

在marklogic中,三元组可以嵌入到现有文档中。我如何使用cts搜索查询来返回文档。文档的示例可以是

<ContentVersion>
  <Name>Testing</Name>
  <Status>Approved</Status>
  <sem:triples xmlns:sem="http://marklogic.com/semantics">
   <sem:triple>
      <sem:subject>http://mycontent/content/Testing</sem:subject>
      <sem:predicate>is</sem:predicate>
      <sem:object>Approved</sem:object>
 </sem:triple>
</sem:triples>
</ContentVersion>

如果尝试以下查询

let $query := cts:word-query('Testing',"case-insensitive")
let $sparql := "PREFIX cts: <http://marklogic.com/cts#>
                DESCRIBE ?s 
                WHERE{ 
                   ?s ?p ?o .
                   FILTER cts:contains(?o, cts:word-query('Testing')) 
                }"
let $results := sem:sparql($sparql,(),("default-graph=magician"),($query))  
return(sem:rdf-serialize($results,'rdfxml'))

我得到一个空的结果。关于为什么没有归还的任何想法?我正在使用MarkLogic 7

1 个答案:

答案 0 :(得分:6)

cts:contains专注于?o,仅包含&#39; Approved&#39;。这就是为什么sem:sparql没有返回结果,而不是因为你使用cts查询错误的方式。

(更新..)

为了确认方法是有效的,我尝试了这个,它适用于我:

xquery version "1.0-ml";

let $xml := <ContentVersion>
  <Name>Testing</Name>
  <Status>Approved</Status>
  <sem:triples xmlns:sem="http://marklogic.com/semantics">
   <sem:triple>
      <sem:subject>http://mycontent/content/Testing</sem:subject>
      <sem:predicate>is</sem:predicate>
      <sem:object>Approved</sem:object>
 </sem:triple>
</sem:triples>
</ContentVersion>
return xdmp:document-insert("/test.xml", $xml, (), "magician")
;

let $query := cts:word-query('Testing',"case-insensitive")
let $sparql := "PREFIX cts: <http://marklogic.com/cts#>
                DESCRIBE ?s 
                WHERE{ 
                   ?s ?p ?o .
                   FILTER cts:contains(?o, cts:word-query('Approved')) 
                }"
let $results := sem:sparql($sparql,(),("default-graph=magician"),($query))  
return $results

使用QC对任何启用了三重索引的数据库执行此操作。

您确定要将自己的文档插入收集&#39;魔术师&#39 ;?这就是使用MarkLogic在特定图形中嵌入三元组的方法。

HTH!