pyld icon indicating copy to clipboard operation
pyld copied to clipboard

Compacting failure with @vocab

Open Fak3 opened this issue 7 years ago • 1 comments

from pprint import pprint
ctx = {'@vocab': 'http://ex.org/#', 'path': {'@type': '@id'}}
data = {
    'http://ex.org/#maxCount': 1,
    'http://ex.org/#path': 'http://ex.org/#shortname'
}
pprint(jsonld.compact(data, ctx))
# {
#   '@context': {'@vocab': 'http://ex.org/#', 'path': {'@type': '@id'}},
#    # NOTE: maxCount: not declared in context => compacted OK
#   'maxCount': 1
#    # NOTE: path: declared in context => compacting FAILED
#   'http://ex.org/#path': 'http://ex.org/#shortname',
# }

Fak3 avatar Jun 24 '18 19:06 Fak3

One interesting doscovery: if i change 'http://ex.org/#shortname' to {'@id': 'http://ex.org/#shortname'} in the input data json, then property name compaction suddenly works, but the property value still not compacted:

{'@context': {'@vocab': 'http://ex.org/#', 'path': {'@type': '@id'}},
 '@id': '_:b0',
 'maxCount': 1,
 'path': 'http://ex.org/#shortname'}
# Note: `path` is compacted, but its value still isn't

Fak3 avatar Jun 25 '18 17:06 Fak3