def get_thingpedia(input_words, workdir, snapshot):
thingpedia_url = os.getenv('THINGPEDIA_URL', 'https://thingpedia.stanford.edu/thingpedia')
output = dict()
with urllib.request.urlopen(thingpedia_url + '/api/snapshot/' + str(snapshot) + '?meta=1', context=ssl_context) as res:
output['devices'] = json.load(res)['data']
for device in output['devices']:
if device['kind_type'] == 'global':
continue
if device['kind_canonical']:
add_words(input_words, device['kind_canonical'])
else:
print('WARNING: missing canonical for tt-device:%s' % (device['kind'],))
for function_type in ('triggers', 'queries', 'actions'):
for function_name, function in device[function_type].items():
if not function['canonical']:
print('WARNING: missing canonical for tt:%s.%s' % (device['kind'], function_name))
else:
add_words(input_words, function['canonical'])
for argname, argcanonical in zip(function['args'], function['argcanonicals']):
if argcanonical:
add_words(input_words, argcanonical)
else:
add_words(input_words, clean(argname))
for argtype in function['schema']:
if not argtype.startswith('Enum('):
continue
enum_entries = argtype[len('Enum('):-1].split(',')
for enum_value in enum_entries:
add_words(input_words, clean(enum_value))
with urllib.request.urlopen(thingpedia_url + '/api/entities?snapshot=' + str(snapshot), context=ssl_context) as res:
output['entities'] = json.load(res)['data']
for entity in output['entities']:
if entity['is_well_known'] == 1:
continue
add_words(input_words, tokenize(entity['name']))
with open(os.path.join(workdir, 'thingpedia.json'), 'w') as fp:
json.dump(output, fp, indent=2)
prepare.py 文件源码
python
阅读 30
收藏 0
点赞 0
评论 0
评论列表
文章目录