json-ld/json-ld.org — Issue #74: Detail how IRI conflicts are resolved when compacting/expanding
Author: msporny
Created: 2012-01-31 15:31:01+00:00
State: open

From Gregg:

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:

[ 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.