【问题标题】:How to handle invalid property name in python in Owlready2如何在 Owlready2 中处理 python 中的无效属性名称
【发布时间】:2021-11-13 19:51:03
【问题描述】:

资源名称以'2_'开头,在python中似乎无效,因为我们得到如下消息:

invalid decimal literal

您能告诉我如何获取该资源的价值吗? 更具体地说,它的URI如下:

http://purl.obolibrary.org/obo/chebi.owl#2_STAR

并且,访问chebi.2_STAR.id 会导致以下结果。

File "<ipython-input-156-66b94380a437>", line 1
    chebi.2_STAR.id
           ^
SyntaxError: invalid decimal literal

谢谢。

【问题讨论】:

    标签: owlready


    【解决方案1】:

    所以我不确定您的 URI 是否正确。我相信这是您在文件中阅读时自动发生的事情。要访问它,我认为您需要一个没有“.owl”的名称空间。另一种选择是使用全局“obo”命名空间。

    我可以通过以下方式访问它:

    obo = get_namespace("http://purl.obolibrary.org/obo/")
    obo['chebi#2_STAR']
    
    # 2_STAR only has comments so,
    obo['chebi#2_STAR'].comment 
    #returns
    ['Annotated by 3rd party', 'Annotated by 3rd party']
    

    遇到不兼容的字符,用括号括起来,作为字符串放入。

    更新 (2021-09-23) 再看一下 CHEBI 本体,看起来有几个可用的命名空间,在 CHEBI 命名空间内调用命名空间的更好方法是:

    from owlready2 import *
    
    #loaded from local file
    chebi = get_ontology("chebi.owl").load()
    
    #get the right namespace. note the 'chebi.' correction to what I initially did.
    chebi2 = chebi.get_namespace("http://purl.obolibrary.org/obo/chebi#")
    #then retrieve
    chebi2['2_STAR']
    

    我还不知道如何查询那里有哪些命名空间,但如果您已经知道前缀,那可以帮助您获得所需的命名空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-01
      • 1970-01-01
      • 2021-03-26
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多