本文整理汇总了Python中ontology.Ontology.decode方法的典型用法代码示例。如果您正苦于以下问题:Python Ontology.decode方法的具体用法?Python Ontology.decode怎么用?Python Ontology.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ontology.Ontology
的用法示例。
在下文中一共展示了Ontology.decode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_mediainfo
# 需要导入模块: from ontology import Ontology [as 别名]
# 或者: from ontology.Ontology import decode [as 别名]
def _load_mediainfo(self):
command = self.env.initialize_command("mediainfo", self.log)
if command:
command.extend([u"--Language=raw", u"--Output=XML", u"--Full", self.ontology["path"]])
proc_mediainfo = Popen(command, stdout=PIPE, stderr=PIPE)
proc_grep = Popen([u"grep", u"-v", u"Cover_Data"], stdin=proc_mediainfo.stdout, stdout=PIPE)
raw_xml = proc_grep.communicate()[0]
# parse the DOM
element = ElementTree.fromstring(raw_xml)
if element is not None:
for node in element.findall(u"File/track"):
if "type" in node.attrib:
mtype = self.env.enumeration["mediainfo stream type"].search(node.attrib["type"])
if mtype is not None:
if mtype.node["namespace"]:
# initialize an ontology with the correct namespace
o = Ontology(self.env, mtype.node["namespace"])
# iterate over the properties and populate the ontology
for item in list(node):
text = item.text
# decode base64 encoded element
if "dt" in item.attrib and item.attrib["dt"] == "binary.base64":
text = base64.b64decode(text)
text = unicode(text, "utf8")
# set the concept on the ontology
o.decode(item.tag, text)
# fix the video encoder settings on video tracks
if mtype.key == "video":
self._fix_mediainfo_encoder_settings(o)
# add the ontology to the stream stack
self._execution["crawl"]["stream"].append(o)
elif mtype.key == "menu":
menu = Menu(self.env)
for item in list(node):
menu.add(Chapter.from_raw(item.tag, item.text, Chapter.MEDIAINFO))
menu.normalize()
if menu.valid:
self._execution["crawl"]["menu"].append(menu)
# Release resources held by the element, we no longer need it
element.clear()
示例2: parse
# 需要导入模块: from ontology import Ontology [as 别名]
# 或者: from ontology.Ontology import decode [as 别名]
def parse(self):
arguments = vars(self.parser.parse_args())
ontology = Ontology(self.env, self.node['namespace'])
for k,v in arguments.iteritems():
ontology.decode(k, v)
return ontology