zazuko / rdf-validate-shacl

Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.
MIT License
98 stars 13 forks source link

Function which extracts a JSON based on a SHACL definition #1

Closed l00mi closed 3 years ago

l00mi commented 4 years ago

Loosly based on UC42.

Create a function which takes

  1. An entry point (root node) term inside a dataset.
  2. SHACL description provided with a term inside a dataset. and outputs a JSON structure described by the SHACL description.

.asJson(rootTerm, shaclTerm, shaclDataset)

martinmaillard commented 4 years ago

Would it be possible to provide sample data (turtle), sample shapes (turtle) and the output that you would expect? That would help me a lot.

martinmaillard commented 4 years ago

@l00mi Reminder ;)

l00mi commented 4 years ago

The following example is not an attempt to find all edge cases but is a starting point.

It shows the input data (taken from https://www.w3.org/TR/vcard-rdf/) and an example of the Output. I do not know how the SHACL would need to look like to be able to get to this transformation, @bergos do you have any idea on that?

Input Data

@base <http://example.com/me/> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
<corky> a vcard:Individual;
vcard:fn "Corky Crystal"; vcard:hasAddress <corky#address>; vcard:hasTelephone <corky#telephone>; vcard:nickname "Corks".
<corky#telephone> a vcard:Home, a vcard:Voice; vcard:hasValue "tel:+61755555555".
<corky#address> a vcard:Home; vcard:country-name "Australia"; vcard:locality "WonderCity"; vcard:postal-code "5555"; vcard:street-address "111 Lake Drive".

Output

{
    "address": {
        "location_link": [{
            "location": {
                "city": {
                    "locality": "WonderCity",
                    "postal-code": "5555",
                    "country-name": "Australia"
                },
                "street-address": "111 Lake Drive"
            }
        }]
    },
    "aka": {
        "fn": "Corky Crystal",
        "nickname": "Corks"
    }
}

Both structures visualised, left the graph, right the output.

Screenshot 2020-03-24 at 17 29 39

For context, the goal of this transformation was to use this template:

  <div>
      <span class="glyphicon glyphicon-envelope" style="font-size:48px; float:left; margin: 0 15px 0 10px;"></span>
      <div>
      <b>{{address.aka.fn}}</b> [aka {{address.aka.nickname}}]<br>
      {{address.location_link.0.location.street-address}}<br>
      {{address.location_link.0.location.city.locality}} {{address.location_link.0.location.city.postal-code}}
      <span style="text-transform:uppercase;">{{address.location_link.0.location.city.country-name}}</span>
      </div>
  </div>
Screenshot 2020-03-24 at 17 52 25
martinmaillard commented 3 years ago

I'll close this, as it does not really fit the scope of this library. By the way, I already have some version of this function in another project ;)