-
Notifications
You must be signed in to change notification settings - Fork 128
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
no term-to-IRI expansion #130
Comments
The e = jsonld.expand( {'key':'value'} )
print(e) # [] The choices here are to make the input valid by either adding the context or use the # add context to input
ctx = {'key':'http://whatever.org/key'}
c = jsonld.compact( {'@context': ctx, 'key':'value'}, ctx )
print(c) # {'@context': {'key': 'http://whatever.org/key'}, 'key': 'value'}
# use expandContext option
ctx = {'key':'http://whatever.org/key'}
c = jsonld.compact( {'key':'value'}, ctx, {'expandContext': ctx} )
print(c) # {'@context': {'key': 'http://whatever.org/key'}, 'key': 'value'} The use case for compacting with the same context as the input is usually to convert full URLs to shorter terms. # use expandContext option
ctx1 = {'key':'http://whatever.org/key'}
ctx2 = {'altKeyName':'http://whatever.org/key'}
c = jsonld.compact( {'@context': ctx1, 'key':'value'}, ctx2 )
print(c) # {'@context': {'altKeyName': 'http://whatever.org/key'}, 'altKeyName': 'value'} |
Hi @davidlehn , thanks for your reply. I think I misunderstood the purpose of compacting. My target is to process the json-ld document to expand all the keys, remove the context, and be left with unambiguous (because the keys are IRIs) json (not LD). That seems to be the purpose of expansion, although expansion introduces all those unnecessary arrays Still, the compaction in the playground does exactly what I want (hence my confusion), by turning
into
which is the same as expansion, but without unnecessary arrays. This is not achievable with the PyLD API, I suppose. PS.: for the convenience of the reader, here is the expanded doc:
|
Perhaps you want to compact with an empty context Depending on your data and options used this might cause some undesired changes. Specifically related to arrays being used or not used (but there are other cases). There is a |
Thanks, using the empty context does what I want. I'll keep an eye for undesired side effects. |
Hi, I am new to JSON-LD so please excuse me if the question does not make much sense.
Consider the following:
In the first snippet,
key
is not matched with the term in the given context.Why do I have to write the full IRI (
'http://whatever.org/key'
) explicitly in the document ??That kind of voids one of the advantages of having a context, doesn't it?
I think this behaviour is not consistent with the JSON-LD playground, where the first example would result in a compacted document which includes the term
key:value
. See hereThe specs say "Term-to-IRI expansion occurs if the key matches a term defined within the active context", but that does not seem to be happening in PyLD (see example 11 of the specs)
Thank you
The text was updated successfully, but these errors were encountered: