本文整理汇总了Python中ontology.Ontology.decode_all方法的典型用法代码示例。如果您正苦于以下问题:Python Ontology.decode_all方法的具体用法?Python Ontology.decode_all怎么用?Python Ontology.decode_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ontology.Ontology
的用法示例。
在下文中一共展示了Ontology.decode_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from ontology import Ontology [as 别名]
# 或者: from ontology.Ontology import decode_all [as 别名]
def parse(self, query):
for source in query["sources"]:
try:
document = json.load(source)
except ValueError as e:
self.log.warning(u"Failed to decode JSON document %s", query["remote url"])
self.log.debug(u"Exception raised %s", unicode(e))
else:
if "process" in query["branch"]:
action = getattr(self, query["branch"]["process"], None)
if action is not None:
document = action(query, document)
else:
self.log.warning(u"Ignoring unknown process function %s", query["branch"]["process"])
if query["branch"]["query type"] == "lookup":
entry = {
"branch": query["branch"],
"record": {
u"head": {u"genealogy": query["parameter"].project("ns.service.genealogy")},
u"body": {u"original": document},
},
}
if "namespace" in query["branch"]:
# make a caonical node
entry["record"]["body"]["canonical"] = Ontology(self.env, entry["branch"]["namespace"])
entry["record"]["body"]["canonical"].decode_all(entry["record"]["body"]["original"], self.name)
# Copy indexed values from the canonical node to the genealogy
if "index" in entry["branch"]:
for index in entry["branch"]["index"]:
if index in entry["record"]["body"]["canonical"]:
entry["record"][u"head"][u"genealogy"][index] = entry["record"]["body"][
"canonical"
][index]
# Append the entry to the query result
query["entires"].append(entry)
elif query["branch"]["query type"] == "search":
for trigger in query["branch"]["resolve"]:
for element in document[query["branch"]["container"]]:
# Decode a reference
o = Ontology(self.env, trigger["namespace"])
o.decode_all(element, self.name)
# Make a URI and trigger a resolution
ref = o.project("ns.service.genealogy")
ref["language"]
uri = trigger["format"].format(**ref)
self.log.debug(u"Trigger %s resolution", uri)
self.resolver.resolve(uri)
示例2: parse
# 需要导入模块: from ontology import Ontology [as 别名]
# 或者: from ontology.Ontology import decode_all [as 别名]
def parse(self, query):
for source in query['sources']:
try:
document = json.load(source)
except ValueError as e:
self.log.warning(u'Failed to decode JSON document %s', query['remote url'])
self.log.debug(u'Exception raised %s', unicode(e))
else:
if 'process' in query['branch']:
# Preprocessing the entry.
# Method should return a document similar to normal itunes api calls
action = getattr(self, query['branch']['process'], None)
if action is not None:
document = action(document)
else:
self.log.warning(u'Ignoring unknown process function %s', query['branch']['process'])
if not document['resultCount'] > 0:
self.log.debug(u'No results found for query %s', query['remote url'])
else:
if query['branch']['query type'] == 'lookup':
for element in document['results']:
for product in query['branch']['produce']:
if satisfies(element, product['condition']):
entry = {
'branch':product['branch'],
'record':{
u'head':{ u'genealogy':Ontology(self.env, 'ns.service.genealogy'), },
u'body':{ u'original':element },
}
}
# make a caonical node
entry['record']['body']['canonical'] = Ontology(self.env, entry['branch']['namespace'])
entry['record']['body']['canonical'].decode_all(entry['record']['body']['original'], self.name)
# Copy indexed values from the canonical node to the genealogy
if 'index' in entry['branch']:
for index in entry['branch']['index']:
if index in entry['record']['body']['canonical']:
entry['record'][u'head'][u'genealogy'][index] = entry['record']['body']['canonical'][index]
# Only produce once for each element
query['entires'].append(entry)
break
elif query['branch']['query type'] == 'search':
for trigger in query['branch']['resolve']:
for element in document['results']:
if satisfies(element, trigger['condition']):
# Decode concepts from the element and populate the ontology
o = Ontology(self.env, trigger['namespace'])
o.decode_all(element, self.name)
# Make a URI and trigger a resolution
ref = o.project('ns.service.genealogy')
ref['language']
uri = trigger['format'].format(**ref)
self.log.debug(u'Trigger %s resolution', uri)
self.resolver.resolve(uri)