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


Python Graph.transitive_subjects方法代码示例

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


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

示例1: __init__

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import transitive_subjects [as 别名]
class W5Metadata:
    def __init__(self, metadata_file_loc: str) -> None:
        logging.info("Reading fhir.ttl metatdata file")
        self.graph = Graph()
        self.graph.parse(metadata_file_loc, format='turtle')

    def as_sdo(self) -> List[W5Entry]:
        # Start with the root w5 node
        w5array = [W5Entry(self.graph, FHIR.w5, '', SDO.Thing)]

        # Cover all the immediate descendants
        fhir_subjs = set(self.graph.transitive_subjects(RDFS.subClassOf, FHIR.w5))
        w5array += [W5Entry(self.graph, e, 'w5:', FHIR.w5) for e in fhir_subjs if e != FHIR.w5]

        # Traverse all the different sorts of things that have a FHIR.w5 predicate
        # (Curiously, w5 is both a Class and a Property...)
        for defn in set(self.graph.objects(None, FHIR.w5)):     # Gives us a BNode
            for o in self.graph.objects(defn, RDF.type):        # Access the w5 types
                if o not in fhir_subjs:
                    fhir_subjs.add(o)
                    w5array.append(W5Entry(self.graph, o, 'w5:', None))

        return w5array
开发者ID:crDDI,项目名称:fhir_to_sdo,代码行数:25,代码来源:w5_metadata.py


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