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


Python Graph.transitive_objects方法代码示例

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


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

示例1: handle

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import transitive_objects [as 别名]
    def handle(self, *args, **options):
        from rdflib.graph import Graph
        from rdflib import RDFS, RDF, OWL
        from rdflib.term import URIRef, BNode, Literal
        import yaml

        OboDefinition = URIRef('http://purl.obolibrary.org/obo/IAO_0000115')
        part_of_some = URIRef('http://purl.obolibrary.org/obo/BFO_0000050_some')
        Synonym = URIRef(u'http://www.geneontology.org/formats/oboInOwl#hasSynonym')

        g = Graph()
        g.parse(args[1], 'xml')

        Model = MuscleOwl if args[0] == 'm' else BehaviorOwl

        # first pass, add the things
        for subject in nonblankthings(g, g.subjects()):
            slabel = g.label(subject)
            m = get_model_instance(Model, unicode(subject))
            m.uri = unicode(subject)
            m.label = unicode(slabel)

            m.rdfs_is_class = (subject, RDF.type, OWL.Class) in g
            m.obo_definition = unicode(g.value(subject, OboDefinition, None))
            m.rdfs_comment = unicode(g.value(subject, RDFS.comment, None))
            synonyms = [unicode(syn) for syn in g.objects(subject, Synonym)]
            if len(synonyms):
                m.synonyms_comma_separated = ", ".join(synonyms)
            else:
                m.synonyms_comma_separated = None

            m.save()

        # second pass, add the relationships
        for subject in nonblankthings(g, g.subjects()):
            slabel = g.label(subject)
            m = Model.objects.get(uri=unicode(subject))

            m.rdfs_subClassOf_ancestors.clear()
            # add all super-classes to m.rdfs_subClassOf_ancestors
            for obj in nonblankthings(g, g.transitive_objects(subject, RDFS.subClassOf)):
                if obj != subject:
                    a = Model.objects.get(uri=unicode(obj))
                    m.rdfs_subClassOf_ancestors.add(a)

            m.bfo_part_of_some.clear()
            # add all things that this thing is part of to m.bfo_part_of_some
            for obj in nonblankthings(g, g.objects(subject, part_of_some)):
                if obj != subject:
                    a = Model.objects.get(uri=unicode(obj))
                    m.bfo_part_of_some.add(a)

            # add only direct super-classes to m.rdfs_subClassOf
            #for obj in nonblankthings(g, g.objects(subject, RDFS.subClassOf)):
            #    if obj != subject:
            #        a = Model.objects.get(uri=unicode(obj))
            #        m.rdfs_subClassOf.add(a)

            m.save()
开发者ID:NESCent,项目名称:feedingdb,代码行数:61,代码来源:loadowl.py


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