本文整理匯總了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)