26 lines
660 B
Python
26 lines
660 B
Python
|
|
import schemeld
|
|
import urllib
|
|
|
|
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
|
|
|
|
|