Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of IRIs and CURIEs as @context keys #43

Closed
gkellogg opened this issue Nov 29, 2011 · 17 comments
Closed

Use of IRIs and CURIEs as @context keys #43

gkellogg opened this issue Nov 29, 2011 · 17 comments

Comments

@gkellogg
Copy link
Member

In today's telco (http://json-ld.org/minutes/2011-11-29/) we discussed using using CURIEs in the key position within an @context object to describe @datatype coercion rules. This needs comes about because of the desire to fully utilize JSON-LD compact form in a generic RDF transformation without requiring a processor to automatically create term definitions. For example, consider the following expressed in Turtle:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://greggkellogg.net/foaf#me>a foaf:Person;
  foaf:name "Gregg Kellogg";
  foaf:homepage <http://greggkellogg.net/>;
  foaf:birthday "1957-02-27"^^xsd:date .

I would like to be able to take advantage of the foaf:birthday range datatype in a JSON-LD representation; if the processor must automatically create a prefix (say, "foaf_birthday") there is some risk with colliding with a definition in another context. The rule would be that if the key is an NCName, it is taken as a term definition, otherwise normal IRI expansion rules apply. Allowing a CURIE to be used in the key position, could allow something such as the following:

{
  "@context": {
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "foaf": "http://xmlns.com/foaf/0.1/",
    "foaf:birthday": {"@coerce": "xsd:date"}
  },
  "@subject": "http://greggkellogg.net/foaf#me",
  "@type": "foaf:Person",
  "foaf:name": "Gregg Kellogg",
  "foaf:birthday": "1957-02-27",
  "foaf:homepage": "http://greggkellogg.net/"
}

This was also briefly discussed on the mailing list:

http://lists.w3.org/Archives/Public/public-linked-json/2011Nov/0041.html

@lanthaler
Copy link
Member

There are basically four cases to support:

1) "prefix:suffix": { "@id": "set-to-something" }

2) "prefix:suffix": {  }

3) "unknownprefix:suffix": { "@id": "set-to-something" }

4) "unknownprefix:suffix": {  }

Case 1 to 3 could be supported by adding an additional processing step that explictly sets @id for case 2.

The problem lies in case 4 where "calculating" @id is impossible since the prefix is unknown.. But that's more or less the same case as defining a term without setting @id.

So I think, if we add an additional processing step which assures that @id is set (where possible), we could just threat this as a term that contains a colon. Of course this then has to take precedence over prefix expansion.

@gkellogg
Copy link
Member Author

I think that 1) would ben an error if prefix:suffix and set-to-something did not resolve to the same IRI; seems like this could be used maliciously.

  1. represents the typical case, where the {} would be used to add "@type" or "@list" properties.

  2. is interesting, since it could imply that a prefix definition could be created by subtracting suffix from set-to-something, but seems like a bad idea to me.

  3. looks like an error. Otherwise, it looks like IRI resolution needs to first look to see if the entire string is defined, and otherwise split on ':' to see if the prefix is defined; seems like an extra step that is not in the spirit of CURIEs anyway.

@iherman
Copy link
Contributor

iherman commented Jan 11, 2012

Here is how I hit this. I do an RDFa->JSON-LD conversion (via RDFLib as an intermediate RDF toolkit), and I would like the beautify the output. If the user in RDFa does

and there are no prefixes (or vocab) defined in the original source.

A simple json-ld is of course

{
"http://www.ex.org/prop" { "@id" : "http://a.b.c" } ,
"http://www.ex.org/prop" { "@id" : "http://p.q.r" }
}

but, to make it cleaner, it would be nice if I could say

{
"@context" {
"http://www.ex.org/prop" : { "@type" : "@id" }
}
"http://www.ex.org/prop" : "http://a.b.c" ,
"http://www.ex.org/prop" : "http://p.q.r"
}

Which would require to have the URI as a key.

Bottom line: I am very much in favour allowing this.

