From 0114153420d3a2d84305eda0759a4842ceae3144 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Wed, 8 Mar 2017 12:19:42 -0500 Subject: [PATCH] In vocab flag (#97) * Mark named items as "not in vocabulary" so that they can only be referenced by fully qualified URI and not by short name. Enables adding validated spec extensions without adding new keywords. --- schema_salad/jsonld_context.py | 21 ++++++++------------- schema_salad/metaschema/metaschema.yml | 6 ++++++ schema_salad/schema.py | 3 ++- setup.py | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/schema_salad/jsonld_context.py b/schema_salad/jsonld_context.py index 43a2a38e..a451769c 100755 --- a/schema_salad/jsonld_context.py +++ b/schema_salad/jsonld_context.py @@ -69,11 +69,6 @@ def pred(datatype, # type: Dict[str, Union[Dict, str]] "Dictionaries") else: raise Exception("jsonldPredicate must be a List of Dictionaries.") - # if not v: - # if field and "jsonldPrefix" in field: - # defaultBase = field["jsonldPrefix"] - # elif "jsonldPrefix" in datatype: - # defaultBase = datatype["jsonldPrefix"] ret = v or vee @@ -108,14 +103,14 @@ def process_type(t, # type: Dict[str, Any] g.add((classnode, RDF.type, RDFS.Class)) split = urlparse.urlsplit(recordname) - if "jsonldPrefix" in t: - predicate = "%s:%s" % (t["jsonldPrefix"], recordname) - elif split.scheme: - (ns, ln) = rdflib.namespace.split_uri(unicode(recordname)) - predicate = recordname - recordname = ln - else: - predicate = "%s:%s" % (defaultPrefix, recordname) + predicate = recordname + if t.get("inVocab", True): + if split.scheme: + (ns, ln) = rdflib.namespace.split_uri(unicode(recordname)) + predicate = recordname + recordname = ln + else: + predicate = "%s:%s" % (defaultPrefix, recordname) if context.get(recordname, predicate) != predicate: raise Exception("Predicate collision on '%s', '%s' != '%s'" % ( diff --git a/schema_salad/metaschema/metaschema.yml b/schema_salad/metaschema/metaschema.yml index a1515258..28b9e662 100644 --- a/schema_salad/metaschema/metaschema.yml +++ b/schema_salad/metaschema/metaschema.yml @@ -162,6 +162,12 @@ $graph: type: string jsonldPredicate: "@id" doc: "The identifier for this type" + - name: inVocab + type: boolean? + doc: | + By default or if "true", include the short name of this type in the + vocabulary (the keys of the JSON-LD context). If false, do not include + the short name in the vocabulary. - name: DocType diff --git a/schema_salad/schema.py b/schema_salad/schema.py index 62be6f13..f961fae6 100644 --- a/schema_salad/schema.py +++ b/schema_salad/schema.py @@ -399,7 +399,8 @@ def make_valid_avro(items, # type: Avro if isinstance(items, dict): items = copy.copy(items) if items.get("name"): - items["name"] = avro_name(items["name"]) + if items.get("inVocab", True): + items["name"] = avro_name(items["name"]) if "type" in items and items["type"] in ("https://w3id.org/cwl/salad#record", "https://w3id.org/cwl/salad#enum", "record", "enum"): if (hasattr(items, "get") and items.get("abstract")) or ("abstract" diff --git a/setup.py b/setup.py index 0b7a4994..486601ec 100755 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ extras_require = {} # TODO: to be removed when the above is added setup(name='schema-salad', - version='2.3', + version='2.4', description='Schema Annotations for Linked Avro Data (SALAD)', long_description=open(README).read(), author='Common workflow language working group',