本文整理汇总了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