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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With