@gkellogg
Copy link
Member Author

Some of the things we need to consider:

{ "@context":
  "vocab": "http://example.com/#",
  "term": {"@id": "vocab:prop", "@list": true},
  "term2": {"@id": "vocab:prop", "@type": "@id"},
  "vocab:prop": { "@type": "xsd:date"},
  "http://example.com/#prop": { "@type": "xsd:dateTime"}
}

These are all perfectly legal ways of identifying different coercion rules for the same
property IRI. The implication is that coercion should first be attempted using the
lexical value of a property key, followed by looking for a fully expanded IRI form of the
property. I would expect the following interpretations:

{"term": ["a"]}

would generate Turtle

[<http:/example.com/#prop> ("a"^^xsd:dateTime)],

because term has a list coercion but no datatype coercion, but http://example.com/#prop
does have a datatype coercion, which is the last specified for a key mapping to
that full IRI, so it is used as for datatype coercion.

{"term2": ["a"]}

would generate Turtle

[<http:/example.com/#prop> (<a>) ],

because the @list coercion for term is promoted to the full IRI, but the datatype
for term2 is explicitly set as @id.

{"vocab:prop": "a"}

would generate Turtle

[<http://example.com/#prop> "a"^^xsd:date]

because the datatype coercion rule is set for vocab:prop explicitly.

{"http://example.com/#prop": ["a"]}

would generate Turtle

[<http://example.com/#prop> ("a"^^xsd:dateTime)]

because list coercion from term is promoted to the full IRI, and the data type is
explicitly defined as xsd:dateTime.

@iherman
Copy link
Contributor

iherman commented Jan 12, 2012

Hi Gregg,

What you say is fine with me... But it might be possible to simplify things somewhat if the 'right hand side' of the context entries would allow full uri-s only. Though using CURIE-s like in your example can be worked out as you did now, that seems to be an extra complication. The keys are those terms that do appear in the rest of the json-ld file, so allowing anything there that is allowed elsewhere is fine; the right hand side is for the authors of the context, that can be much more restrictive.

Also, you say 'last specified for a key mapping': afaik, there is no order within a json object by default, is there?

Ivan

On Jan 12, 2012, at 02:54 , Gregg Kellogg wrote:

Some of the things we need to consider:

{ "@context":
"vocab": "http://example.com/#",
"term": {"@id": "vocab:prop", "@list": true},
"term2": {"@id": "vocab:prop", "@type": "@id"},
"vocab:prop": { "@type": "xsd:date"},
"http://example.com/#prop": { "@type": "xsd:dateTime"}
}

These are all perfectly legal ways of identifying different coercion rules for the same
property IRI. The implication is that coercion should first be attempted using the
lexical value of a property key, followed by looking for a fully expanded IRI form of the
property. I would expect the following interpretations:

{"term": ["a"]}

would generate Turtle

[http:/example.com/#prop ("a"^^xsd:dateTime)],

because term has a list coercion but no datatype coercion, but http://example.com/#prop
does have a datatype coercion, which is the last specified for a key mapping to
that full IRI, so it is used as for datatype coercion.

{"term2": ["a"]}

would generate Turtle

[http:/example.com/#prop () ],

because the @list coercion for term is promoted to the full IRI, but the datatype
for term2 is explicitly set as @id.

{"vocab:prop": "a"}

would generate Turtle

[http://example.com/#prop "a"^^xsd:date]

because the datatype coercion rule is set for vocab:prop explicitly.

{"http://example.com/#prop": ["a"]}

would generate Turtle

[http://example.com/#prop ("a"^^xsd:dateTime)]

because list coercion from term is promoted to the full IRI, and the data type is
explicitly defined as xsd:dateTime.


Reply to this email directly or view it on GitHub:
#43 (comment)


Ivan Herman, W3C Semantic Web Activity Lead
Home: http://www.w3.org/People/Ivan/
mobile: +31-641044153
FOAF: http://www.ivan-herman.net/foaf.rdf

@gkellogg
Copy link
Member Author

We had previously allowed the use of CURIEs in the RHS, but here I was really just using them as a short-hand; mostly to allow @type: xsd:date, for example. The point was that different terms or other things could map to the same IRI but have different coercion rules.

The potential for overlapping meanings is an issue that I wanted to illustrate.

Maintaining order of keys within an object may be a problem for some implementations, and this is a difficult issue. It may be that coercion must apply only to the lexical form of the key, and not the IRI to which it maps, but I do it differently, and I believe that there may be some problem that I don't recall the details of right now if we don't make sure that the coercion applies to other representations of the same IRI as well.

@lanthaler
Copy link
Member

I think the easiest (and after having spent quite some thoughts on this) also the cleanest solution is to use keys in the context as they are specified without doing any expansion. That means that in an JSON-LD document type coercion just looks up the exact name of the property that is being coerced. This way there are no name clashes and different coercions for different terms even if they map to the same IRI would work.

I don't know if it's possible to understand what I wrote above so let me use your example Gregg:

{ "@context": {
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "vocab": "http://example.com/#",
    "term": {"@id": "vocab:prop", "@list": true},
    "term2": {"@id": "vocab:prop", "@type": "@id"},
    "vocab:prop": { "@type": "xsd:date"},
    "http://example.com/#prop": { "@type": "xsd:dateTime"}
  }
}

Let's assume there is a property with the key "term2" in the documents. The parser would only look up "term2" in the active context. If the property's key is "vocab:prop", only that would be looked up in the context, if no "@id" is found (it is arguable if we wanna allow that), the normal prefix expansion algorithm is used.

@lanthaler
Copy link
Member

2012-01-17 telecon outcomes:

RESOLVED: When expanding JSON-LD keys outside of the @context, perform a direct comparison on the @context keys first, then run the CURIE expansion algorithm using the @context keys.

RESOLVED: If a CURIE as a key in the @context is not bound to an @id, the @id is determined by expanding the key as a CURIE.

RESOLVED: The type coercion algorithm only checks for equality in the context when attempting to find a type coercion rule.

@iherman
Copy link
Contributor

iherman commented Jan 17, 2012

Just to check. My way of interpreting these resolution is that full URI can appear as a key in @context, ie,

@context {
"http://example.org/pred" : { @type : @id }
}

is conform to JSON-LD. Is that correct?

Ivan

On Jan 17, 2012, at 16:35 , Markus Lanthaler wrote:

RESOLVED: When expanding JSON-LD keys outside of the @context, perform a direct comparison on the @context keys first, then run the CURIE expansion algorithm using the @context keys.

RESOLVED: If a CURIE as a key in the @context is not bound to an @id, the @id is determined by expanding the key as a CURIE.


Reply to this email directly or view it on GitHub:
#43 (comment)


Ivan Herman
Bankrashof 108
1183NW Amstelveen
The Netherlands
http://www.ivan-herman.net

@lanthaler
Copy link
Member

Yes Ivan, that's correct. But the specified @type will just be used for properties in the document whose key equals to "http://example.org/pred". It won't apply to a property whose key is, e.g., "ex:pred" that happens to expand to that IRI.

@iherman
Copy link
Contributor

iherman commented Jan 18, 2012

yes, I understand!

Ivan


Reply to this email directly or view it on GitHub:
#43 (comment)

@gkellogg
Copy link
Member Author

Allowing a key which is a CURIE (or worse yet, an IRI) to have an @id which specifies something different to what the key would otherwise resolve to really seems like a bad idea. For example:

{ "http://xmlns.com/foaf/0.1/Person": {"@id": "http://schema.org/Person"}}

Also, allowing a CURIE definition, where the prefix portion is not, itself, defined seems like it could either lead to the use of a syntax without really understanding what it means, or that it could also be abused.

I would suggest that the use of @id in @context where the key is either a CURIE or an IRI is either illegal, or MUST resolve to the identical IRI as the expanded form of the key.

@iherman
Copy link
Contributor

iherman commented Jan 24, 2012

Note that my use case was very different:

{ "http://xmlns.com/foaf/0.1/Person": {"@type" : "@id" }}

I do not thank that would be affected.

Ivan


Reply to this email directly or view it on GitHub:
#43 (comment)


Ivan Herman
Bankrashof 108
1183NW Amstelveen
The Netherlands
http://www.ivan-herman.net

@lanthaler
Copy link
Member

Gregg,

in the last telecon we decided to not disallow the use of @id for keys that are CURIEs or IRIs since we didn't see a need for that. Nevertheless we agreed that it would be a bad practice that we should discourage by adding a note to the spec.

@gkellogg
Copy link
Member Author

So, one significant complication by looking up term coercions vs. IRI coercions is when compacting IRIs. IRI compaction is now more complicated, as there may be multiple terms associated with an absolute IRI. We now must take into consideration the datatypes of values associated with a specific key to choose between multiple possible term mappings.

Are we making this to complex? Before, the algorithms specified coercion based on expanded IRIs, not unexpanded terms, CURIEs or IRIs.

For example, consider the following:

{
  "@context":
  {
    "a": {"@id": "http://example.com/foo", "@type": "xsd:integer"},
    "b": {"@id": "http://example.com/foo"}
  },
  "a": "1",
  "b": "1"
}

I've not declared the following RDF:

[ <http://example.com/foo> 1, "1" ] .

When expanded, I get the following:

{
  "http://example.com/foo": {"@literal": "1", "@type": "http://www.w3.org/2001/XMLSchema#integer"},
  "http://example.com/foo": "1"
}

Of course, this is illegal, so expansion rules need to consider that multiple keys may need to be resolved:

{
  "http://example.com/foo":
  [
    {"@literal": "1", "@type": "http://www.w3.org/2001/XMLSchema#integer"},
    "1"
  ]
}

Now when we go to compact, it becomes even more difficult. Do we use two different keys and re-split this? Looking up the appropriate term becomes much more complicated.

This problem would be simplified if we restricted a context from having at most on mapping from a term/CURIE/IRI to an IRI, allowing a reverse map. As the context algorithm is specified now, this is pretty much what happens:

It is also used to maintain coercion mappings from IRIs associated with terms to datatypes, and list mappings for IRIs associated with terms

This describes that the mapping is from IRIs, not terms. I suggest we keep this algorithm and restrict the context to have only a single mapping from term to IRI and no mapping for CURIEs or IRIs to IRI, depending on the prefix being a term.

Still, even as it is now, a user could specify two terms mapping to the same IRI, in which case the one which is used for compaction becomes undefined, as is any coercion rule used.

gkellogg added a commit that referenced this issue Jan 27, 2012
… IRI expansion rules to look for full match before prefix match.

This addresses issue #43 (not closed, because of ongoing concerns about multiple mappings to the same IRI and the effect on compression).
@lanthaler
Copy link
Member

This issue was resolved.

2012-01-17 telecon outcomes:

RESOLVED: When expanding JSON-LD keys outside of the @context, perform a direct comparison on the @context keys first, then run the CURIE expansion algorithm using the @context keys.

RESOLVED: If a CURIE as a key in the @context is not bound to an @id, the @id is determined by expanding the key as a CURIE.

RESOLVED: The type coercion algorithm only checks for equality in the context when attempting to find a type coercion rule.

Issue #74 was created to follow-up the discussion about the issues Gregg raised.

@lanthaler
Copy link
Member

Added example showing use of compact IRIs in contexts in c2bea5f

I'll leave the issue open as long as the API spec hasn't been updated.

gkellogg added a commit that referenced this issue Mar 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants