Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marklogic Cts:search with sparql

In marklogic, triples can be embedded into an existing document. How can i use cts search query to return the document. An example of a document could be

<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>

if try the below query

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'))

I get an empty result. Any ideas on why nothing is returned? I am using MarkLogic 7

like image 833
C Kingsley Avatar asked Mar 14 '23 09:03

C Kingsley


1 Answers

The cts:contains is focused to ?o, which only contains 'Approved'. That is why the sem:sparql is not returning results, not because you are using the cts query the wrong way.

(update..)

To confirm the approach is valid, I tried this and it works for me:

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

Run this with QC against any database that has triple index enabled.

Are you sure you insert your docs with collection 'magician'? That is how you can get embedded triples inside a specific graph with MarkLogic.

HTH!

like image 109
grtjn Avatar answered May 09 '23 19:05

grtjn