Closed cjslep closed 5 years ago
Note that this has implications for downstream users of the ActivityStreams IRI in other @context
, such as this issue for Mastodon: https://github.com/tootsuite/mastodon/issues/10646
as I responded in the referenced issue, I don't believe your interpretation of the processing algorithm is correct. can you point to an existing JSON-LD validator that throws this error when interpreting as2 documents?
On Tue, Apr 30, 2019, 3:29 PM Cory J Slep notifications@github.com wrote:
Note that this has implications for downstream users of the ActivityStreams IRI in other @context, such as this issue for Mastodon: tootsuite/mastodon#10646 https://github.com/tootsuite/mastodon/issues/10646
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/w3c/activitystreams/issues/500#issuecomment-488084140, or mute the thread https://github.com/notifications/unsubscribe-auth/AABZCV3TSOOMQ2URUNAU3TDPTCM25ANCNFSM4HJPPUGA .
You've missed a key clause in the processing algorithm. Emphasis mine:
Then, for every other key in local context, we update the term definition in result. Since term definitions in a local context may themselves contain terms or compact IRIs, we may need to recurse. When doing so, we must ensure that there is no cyclical dependency, which is an error. After we have processed any term definition dependencies, we update the current term definition, which may be a keyword alias.
This immediately follows a discussion of the @context
key, so we're talking about "every other key than @context
". I interpret this as: all non-@context
keys must have no cyclical dependency.
I think it's important to note that the paragraph quoted is not the normative processing algorithm, which is a list of explicit steps in pseudocode. I would prefer to anchor our discussion in reference JSON-LD implementations to avoid rehashing the exact spec language, but if we really have to we should make sure to reference the actual algorithm.
@dariusk I did interpret it correctly. The emphasis you made is in reference to the preceding paragraph:
If context is a JSON object, we first update the base IRI, the vocabulary mapping, and the default language by processing three specific keywords: @base, @vocab, and @language. These are handled before any other keys in the local context because they affect how the other keys are processed. Please note that @base is ignored when processing remote contexts.
This means that in the @context
object (the very large {"@vocab" ... "shares"}
object) only the @base
, @vocab
, and @language
are processed first, and then the section I am quoting about forbidding recursion comes into play, which is handing every term definition outside of the above. Which includes the term "as"
.
And I knew the "non normative" bit would come back but let's be honest, the entire spec is a train wreck of "everything is labelled non normative" so that makes it a weak counterargument.
As for validators that fail, astool
has always failed on it (I use my own @context
OWL definition) and Google's Structured Data Testing Tool also chokes on it:
<script type="application/ld+json">
{"@context":"https://www.w3.org/ns/activitystreams","@type":"as:Person"}
</script>
Returns:
There was an invalid type in your JSON-LD.
Highlighting the @context
value.
googling astool
doesn't return any relevant results, mind elaborating? By "existing" validators I mean ones that you didn't make yourself.
My tests seem to show that Google's Structured Data Testing Tool doesn't accept string @context
values. (changing the activitystreams context out for https://web-payments.org/contexts/security-v1.jsonld
produces the same error) are you certain they claim full compatibility with JSON-LD?
For reference, the JSON-LD playground (using https://github.com/digitalbazaar/jsonld.js, which is a reference implementation of the JSON-LD processing algorithms), processes AS2 documents just fine.
This parses just fine:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "http://www.example.com",
"name": "Unlimited Ball Bearings Corp.",
"contactPoint": {
"@type": "ContactPoint",
"telephone": "+1-401-555-1212",
"contactType": "Customer service"
}
}
</script>
Which is from Understand how structured data works and includes a table titled "Google Search supports structured data in the following formats, unless documented otherwise:" which includes JSON-LD with an asterisk to indicate "Google recommends using JSON-LD for structured data whenever possible."
does it work with any context except schema.org?
@nightpool nearly this library (https://github.com/digitalbazaar/php-json-ld) we are using in Friendica to compact the input before parsing it. We don't have issues with compacting content from Mastodon.
You're making a classic mistake, common to many json-ld context examining folks: a namespace and a context are two different things... even if they might be located at the same URL!
"as": "https://www.w3.org/ns/activitystreams#",
DOES NOT define another context, and it isn't traversed in json-ld context parsing (really! I've written a json-ld parser before). Instead, this defines the namespace or alias in which the rest of the as:foo
terms are defined.
...but a namespace is a type of term in the JSON-LD spec (6.10).
And terms are recurred in the API processing spec.
And a compact IRI is:
A compact IRI has the form of prefix:suffix and is used as a way of expressing an IRI without needing to define separate term definitions for each IRI contained within a common vocabulary identified by prefix.
Which I take as meaning the common vocabulary (suffix) is recurred once at that prefix term definition so that when future uses of that prefix are processed (Ex: encountering as:Person
) do not define a separate term definition for that specific subtype (Continuing with ex: trying to define the term https://www.w3.org/ns/activitystreams#Person
).
I see the light now.
In my own tools I had modified the IRI Expansion algorithm to actually expand the IRI vocabulary. But actually the whole algorithm is actually skipped when behaving properly. For my use case, this skipping is actually problematic, and I had forgotten I had modified it. I am sorry.
The key is the setup in step 4 of Create Term Definition:
4) Remove any existing term definition for term in active context.
Later, when 13.2 is hit (due to the @id
transformation and term "as"
not equaling its value "https://www.w3.org/ns/activitystreams"
)
13.2) Otherwise, set the IRI mapping of definition to the result of using the IRI Expansion algorithm, passing active context, the value associated with the @id key for value, true for vocab, false for document relative, local context, and defined.
Going through the IRI Expansion algorithm steps:
"https://www.w3.org/ns/activitystreams"
)"https://www.w3.org/ns/activitystreams"
is not a key in the @context
)https://
.This means that this skipping happens for any defining of shorthand compact prefixes. Which for the Expansion/Compaction algorithms are fine. But for anything else trying to understand the documents beyond just shuffling around its textual representation, skipping fetching these is not tenable.
I guess the TL;DR lesson for me is that for text-level transformations (Expansion and Compaction), Context Processing & Co algorithms are sufficient. But for semantic understanding (such as native type code generation) Context Processing & Co algorithms are insufficient.
Since it appears I'm firmly alone in the latter camp, I am closing this bug.
yes, contexts themselves do not provide semantic understanding. they have to be coupled with a schema definition to do so.
On Wed, May 1, 2019 at 4:22 AM Cory J Slep notifications@github.com wrote:
I see the light now.
In my own tools I had modified the IRI Expansion algorithm https://www.w3.org/TR/json-ld-api/#create-term-definition to actually expand the IRI vocabulary. But actually the whole algorithm is actually skipped when behaving properly. For my use case, this skipping is actually problematic, and I had forgotten I had modified it. I am sorry.
The key is the setup in step 4 of Create Term Definition https://www.w3.org/TR/json-ld-api/#create-term-definition:
- Remove any existing term definition for term in active context.
Later, when 13.2 is hit (due to the @id transformation and term "as" not equaling its value "https://www.w3.org/ns/activitystreams")
13.2) Otherwise, set the IRI mapping of definition to the result of using the IRI Expansion algorithm, passing active context, the value associated with the @id https://github.com/id key for value, true for vocab, false for document relative, local context, and defined.
Going through the IRI Expansion algorithm steps:
- "If value is a keyword or null..." Nope! (value = " https://www.w3.org/ns/activitystreams")
- "If local context is not null, it contains a key that equals value, and..." Nope! ("https://www.w3.org/ns/activitystreams" is not a key in the @context)
- "If vocab is true and the active context has a term definition for value..." Nope! (Was deleted in step 4 of Create Term Definition)
- "If value contains a colon (:)" Yep! But it is immediately returned since it is matching on the https://.
This means that this skipping happens for any defining of shorthand compact prefixes. Which for the Expansion/Compaction algorithms are fine. But for anything else trying to understand the documents beyond just shuffling around its textual representation, skipping fetching these is not tenable.
I guess the TL;DR lesson for me is that for text-level transformations (Expansion and Compaction), Context Processing & Co algorithms are sufficient. But for semantic understanding (such as native type code generation) Context Processing & Co algorithms are insufficient.
Since it appears I'm firmly alone in the latter camp, I am closing this bug.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/w3c/activitystreams/issues/500#issuecomment-488233823, or mute the thread https://github.com/notifications/unsubscribe-auth/AABZCV577VI3F3U4GPTFHSTPTFHKZANCNFSM4HJPPUGA .
Please Indicate One:
Please Describe the Issue:
According to the JSON-LD Context Processing sections,
@context
definitions must not be recursive (emphasis mine):However, when fetching the
@context
located athttps://www.w3.org/ns/activitystreams
one obtains a@context
with a cyclical alias that breaks JSON-LD processing:The curl call:
Obtains (
//
comment is mine own indicating the cyclic nature):