This is a follow-up to my question here: https://stackoverflow.com/questions/47449002/marklogic-template-driven-extraction-and-triples-dealing-with-array-nodes/47459250#47459250
So let’s say I have a number of documents structured like this:
declareUpdate();
xdmp.documentInsert(
'/test/tde.json',
{
content: {
name:'Joe Parent',
children: [
{
name: 'Bob Child'
},
{
name: 'Sue Child'
},
{
name: 'Guy Child'
}
]
}
},
{permissions : xdmp.defaultPermissions(),
collections : ['test']})
I want to define a template that would extract triples from these documents defining sibling relationships between the children. For the above example, I would want to extract the following triples (the relationship is two-way):
Bob Child sibling-of Sue Child
Bob Child sibling-of Guy Child
Sue Child sibling-of Bob Child
Sue Child sibling-of Guy Child
Guy Child sibling-of Bob Child
Guy Child sibling-of Sue Child
How can i set up my template to accomplish this?
Thanks!
I converted JSON to XML, wrote XSLT transformation to get XML triples. Later XML can be transformed back to JSON if needed.
XSLT transformation:
XQuery code that converts JSON to XML and makes transformation:
I don’t know of a way to do that, but it seems like any “sibling-of” relationship is equivalent to two “child-of” relationships. Could you do something like this instead?
Or if you’re in a position to use inference rules, you can build a rule that defines “sibling-of” like that. Then although the template doesn’t generate “sibling-of” directly, the triples are still tied to the ingested document in the same way as they would be, by virtue of the template generating the “is-parent-of” triples.