Skip to content

Instantly share code, notes, and snippets.

@grechaw
Created October 23, 2014 20:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grechaw/8b6fbb9bb3ed3eeb6103 to your computer and use it in GitHub Desktop.
Save grechaw/8b6fbb9bb3ed3eeb6103 to your computer and use it in GitHub Desktop.
Turn MarkLogic XML triples into MarkLogic JSON triples
(: if for some reason you want to take MarkLogic XML triples and make JSON triples from them, here's how: :)
let $docs := ("/triplestore/1e5ca14152cd5e08.xml","/triplestore/61ac1300bf2345c4.xml","/triplestore/6b24e3291b9d8fe0.xml","/triplestore/860af3160dfa6a14.xml")
let $triples := for $d in $docs
return doc($d)//sem:triple
let $json-triples :=
for $t in $triples
let $object := map:new((
map:entry("value" , $t/sem:object/text()),
if ($t/sem:object/@datatype) then map:entry("datatype", $t/sem:object/@datatype) else (),
if ($t/sem:object/@lang) then map:entry("lang", $t/sem:object/@datatype) else ()
))
return
object-node { "triple" :
object-node { "subject" : object-node { "value" : $t/sem:subject/text() },
"predicate" : object-node { "value" : $t/sem:predicate/text() } ,
"object" : xdmp:to-json($object)/node() }
}
return xdmp:save("/home/cgreer/tmp/x.json", array-node { $json-triples })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment