An easy way to mix together OWL and Jena Fuseki.
Project description
PyFuseki
pyfuseki - An easy way to mix together OWL and Jena Fuseki.
一个用来连接并操作 Apache Jena Fuseki 的 Python 库,同时提供了同步和异步的两种操作方式。通过使用它,你可以很简单地将你的数据插入 Fuseki 中。
Documentation: https://yubincloud.github.io/pyfuseki/
Source Code: https://github.com/yubinCloud/pyfuseki
Requirements
Python 3.6+
PyFuseki 基于以下三个库来实现任务:
Installation
$ pip install pyfuseki
Example
这里有个简单的例子来演示如何将你的数据插入到 Fuseki 中,先不用究于细节,之后我们会对每一部分进行讲解。
- 首先,我们先按照本体来定义出里面的类,以方便实例化数据:
from pyfuseki.rdf import rdf_prefix, NameSpace as ns
@rdf_prefix('http://expample.com/')
class RdfPrefix():
Person: ns
Dog: ns
rp = RdfPrefix()
- 接下来,我们按照本体中来定义出里面的关系(属性),以方便表示该关系:
from pyfuseki.rdf import rdf_property
from rdflib import URIRef as uri
@rdf_property('http://example.org/')
class ObjectProperty:
own: uri
@rdf_property('http://example.org/')
class DataProperty:
hasName: uri
- 最后,我们实例化出一些数据,并将其相关陈述(三元组)插入到图中:
from pyfuseki import FusekiUpdate
from rdflib import Graph, Literal, RDF
g = Graph()
# 实例化数据
person = rp.Person['12345'] # 假设 '12345' 是这个人的唯一身份证号
dog = rp.Dog['56789'] # 假设这只狗也有唯一的 ID 为 ‘56789’
# 将陈述加入到图中
g.add((person, RDF.type, rp.Person.to_uri())) # 声明 person 的类型是 Person
g.add((dog, RDF.type, rp.Dog.to_uri()))
g.add((person, dp.hasName, Literal('Ryan'))) # 加入了一条三元组,表示 person1 有名字为 'Ryan'
g.add((dog, dp.hasName, Literal('lucy')))
g.add((person, op.own, dog))
# 把图插入到 Fuseki 中
fuseki = FusekiUpdate('http://localhost:3030', 'test_db')
fuseki.insert_graph(g)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyfuseki-1.6.tar.gz
(19.1 kB
view details)
Built Distribution
pyfuseki-1.6-py3-none-any.whl
(25.8 kB
view details)
File details
Details for the file pyfuseki-1.6.tar.gz
.
File metadata
- Download URL: pyfuseki-1.6.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cbca07bec99d27b3b1ee8e8213c9bd0f2a35aa85f2b213175294c6d0ac6ce6c |
|
MD5 | ef05bb72904a963e5d01b94d30e18ba2 |
|
BLAKE2b-256 | d4bf44987c3bb25193498467a5a7cf2d2e2993490122c4129d1b29c5162e675c |
File details
Details for the file pyfuseki-1.6-py3-none-any.whl
.
File metadata
- Download URL: pyfuseki-1.6-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5557e52adbc3b42bab98d0c033de78442d52ca0ce748cd4a8c0ef915bf3b3c7b |
|
MD5 | db4d16df90297d54616c5780231fa925 |
|
BLAKE2b-256 | b9332d2b1e41d294b6ba1f9beee6ddd9a9acce1b4e6f806735017078e571a1da |