1
0
datagraph/parse.py

25 lines
646 B
Python
Raw Normal View History

import schemeld
def determine_concepts_internal(json, context, outputs):
if isinstance(json, list):
for m in json:
determine_concepts_internal(m, context, outputs)
return
assert isinstance(json, dict), type(json)
context = urllib.parse.urlparse(json.get('@context', context))
assert context.netloc == 'schema.org'
if '@graph' in json:
determine_concepts_internal(json['@graph'], context, outputs)
else:
outputs.append(schemeld.Concept(context, json))
def determine_concepts(json):
concepts = []
determine_concepts_internal(json, '', concepts)
return concepts