25 lines
646 B
Python
25 lines
646 B
Python
|
|
||
|
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
|
||
|
|
||
|
|