[Python-modules-commits] [python-pyld] 71/276: Allow null @id mappings, use null mapping in compact IRI.
Wolfgang Borgert
debacle at moszumanska.debian.org
Wed Oct 8 23:47:55 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to branch master
in repository python-pyld.
commit e05e298e6683b4985cab2d5c3700df2611c2eeb8
Author: Dave Longley <dlongley at digitalbazaar.com>
Date: Fri Apr 27 17:28:57 2012 -0400
Allow null @id mappings, use null mapping in compact IRI.
---
lib/pyld/jsonld.py | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index e6784af..12844e6 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -712,8 +712,7 @@ class JsonLdProcessor:
if _is_subject_reference(element):
type = JsonLdProcessor.getContextValue(ctx, property, '@type')
if type == '@id' or property == '@graph':
- element = self._compactIri(ctx, element['@id'])
- return element
+ return self._compactIri(ctx, element['@id'])
# recursively process element keys
rval = {}
@@ -741,7 +740,8 @@ class JsonLdProcessor:
# preserve empty arrays
if len(value) == 0:
prop = self._compactIri(ctx, key)
- JsonLdProcessor.addValue(rval, prop, [], True)
+ if prop is not None:
+ JsonLdProcessor.addValue(rval, prop, [], True)
# recusively process array values
for v in value:
@@ -750,6 +750,10 @@ class JsonLdProcessor:
# compact property
prop = self._compactIri(ctx, key, v)
+ # skip null properties
+ if prop is None:
+ continue
+
# remove @list for recursion (will re-add if necessary)
if is_list:
v = v['@list']
@@ -2052,6 +2056,10 @@ class JsonLdProcessor:
# no matching terms, use IRI
if len(terms) == 0:
+ # return None if a null mapping exists
+ if iri in ctx['mappings'] and ctx['mappings'][iri]['@id'] is None:
+ return None
+ # use iri
return iri
# return shortest and lexicographically-least term
@@ -2121,7 +2129,7 @@ class JsonLdProcessor:
kw = active_ctx['mappings'][key]['@id']
if _is_keyword(kw):
active_ctx['keywords'][kw].remove(key)
- del active_ctx['mappings'][key]
+ active_ctx['mappings'][key] = {'@id': None}
defined[key] = True
return
@@ -2138,7 +2146,7 @@ class JsonLdProcessor:
if key not in aliases:
aliases.append(key)
aliases.sort(key=cmp_to_key(_compare_shortest_least))
- else:
+ elif value is not None:
# expand value to a full IRI
value = self._expandContextIri(
active_ctx, ctx, value, base, defined)
@@ -2217,8 +2225,10 @@ class JsonLdProcessor:
# add @language to mapping
mapping['@language'] = language
- # merge onto parent mapping if one exists for a prefix
- if prefix is not None and prefix in active_ctx['mappings']:
+ # if not a null mapping, merge onto parent mapping if one exists for
+ # a prefix
+ if (mapping['@id'] is not None and prefix is not None and
+ prefix in active_ctx['mappings']):
mapping = dict(
list(active_ctx['mappings'][prefix].items()) +
list(mapping.items()))
@@ -2247,8 +2257,8 @@ class JsonLdProcessor:
# recurse if value is a term
if value in active_ctx['mappings']:
id = active_ctx['mappings'][value]['@id']
- # value is already an absolute IRI
- if value == id:
+ # value is already an absolute IRI or id is a null mapping
+ if value == id or id is None:
return value
return self._expandContextIri(active_ctx, ctx, id, base, defined)
@@ -2268,8 +2278,9 @@ class JsonLdProcessor:
# recurse if prefix is defined
if prefix in active_ctx['mappings']:
id = active_ctx['mappings'][prefix]['@id']
- return self._expandContextIri(
- active_ctx, ctx, id, base, defined) + suffix
+ if id is not None:
+ return self._expandContextIri(
+ active_ctx, ctx, id, base, defined) + suffix
# consider value an absolute IRI
return value
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pyld.git
More information about the Python-modules-commits
mailing list