简体   繁体   中英

Updating embedded triples using xquery in MarkLogic

I tried to update embedded triples in marklogic using xquery but it seems to be not working for embedded triples however the same query is working for other triples can you tell me if there is some other option which needs to specified while performing an update on embedded triples. The code i used is

  xquery version "1.0-ml";
  import module namespace sem = "http://marklogic.com/semantics" 
  at "/Marklogic/semantics.xqy";

  let $triples := cts:triples(sem:iri("http://smartlogic.com/document#2012-10-26_DNB.OL_(Citi)_DNB_ASA_(DNB.OL)__Model_Update.61259187.xml"),()())
  for  $triple in  $triples
  let $node := sem:database-nodes($triple)
  let $replace := 
  <sem:triple>
  <sem:subject>http://www.example.com/products/1001_Test
  </sem:subject>
   {$node/sem:predicate, $node/sem:object}
  </sem:triple>

  return $node ! xdmp:node-replace(., $replace)

My document contains the following triple

  <sem:triples xmlns:sem="http://marklogic.com/semantics">
  <sem:triple>
  <sem:subject>http://smartlogic.com/document#2012-10-26_DNB.OL_(Citi)_DNB_ASA_(DNB.OL)__Model_Update.61259187.xml</sem:subject>
    <sem:predicate>http://www.smartlogic.com/schemas/docinfo.rdf#cik</sem:predicate>
  <sem:object>datatype="http://www.w3.org/2001/XMLSchema#string</sem:object>
  </sem:triple>
 </sem:triples>

and i want this particular subject to change into something like this

  <sem:subject>http://www.example.com/products/1001_Test</sem:subject>

But when i use the xquery to update it , it does not alter anything, the embedded triple in the documents remains the same. Because when i tried to see if any of the results have changed to the subject i specified it returned me no results.

I used the following query to test.

  SELECT *
  WHERE {
  <http://www.example.com/products/1001_Test> ?predicate ?object
  }

You need to add the option 'all' when you ask for the database nodes backing the triple: sem:database-nodes($triple, 'all') .

To be perfectly honest, I am not 100% sure why, but I think this is because your sem:triples element is not the root element of the document it appears on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM