Skip to content

Lowering Grounding Examples

ThibaultGerrier edited this page May 27, 2020 · 3 revisions

Currently I have the custom spp function split (not like described in the mindlab deliverable) into one that returns only one item and the other that returns a list of items (spp vs sppList). I'm not sure if this will stay like this. In this document they are split.

Grounding Mapping Examples

input action:

{
  "@context": {
    "@vocab": "http://schema.org/"
  },
  "@type": "Action",
  "actionStatus": "http://schema.org/ActiveActionStatus",
  "agent": {
    "@type": "Person",
    "name": "John"
  },
  "object": [
    {
      "@type": "Place",
      "name": "top",
      "description": "its nice"
    },
    {
      "@type": "Place",
      "name": "bot",
      "description": "its bad"
    }
  ]
}

wanted output:

1: simple string

hello John

2: json

{
  "name": "John",
  "val": [
    {
      "name": "top",
      "desc": "its nice"
    },
    {
      "name": "top",
      "description": "its bad"
    }
  ]
}

3: xml

<root>
    <name>John</name>
    <val name="top">its nice</val>
    <val name="bot">its bad</val>
</root>

Handlebars

1:

hello {{ spp ":agent/:name" }}

2:

json bit tricky with arrays, might add a helper function later

{
  "name": "{{ spp ":agent/:name" }}",
  "val": [
  {{#each (sppList ":object") }}
    {
      "name": "{{ spp this ":name"}}",
      "desc": "{{ spp this ":description"}}"
    }{{#unless @last}},{{/unless}}
  {{/each}}
  ]
}

3:

<root>
    <name>{{ spp ":agent/:name" }}</name>
    {{#each (sppList ":object") }}
    <val name="{{ spp this ":name" }}">{{ spp this ":description" }}</val>
  {{/each}}    
</root>

XQuery

1:

"hello " || fn:spp(":agent/:name")

2:

map {
    "name": fn:spp(":agent/:name"),
    "val": array { 
        fn:for-each(fn:sppList(":object"), function($id){
            map {
                "name": fn:spp($id, ":name"),
                "desc": fn:spp($id, ":description")
            }
        })
    }
}

3:

<root>
    <name>{fn:spp(":agent/:name")}</name>
    {fn:for-each(fn:sppList(":object"), function($id){
        <val name="{fn:spp($id, ":name")}">{fn:spp($id, ":description")}</val>
    })}
</root>

JavaScript

1:

`Hello ${spp(':agent/:name')}`

2:

({
    "name": spp(":agent/:name"),
    "val": sppList(":object").map(id => ({
        "name": spp(id, ":name"),
        "desc": spp(id, ":description")
    }))
})

3:

`<root>
    <name>${spp(":agent/:name")}</name>
    ${sppList(":object").map(id =>
        `<val name="${spp(id, ":name")}">${spp(id, ":description")}</val>`
    ).join('')}
</root>`