当前位置: 首页>>代码示例>>Python>>正文


Python Ontology.project方法代码示例

本文整理汇总了Python中ontology.Ontology.project方法的典型用法代码示例。如果您正苦于以下问题:Python Ontology.project方法的具体用法?Python Ontology.project怎么用?Python Ontology.project使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ontology.Ontology的用法示例。


在下文中一共展示了Ontology.project方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decode_resource_path

# 需要导入模块: from ontology import Ontology [as 别名]
# 或者: from ontology.Ontology import project [as 别名]
 def decode_resource_path(self, path):
     result = None
     if path:
         decoded = Ontology(self.env, 'ns.medium.resource.url.decode')
         decoded['directory'], decoded['file name'] = os.path.split(path)
         if 'file name' in decoded and 'directory' in decoded:
             
             # Normalize the directory
             # This will replace path framents with canonic values
             decoded['directory'] = self.normalize(decoded['directory'])
             
             # Check if the directory resides in a volume
             for volume in self.volume.element.values():
                 if os.path.commonprefix((volume.node['real'], decoded['directory'])) == volume.node['real']:
                     decoded['volume'] = volume.key
                     
             # If a UMID was encoded in the name, infer the home id and media kind
             # This will also trigger rule.medium.resource.filename.parse
             if 'umid' in decoded:
                 umid = Umid.decode(decoded['umid'])
                 if umid:
                     decoded['media kind'] = umid.media_kind
                     decoded['home id'] = umid.home_id
                     
             # Make the elements of the decoded onlology kernel elements of the result
             result = decoded.project('ns.medium.resource.location')
             for k,v in decoded.iteritems(): result[k] = v
             
             # set the host and domain
             result['host'] = self.host
             result['domain'] = self.domain
     return result
开发者ID:moonwatcher,项目名称:mp4pack.py,代码行数:34,代码来源:environment.py

示例2: parse

# 需要导入模块: from ontology import Ontology [as 别名]
# 或者: from ontology.Ontology import project [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)
开发者ID:moonwatcher,项目名称:mp4pack.py,代码行数:55,代码来源:tmdb.py

示例3: parse

# 需要导入模块: from ontology import Ontology [as 别名]
# 或者: from ontology.Ontology import project [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)
开发者ID:moonwatcher,项目名称:mp4pack.py,代码行数:64,代码来源:itunes.py


注:本文中的ontology.Ontology.project方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。