在Python中加载本体

发布于 2024-10-18 13:26:54 字数 161 浏览 7 评论 0原文

我有一个用 OWL 编写的本体。有谁知道我可以将它加载到 python 中吗?任何软件包甚至手动? 其他问题中提到的 rdflib 不适合我,因为它主要与 RDF 相关,而“Seth”这个非常好的库不起作用,因为它需要“Pellet”库,而该库的网站似乎已关闭并且它(seth) 也仅适用于 JVM 1.4!

I have an Ontology written in OWL. Does anyone know I can load it into python? any packages or even manually?
rdflib which is mentioned in other questions is not suitable for me because it mainly concerns with RDF and "Seth" which is a very nice library doesn't work, because it requires "Pellet" library for which the website seems to be down and it(seth) also only works with JVM 1.4!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

情深缘浅 2024-10-25 13:26:54

我还没有完全尝试过这一点,但是您可以考虑将本体加载到 Sesame 数据库中,然后查询它使用 Python 包装器。我玩过 RDFAlchemypySesame 一点,但我仍然不知道它们有多好。总的来说,RDF/OWL 数据库对我来说非常不成熟,因此预计会遇到一些重大的技术障碍。

I've not fully tried this, but you could look at loading your ontology into a Sesame database and then query it using a Python wrapper. I've played with RDFAlchemy and pySesame a little, but I still don't have a feel for how good they are. RDF/OWL databases feel very immature to me in general, so expect to encounter some significant technical hurtles.

沫雨熙 2024-10-25 13:26:54

如果有人再次偶然发现这个问题,这个包现在可用于与 Python 中的 OWL 本体进行交互: https:// /pypi.org/project/Owlready2/

从项目描述来看,它具有以下功能:

  1. 以 NTriples、RDF/XML 或 OWL/XML 格式导入 OWL 2.0 本体。
  2. 将 OWL 2.0 本体导出为 NTtriples 或 RDF/XML。
  3. 透明地操作本体类、实例和属性,就像它们是普通的 Python 对象一样。
  4. 将 Python 方法添加到本体类。
  5. 使用 HermiT 推理器执行类和实例的自动分类。
  6. 测试了多达 1 亿个 RDF 三元组(但可能支持更多)。
  7. 此外,quadstore与RDFlib Pyton模块兼容,可用于执行SPARQL查询。

In case anyone stumbles across this question again, this package is now available for interacting with OWL ontologies in Python: https://pypi.org/project/Owlready2/

From the project description, it has these capabilities:

  1. Import OWL 2.0 ontologies in NTriples, RDF/XML or OWL/XML format.
  2. Export OWL 2.0 ontologies to NTriples or RDF/XML.
  3. Manipulates ontology classes, instances and properties transparently, as if they were normal Python objects.
  4. Add Python methods to ontology classes.
  5. Perform automatic classification of classes and instances, using the HermiT reasoner.
  6. Tested up to 100 millions of RDF triples (but can potentially support more).
  7. In addition, the quadstore is compatible with the RDFlib Pyton module, which can be used to perform SPARQL queries.
陌上芳菲 2024-10-25 13:26:54

rdfAlchemy 中的 commands.py 文件中有一个命令部分就是为此目的而启动的。有一段时间没有使用它了,但它正是您所问问题的开始,即从本体创建 python 骨架。

事实上,它使用粘贴“命令”。如果您转到 rdfalchemy 子目录并输入:

paster rdfSubject -h

您应该看到:

用法:/home/phil/venv/some_path/bin/paster rdfSubject [选项] 
粘贴 rdfalchemy.commands
使用 RDF 模式中的描述符创建 rdfSubject 子类

    将设置 rdf_type
    将创建描述符
    
      1. rdfs:domain 和 rdfs:range 受到尊重
      2. rdfSingle 用于以下属性
            * owl:逆函数性质
            * owl:功能属性   
      3. 如果设置了合适的范围,则使用rdfList或rdfContainer
      4. rdfMultiple 用于所有其他
      
    生成的 .py 文件将作为开发人员信心的框架。  
    不要指望能够使用原始结果。
    
使用 RDF 模式中的描述符创建 rdfSubject 子类

选项:
  -h, --help 显示此帮助消息并退出
  -v, --详细         
  -n, --模拟        
  -s 架构,--schema=架构
                        此类的 rdfSchema 的文件名或 url
  -o FOUT, --fout=FOUT 输出文件名默认:stdout(例如
                        ../MyRdfModel.py)
  -l, --list 列出架构文件中 `owl:Class` 的有效实例

Within rdfAlchemy in the commands.py file there is commands section that was started for just this purpose. Haven't used it in a while but it is the beginings of exactly what you asked about i.e. creating the python skel from an ontology.

In fact, it uses paster "commands". If you go to the rdfalchemy subdir and type:

paster rdfSubject -h

you should see:

Usage: /home/phil/venv/some_path/bin/paster rdfSubject [options] 
paster rdfalchemy.commands
Create an rdfSubject subclass with descriptors from an RDF Schema

    will set the rdf_type
    Descriptors will be created
    
      1.  rdfs:domain and rdfs:range are respected
      2.  rdfSingle is used for properties that are
            * owl:InverseFunctionalProperty
            * owl:FunctionalProperty   
      3.  rdfList or rdfContainer is used if the proper range is set
      4.  rdfMultiple is used for all others
      
    The resulting .py file is ment to be a skeleton for the developers confvience.  
    Do not expect to be able to use the raw results.
    
Create an rdfSubject subclass with descriptors from an RDF Schema

Options:
  -h, --help            show this help message and exit
  -v, --verbose         
  -n, --simulate        
  -s SCHEMA, --schema=SCHEMA
                        file name or url of rdfSchema for this class
  -o FOUT, --fout=FOUT  output file name default: stdout (e.g.
                        ../MyRdfModel.py)
  -l, --list            list valid instances of `owl:Class` in the schema file
打小就很酷 2024-10-25 13:26:54

是的,RDFLib 适用于 RDF 语义,因此您需要一个工具包来管理 OWL 语义。

我通常首先使用另一个工具来获取所有三元组(OWLAPIOWLRL),然后将其加载到 RDFLib 中。

Right, RDFLib works at the RDF semantics, so you'd need a toolkit for managing OWL semantics.

What I usually do it to first use another tool to get all the triples (OWLAPI or OWLRL, for instance) and then load it in RDFLib.

錯遇了你 2024-10-25 13:26:54

我还可以找到这个 ordf 但似乎他们刚刚为自己写了一些文字完全不清楚如何使用,很遗憾!

I could also find this ordf but it seems that they have just written some text for themsleves it is not clear at all how to use it, it's a pity!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文