w3c / json-ld-framing

JSON-LD 1.1 Framing Specification
https://w3c.github.io/json-ld-framing/
Other
24 stars 20 forks source link

Reframing Relationships #73

Open AtesComp opened 4 years ago

AtesComp commented 4 years ago

I have the following data structure:

{
  "@context": {
    "ex": "http://example.org/",
    "exv": "http://example.org/vocab#",
    "exv:source": {"@type": "@id"},
    "exv:target": {"@type": "@id"}
  },
  "@graph": [
  { "@id": "ex:relationship-12345",
    "@type": "exv:Relationship",
    "exv:relationshipType": {"@id": "exv:created"},
    "exv:source": {
      "@id": "ex:actor-23456",
      "@type": "exv:Actor",
      "exv:description": "Some odd actor."
    },
    "exv:target": {
      "@id": "ex:event-34567",
      "@type": "exv:Event",
      "exv:description": "Some odd event."
    }
  }]
}

I would like to restructure it as:

{
  "@context": {
    "ex": "http://example.org/",
    "exv": "http://example.org/vocab#",
    "exv:source": {"@type": "@id"},
    "exv:target": {"@type": "@id"}
  },
  "@graph": [
  { "@id": "ex:actor-23456",
    "@type": "exv:Actor",
    "exv:description": "Some odd actor.",
    "exv:created": {
      "@id": "ex:event-34567",
      "@type": "exv:Event",
      "exv:description": "Some odd event."
    }
  },
  { "@id": "ex:relationship-12345",
    "@type": "exv:Relationship",
    "exv:source": "ex:actor-23456",
    "exv:relationshipType": {"@id": "exv:created"},
    "exv:target": "ex:event-34567"
  }]
}

In other words, the structure can be viewed as reifed data where:

exv:Relationship subclass of rdf:Statement
exv:source subproperty of rdf:subject
exv:relationshipType subproperty of rdf:predicate
exv:target subproperty of rdf:object

and I need to instantiate its triple: ex:actor-23456 -- exv:created --> ex:event-34567

Some framing issues are:

  1. Referencing the value of a property for later use, like the "exv:relationshipType" value.
  2. Using a referenced value as a property, like the value of "exv:relationshipType" used as the property of the "exv:source" value.
  3. Matching node patterns like "ex:relationship-" + variable info It seems wildcard matching is an all or nothing affair: match specific IRIs, everything {}, or nothing [], but not generic string matching. It would be useful for the frame matching to use regex patterns like "ex:relationship-.+". This is helpful when I don't have @type, but can create type based on the @id match.

Then, I can validate some pattern while framing. The framing could be:

{
  "@context": {
    "ex": "http://example.org/",
    "exv": "http://example.org/vocab#",
    "exv:source": {"@type": "@id"},
    "exv:target": {"@type": "@id"}
  },
  "@graph": [
  { "@requireAll": true,
    "@id": {"@regex": "ex:relationship-.+"},      <-- verifies a proper string match for a Relationship
    "@type": {"@default": "exv:Relationship"},    <-- new type if it doesn't exist
    "exv:relationshipType": {"@id": ?prop},       <-- reference for property
    "exv:source": {
      ?prop: {"@default": {"@id": ?obj}}          <-- new key-value pair
    },
    "exv:target": {"@id": ?obj},                  <-- reference for value, will order matter (target before source)?
  }]
}

to produce:

{
  "@context": {
    "ex": "http://example.org/",
    "exv": "http://example.org/vocab#",
    "exv:source": {"@type": "@id"},
    "exv:target": {"@type": "@id"}
  },
  "@graph": [
  { "@id": "ex:relationship-12345",
    "@type": "exv:Relationship",
    "exv:relationshipType": {"@id": "exv:created"},
    "exv:source": {
      "@id": "ex:actor-23456",
      "@type": "exv:Actor",
      "exv:description": "Some odd actor.",
      "exv:created": "ex:event-34567"             <------ new key-value pair 
    },
    "exv:target": {
      "@id": "ex:event-34567",
      "@type": "exv:Event",
      "exv:description": "Some odd event."
    }
  }]
}

Yeah, I hate it too. It looks ugly, but I currently don't see a way around it.

iherman commented 4 years ago

This issue was discussed in a meeting.