当标签不在 ontology 但可以在 URI 中找到时,从 owl 本体中提取标签
Extracting labels from owl ontologies when the label isn't in the ontology but can be found at the URI
请耐心等待,因为我是语义技术的新手。
我正在尝试使用包 rdflib
从本体中的 类 中提取标签。然而,有些本体本身不包含标签,但具有来自其他本体的 类 URI。如何从外部本体的 URI 中提取标签?
我的尝试背后的直觉集中在识别 类 不包含本地标签(如果这是正确的放置方式),然后 "following" 它们的 URI 到外部本体提取标签。但是我实现它的方式不起作用。
import rdflib
g = rdflib.Graph()
# I have no trouble extracting labels from this ontology:
# g.load("http://purl.obolibrary.org/obo/po.owl#")
# However, this ontology contains no labels locally:
g.load("http://www.bioassayontology.org/bao/bao_complete.owl#")
owlClass = rdflib.namespace.OWL.Class
rdfType = rdflib.namespace.RDF.type
for s in g.subjects(predicate=rdfType, object=owlClass):
# Where label is present...
if g.label(s) != '':
# Do something with label...
print(g.label(s))
# This is what I have added to try to follow the URI to the external ontology.
elif g.label(s) == '':
g2 = rdflib.Graph()
g2.parse(location=s)
# Do something with label...
print(g.label(s))
我是不是采取了完全错误的方法?感谢所有帮助!谢谢。
我认为你可以比这更有效率。您正在尝试执行 Web 请求,远程 ontology 下载并搜索 每次 您遇到一个没有在 http://www.bioassayontology.org/bao/bao_complete.owl
中给出的标签的 URI他们中的大多数,这是一个非常大的数字。因此,您的脚本将永远持续下去,并会破坏提供这些远程本体的 Web 服务器。
查看 http://www.bioassayontology.org/bao/bao_complete.owl
,我发现大多数没有标签的 URI 来自 OBO,也许还有一些其他本体,但主要是 OBO。
您应该做的是下载一次 OBO 并使用 RDFlib 加载它。然后,如果您 运行 您在 http://www.bioassayontology.org/bao/bao_complete.owl
和 OBO 的联合(并集)图上的脚本,您将触手可及 OBO 的所有内容,这样 g.label(s)
就会发现更高的比例标签数量。
也许还有一些其他源本体为您可能需要的 http://www.bioassayontology.org/bao/bao_complete.owl
提供标签,但我的快速浏览只看到 OBO。
请耐心等待,因为我是语义技术的新手。
我正在尝试使用包 rdflib
从本体中的 类 中提取标签。然而,有些本体本身不包含标签,但具有来自其他本体的 类 URI。如何从外部本体的 URI 中提取标签?
我的尝试背后的直觉集中在识别 类 不包含本地标签(如果这是正确的放置方式),然后 "following" 它们的 URI 到外部本体提取标签。但是我实现它的方式不起作用。
import rdflib
g = rdflib.Graph()
# I have no trouble extracting labels from this ontology:
# g.load("http://purl.obolibrary.org/obo/po.owl#")
# However, this ontology contains no labels locally:
g.load("http://www.bioassayontology.org/bao/bao_complete.owl#")
owlClass = rdflib.namespace.OWL.Class
rdfType = rdflib.namespace.RDF.type
for s in g.subjects(predicate=rdfType, object=owlClass):
# Where label is present...
if g.label(s) != '':
# Do something with label...
print(g.label(s))
# This is what I have added to try to follow the URI to the external ontology.
elif g.label(s) == '':
g2 = rdflib.Graph()
g2.parse(location=s)
# Do something with label...
print(g.label(s))
我是不是采取了完全错误的方法?感谢所有帮助!谢谢。
我认为你可以比这更有效率。您正在尝试执行 Web 请求,远程 ontology 下载并搜索 每次 您遇到一个没有在 http://www.bioassayontology.org/bao/bao_complete.owl
中给出的标签的 URI他们中的大多数,这是一个非常大的数字。因此,您的脚本将永远持续下去,并会破坏提供这些远程本体的 Web 服务器。
查看 http://www.bioassayontology.org/bao/bao_complete.owl
,我发现大多数没有标签的 URI 来自 OBO,也许还有一些其他本体,但主要是 OBO。
您应该做的是下载一次 OBO 并使用 RDFlib 加载它。然后,如果您 运行 您在 http://www.bioassayontology.org/bao/bao_complete.owl
和 OBO 的联合(并集)图上的脚本,您将触手可及 OBO 的所有内容,这样 g.label(s)
就会发现更高的比例标签数量。
也许还有一些其他源本体为您可能需要的 http://www.bioassayontology.org/bao/bao_complete.owl
提供标签,但我的快速浏览只看到 OBO。