Giter Site home page Giter Site logo

yubincloud / pyfuseki Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 3.0 612 KB

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

Home Page: https://yubincloud.github.io/pyfuseki/

License: Apache License 2.0

Python 100.00%
jena-fuseki owl httpx async-await sparql rdf

pyfuseki's Introduction

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)

pyfuseki's People

Contributors

yubincloud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyfuseki's Issues

allow for insertion of named graphs

I would suggest that you allow for named graph insertion in pyfuseki.utils.RdfUtils.convert_graph_to_insert_sparql, say if the passed Graph has an identifier, use this as the graph name.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.