當前位置: 首頁>>代碼示例>>Python>>正文


Python Ontology.decode方法代碼示例

本文整理匯總了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()
開發者ID:moonwatcher,項目名稱:mp4pack.py,代碼行數:50,代碼來源:crawler.py

示例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
開發者ID:moonwatcher,項目名稱:mp4pack.py,代碼行數:8,代碼來源:environment.py


注:本文中的ontology.Ontology.decode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。