Skip to main content

An easy way to mix together OWL and Jena Fuseki.

Project description

PyFuseki

pyfuseki - An easy way to mix together OWL and Jena Fuseki.

A library that uses Python to connect and manipulate Jena Fuseki, which provides sync and async methods.

By using PyFuseki, you can easily store data from your program into Jena Fuseki, following the ontology model, and then query and parse Jena.


Documentation: https://yubincloud.github.io/pyfuseki/

Source Code: https://github.com/yubinCloud/pyfuseki


Requirements

Python 3.6+

PyFuseki stands on the shoulders of giants:

Installation

$ pip install pyfuseki

---> 100%

Example

  • First, we define the classes of the ontology predesigned:
from pyfuseki.ontology_mapper import rdf_prefix, BaseRdfPrefixEnum
from rdflib import Namespace
from pyfuseki import config

@rdf_prefix
class RdfPrefix(BaseRdfPrefixEnum):
    BrandProject = Namespace(config.COMMON_PREFIX + 'BrandProject')
    Firm = Namespace(config.COMMON_PREFIX + 'Firm')
  • Next, we define the data properties and object properties of the ontology predesigned:
from pyfuseki.ontology_mapper import BaseProperty
from rdflib import Namespace
from pyfuseki import config

yb = Namespace(config.COMMON_PREFIX)

class ObjectProperty(BaseProperty):
    """
    本体中所有Object properties的枚举
    name 为该 property 的 display name, value 为包装了该 property IRI 的 URIRef 对象
    """
    brandAgencyObjectProperty = yb.brandAgencyObjectProperty
    subordinateTo = yb.subordinateTo   # 从属于


class DataProperty(BaseProperty):
    """
    本体中所有Data properties的枚举
    name 为该 property 的 display name, value 为包装了该 property IRI 的 URIRef 对象
    """
    brandAgencyDataProperty = yb.brandAgencyDataProperty
    createTime = yb.createTime
    enName = yb.enName
  • Finally, we can insert data which we collected into Jena Fuseki:
async def insert_test():
    pyfuseki.register.register_common_prefix("http://www.yubin.com/kg/")
    fuseki = AsyncFuseki('http://localhost:3030', 'pyfuseki_db')
    g = Graph()

    """测试整个过程"""
    # RdfUtils.bind_prefixes_to_graph(self.g, [rp.BrandProject, rp.Firm])  # 绑定前缀
    # 假设获取的数据为rev_data
    rev_data = {
        'band_project': '腾讯',
        '所属企业': '深圳市腾讯计算机系统有限公司',
        '成立日期': '1998-11-11',
        '英文名称': 'QQ'
    }
    # 将rev_data转化成RDF三元组并加入graph中
    tencent = rp.BrandProject.val('腾讯')
    RdfUtils.add_dict_to_graph(g, tencent, {
        op.subordinateTo.value: rp.Firm.val('深圳市腾讯计算机系统有限公司'),
        dp.createTime.value: Literal(rev_data['成立日期'], datatype=XSD.date),
        dp.enName.value: Literal(rev_data['英文名称'], datatype=XSD.string)
    })
    print(g)
    # 将graph插入
    await 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.0.2.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

pyfuseki-1.0.2-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file pyfuseki-1.0.2.tar.gz.

File metadata

  • Download URL: pyfuseki-1.0.2.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for pyfuseki-1.0.2.tar.gz
Algorithm Hash digest
SHA256 30a8fef7bdbf70b5f37ec72828edefe9b59579430a4283ba37f58133913186ee
MD5 d23373468e672b87efdd7a2799f9f6bf
BLAKE2b-256 b3fce44acd0084371472a0bd3e592a2ea5f8f056047af228def6e1eeb2aa7a9c

See more details on using hashes here.

File details

Details for the file pyfuseki-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyfuseki-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for pyfuseki-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c2d9dfba00296f1523eb97b94b9c9c862d483aacb3c5e4ee6a3cd8b6bf96658c
MD5 f52e216860b666a7bdc932522eb297e9
BLAKE2b-256 b73fe0e02832d34e87d8644ca1b911f0bb1c11b25346b5b7e51b29e9681f3aeb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page