MarkLogic模板驱动的提取和三元组:处理数组节点 [英] MarkLogic template driven extraction and triples: dealing with array nodes

查看:96
本文介绍了MarkLogic模板驱动的提取和三元组:处理数组节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在这里研究示例: https://docs.marklogic. com/guide/semantics/tde#id_25531

I've been studying the examples here: https://docs.marklogic.com/guide/semantics/tde#id_25531

我有一组文档,这些文档的结构由父名称和具有自己名称的子节点组成.我想创建一个模板,该模板生成形式为"name1 is-a-parent-of name2"的三元组.这是我尝试过的测试,其中包含文档结构的示例:

I have a set of documents that are structured with a parent name and an array of children nodes with their own names. I want to create a template that generates triples of the form "name1 is-a-parent-of name2". Here's a test I tried, with a sample of the document structure:

declareUpdate();

xdmp.documentInsert(
       '/test/tde.json',
       {
         content: {
           name:'Joe Parent',
           children: [
             {
               name: 'Bob Child'
             },
             {
               name: 'Sue Child'
             }
           ]
         }
       },
       {permissions : xdmp.defaultPermissions(),
        collections : ['test']})

cts.doc('/test/tde.json')

var tde = require("/MarkLogic/tde.xqy");
// Load the user template for user profile rows
var template = xdmp.toJSON(
{
  "template":{
    "context":"content",
    "collections": [
      "test"
    ],
      "triples":[
      {
        "subject": {
          "val": "xs:string(name)"
        },
        "predicate": {
          "val": "sem:iri('is-parent-of')"
        },
        "object": {
          "val": "xs:string(children/name)"
        }     
      }
    ]   
  }
}
);
//tde.validate([template]),
tde.templateInsert("/templates/test.tde", template);
tde.nodeDataExtract( 
  [cts.doc( '/test/tde.json' )]
)

但是,上面的方法抛出异常:

However, the above throws an Exception:

[javascript] TDE-EVALFAILED:tde.nodeDataExtract([cts.doc("/test/tde.json")]))-Eval for Object ='xs:string(children/name)'返回TDE-BADVALEXPRESSION :无效的val表达式:XDMP-CAST:(err:FORG0001)无效的强制转换:(fn:doc("/test/tde.json")/content/array-node("children")/object-node()[1 ]/text("name"),fn:doc("/test/tde.json")/content/array-node("children")/object-node()[2]/text("name"))投射为xs:string?

[javascript] TDE-EVALFAILED: tde.nodeDataExtract([cts.doc("/test/tde.json")]) -- Eval for Object='xs:string(children/name)' returns TDE-BADVALEXPRESSION: Invalid val expression: XDMP-CAST: (err:FORG0001) Invalid cast: (fn:doc("/test/tde.json")/content/array-node("children")/object-node()[1]/text("name"), fn:doc("/test/tde.json")/content/array-node("children")/object-node()[2]/text("name")) cast as xs:string?

将数组节点提取为三元组的正确语法是什么?

What is the proper syntax for extracting array nodes into a triple?

第二个相关问题:说我还想拥有"child1 is-sibling-of child2"形式的三元组.对于上面的示例,它将是"Bob Child is-sibling- Sue Child".正确的语法是什么?我什至不知道该如何开始.

2nd somewhat related question: say I also wanted to have triples of the form "child1 is-sibling-of child2". For the example above it would be "Bob Child is-sibling-of Sue Child". What would be the proper syntax for this? I'm not even sure how to begin with this one.

TDE甚至可以走到这里吗?还是以编程方式执行此操作更好?即在文档提取方面,直接在文档内部生成那些三元组?

Is TDE even the way to go here? Or is it better to do this programmatically? i.e. on document ingestion, generate those triples inside the document directly?

(如果相关,则使用的ML版本为9.)

(If it's relevant, the ML version being used is 9.)

推荐答案

更改模板的上下文以匹配每个子对象,然后从每个子对象而不是父对象投射三元组.

Change the context for your template to match on each of the children, and then project the triples from each child, rather than from the parent.

在上下文为children的情况下,对象val是xs:string(name),然后为了选择它的父对象,请将相对于子对象的主val的选择调整为xs:string(../../name).

With the context as children, the object val is xs:string(name) and then in order to select it's parent, adjust the selection of the subject val relative from the child to be xs:string(../../name).

var template = xdmp.toJSON(
{
  "template":{
    "context":"children",
    "collections": [
      "test"
    ],
      "triples":[
      {
        "subject": {
          "val": "xs:string(../../name)"
        },
        "predicate": {
          "val": "sem:iri('is-parent-of')"
        },
        "object": {
          "val": "xs:string(name)"
        }     
      }
    ]   
  }
}
);

这篇关于MarkLogic模板驱动的提取和三元组:处理数组节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