Project Icon

pygraft

开源Python库,生成自定义模式和知识图谱

PyGraft是一个开源Python库,用于生成合成但真实的模式和知识图谱(KGs)。该工具支持灵活配置生成过程,可单独或同时生成模式和KG。PyGraft采用RDFS和OWL构造,确保逻辑一致性,适用于数据敏感或难以获取的研究领域。它提供多种可调参数,并使用DL推理器保证一致性。研究人员可以利用PyGraft根据简单规格快速生成所需的模式和KGs。

License pypi downloads Code style: black

PyGraft: Configurable Generation of Synthetic Schemas and Knowledge Graphs at Your Fingertips

This is the open-source implementation of PyGraft, initially presented in this paper.

PyGraft is an open-source Python library for generating synthetic yet realistic schemas and (KGs) based on user-specified parameters. The generated resources are domain-agnostic, i.e. they are not tied to a specific application field.

Being able to synthesize schemas and KGs is an important milestone for conducting research in domains where data is sensitive or not readily available. PyGraft allows researchers and practitioners to generate schemas and KGs on the fly, provided minimal knowledge about the desired specifications.

PyGraft has the following features:

  • possibility to generate a schema, a KG, or both
  • highly-tunable process based on a broad array of user-specified parameters
  • schemas and KGs are built with an extended set of RDFS and OWL constructs
  • logical consistency is ensured by the use of a DL reasoner (HermiT)

Installation

The latest stable version of PyGraft can be downloaded and installed from PyPI with:

pip install pygraft

The latest version of PyGraft can be installed directly from GitHub source with:

pip install git+https://github.com/nicolas-hbt/pygraft.git

Upcoming Features

Additional features will be provided in the next versions of PyGraft. To name but a few:

High Priority

  • Allow support for any input schema (and not only the schemas generated by PyGraft).
  • Allow explanations for inconsistencies to be parsed from HermiT API. This would make it possible to remove a subset of triples from inconsistent KGs to make them consistent, without needing the user to run the KG generation pipeline again. This is especially true for very large graphs, or if the user comes with an already existing schema which is not perfectly consistent.

Medium Priority

  • Fix the conflict between the following properties rdfs:subPropertyOf, owl:FunctionalProperty, and owl:InverseFunctionalProperty, as a non-zero value for the three of them at the same time can lead to inconsistent KGs.

Low Priority

  • Facilitate the generation of larger KGs (this would imply removing any dependency to rdflib).
  • Add support for literals.

PyGraft Overview

The contributions of PyGraft are as follows:

  • To the best of our knowledge, PyGraft is the first generator able to synthesize both schemas and KGs in a single pipeline.

  • The generated schemas and KGs are described with an extended set of RDFS and OWL constructs, allowing for both fine-grained resource descriptions and strict compliance with common Semantic Web standards.

  • A broad range of parameters can be specified by the user. These allow for creating an infinite number of graphs with different characteristics. More details on parameters can be found in the Parameters section of the official documentation.

From a high-level perspective, the entire PyGraft generation pipeline is depicted in Figure 1. In particular, Class and Relation Generators are initialized with user-specified parameters and used to build the schema incrementally. The logical consistency of the schema is subsequently checked using the HermiT reasoner from owlready2. If you are also interested in generating a KG based on this schema, the KG Generator is initialized with KG-related parameters and fused with the previously generated schema to sequentially build the KG. Ultimately, the logical consistency of the resulting KG is (again) assessed using HermiT.

Figure 1: PyGraft Overview

Usage -- PyGraft as a package

Once installed, PyGraft can be loaded with:

import pygraft

Importantly, you can access all the functions with:

pygraft.__all__

Generating a Schema

Let us assume we are only interested in generating a schema. We first need to retrieve the template configuration file (e.g. a .yaml configuration file), which is as simple as calling create_yaml_template():

pygraft.create_yaml_template()

Now, the template has been generated under the current working directory, and is named template.yml by default.

This file contains all the tunable parameters. For more details on their meanings, please check the Parameters section.

For the sake of simplicity, we do not plan to modify this template and stick with the default parameter values.

Generating an ontology is made possible via the generate_schema(path) function, which only requires the relative path to the configuration file.

[!IMPORTANT] For the following steps, i.e. generating a schema and a KG, you need Java to be installed and the $JAVA_HOME environment variable to be properly assigned. This is because the HermiT reasoner currently runs using Java.

In our case, the configuration file is named template.yml and is located in the current working directory, thereby:

pygraft.generate_schema("template.yml")

The generated schema can be retrieved in output/template/schema.rdf. Additional files are created during the process: output/template/class_info.json and output/template/relation_info.json. These files give important information about the classes and relations of the generated schema, respectively.

Generating a KG

Let us now explore how to use PyGraft to generate a KG. In this section, we assume we already have a schema, that will serve as a blueprint for generating our KG. We can use the same configuration file as before – as it also contained parameters related to the KG generation (although not used before, since we only asked for a schema) – to generate a KG:

pygraft.generate_kg("template.yml")

The generated KG can be retrieved in output/template/full_graph.rdf. It combines information inherited from output/template/schema.rdf (i.e. ontological information) with information related to individuals.

Full Pipeline Execution

In most cases, one wants to generate both a schema and a KG in a single process. PyGraft allows this with the generate(path) function, which operates just as the aforedescribed two functions generate_schema(path) and generate_kg(path):

pygraft.generate("template.yml")

Usage -- PyGraft from the CLI

Assuming you have cloned the PyGraft repository to your computer:

  1. Install dependencies:
pip install pygraft
  1. Call the PyGraft entry point, from the project's root folder:
# Displaying help
python -m pygraft.main --help
# Generating a schema from a local template file
python -m pygraft.main -g generate_schema -conf template.yml

# ...  then browse the resulting schema in the ./output/template folder.

About

Interested in contributing to PyGraft? Please consider reaching out: nicolas.hubert@univ-lorraine.fr

If you like PyGraft, consider downloading PyGraft and starring our GitHub repository to make it known and promote its development!

If you use or mention PyGraft in a publication, cite our work as:

@misc{hubert2023pygraft,
  title={PyGraft: Configurable Generation of Schemas and Knowledge Graphs at Your Fingertips}, 
  author={Nicolas Hubert and Pierre Monnin and Mathieu d'Aquin and Armelle Brun and Davy Monticolo},
  year={2023},
  eprint={2309.03685},
  archivePrefix={arXiv},
  primaryClass={cs.AI}
}
项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

吐司

探索Tensor.Art平台的独特AI模型,免费访问各种图像生成与AI训练工具,从Stable Diffusion等基础模型开始,轻松实现创新图像生成。体验前沿的AI技术,推动个人和企业的创新发展。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号