Created
October 23, 2014 20:29
-
-
Save grechaw/8b6fbb9bb3ed3eeb6103 to your computer and use it in GitHub Desktop.
Turn MarkLogic XML triples into MarkLogic JSON triples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: 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