Skip to content

Commit

Permalink
type fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Jun 30, 2016
1 parent 0407370 commit f857e9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions schema_salad/jsonld_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,16 @@ def salad_to_jsonld_context(j, schema_ctx):
return (context, g)

def fix_jsonld_ids(obj, ids):
# type: (Union[Dict[unicode, Any], List[Dict[unicode, Any]]], List[unicode]) -> None
if isinstance(obj, dict):
for i in ids:
if i in obj:
obj["@id"] = obj[i]
for v in obj.values():
fix_jsonld_ids(v, ids)
if isinstance(obj, list):
for i in obj:
fix_jsonld_ids(i, ids)
for entry in obj:
fix_jsonld_ids(entry, ids)

def makerdf(workflow, wf, ctx):
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType) -> Graph
Expand Down
10 changes: 7 additions & 3 deletions schema_salad/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


def printrdf(workflow, wf, ctx, sr):
# type: (str, Union[List, Dict[Any, Any], str, unicode], Dict[unicode, Any], str) -> None
# type: (str, Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Dict[unicode, Any], str) -> None
g = jsonld_context.makerdf(workflow, wf, ctx)
print(g.serialize(format=sr))

Expand Down Expand Up @@ -209,8 +209,12 @@ def main(argsl=None): # type: (List[str]) -> int

# Optionally convert the document to RDF
if args.print_rdf:
printrdf(args.document, document, schema_ctx, args.rdf_serializer)
return 0
if isinstance(document, (dict, list)):
printrdf(args.document, document, schema_ctx, args.rdf_serializer)
return 0
else:
print("Document must be a dictionary or list.")
return 1

if args.print_metadata:
print(json.dumps(doc_metadata, indent=4))
Expand Down

0 comments on commit f857e9d

Please sign in to comment.