[英]How to get the results of a TDE in MarkLogic in RDF/JSON or Turtle format?
With any kind of Template Driven Extraction (TDE) in MarkLogic, how can I convert the results I get from the tde:node-data-extract
function into RDF/JSON format?使用 MarkLogic 中的任何类型的模板驱动提取 (TDE),如何将从 tde
tde:node-data-extract
function 获得的结果转换为 RDF/JSON 格式? The JSON format returned by this method is not compliant with RDF/JSON, so I can't use it directly to insert triples into another database.该方法返回的 JSON 格式不符合 RDF/JSON,所以我不能直接使用它来将三元组插入另一个数据库。 In this case, I don't want to insert the triples into the same database that I'm applying the template against, I just want to use the template to create triples from XML data.
在这种情况下,我不想将三元组插入到应用模板的同一个数据库中,我只想使用模板从 XML 数据创建三元组。
Here's an example of the JSON output that I get from the tde:node-data-extract
function:这是我从 tde
tde:node-data-extract
function 获得的 JSON output 的示例:
{
"document/pt/document/39627370": [{
"triple": {
"subject": "http://www.example.com/document/id/39627370",
"predicate": "http://www.example.com/typeOf",
"object": {
"datatype": "http://www.w3.org/2001/XMLSchema#string",
"value": "http://www.example.com/document"
}
}
},
{
"triple": {
"subject": "http://www.example.com/publisher/Oxford_University_Press",
"predicate": "http://www.example.com/typeOf",
"object": {
"datatype": "http://www.w3.org/2001/XMLSchema#string",
"value": "http://www.example.com/publisher"
}
}
}
}
}
Convert each "triple" property into a triple object using sem.triple()
.使用
sem.triple()
将每个“三元组”属性转换为三元组 object 。 Then serialize the array of sem.triple
objects using sem.rdfSerialize()
.然后使用
sem.rdfSerialize()
序列化sem.triple
对象数组。
With the help from John and Mads, I found a slight variation that works really well assuming you're in the query console.在 John 和 Mads 的帮助下,我发现了一个细微的变化,假设您在查询控制台中,它的效果非常好。
$docs
is any sequence of documents and $template
is the TDE template. $docs
是任何文档序列, $template
是 TDE 模板。
let $jsontriples := tde:node-data-extract($docs, $template)
for $key in map:keys($jsontriples)
let $entry := map:get($jsontriples, $key)
return $entry["triple"]
This will return the triples automatically serialized into Turtle format in the query console Result tab, which you can switch to JSON or Text.这将在查询控制台结果选项卡中返回自动序列化为 Turtle 格式的三元组,您可以将其切换为 JSON 或文本。 I assume the answer from John is the most correct in a situation where the serialization is not automatically performed (eg when not using the query console).
我假设 John 的回答在序列化不是自动执行的情况下是最正确的(例如,当不使用查询控制台时)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.