2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[python]rdflibを使って自作FusekiサーバにRDFトリプルを追加する方法

Last updated at Posted at 2015-03-03

rdflibの扱い方を把握し切れてないので、暫定的な処理
rdflibドキュメント
*事前にFusekiサーバを起動
fuseki-server --mem --update --desc [ttl_file] /dataset

FusekiサーバにRDFトリプルを追加するコード

rdf2fuseki.py
import rdflib
from rdflib import Graph,URIRef

if __name__ == '__main__':

    # 追加するRDFトリプルの用意
    bob    = URIRef("http://example.org#bob")
    like   = URIRef("http://example.org#like")
    tomato = URIRef("http://example.org#tomato")

    # Endpointの用意
    endpoint = r"http://localhost:3030/ds/query"
    store = sparqlstore.SPARQLUpdateStore()
    store.open((endpoint,r"http://localhost:3030/ds/update"))
    
    # 追加するGraph
    default_graph = URIRef('http://example.org/default-graph')
    ng = Graph(store, identifier=default_graph)
    ng.add((bob, like, tomato)) #RDFトリプルに追加

RDFトリプルは追加されるが、以下の警告がでるので改善が必要

WARN : Unrecognize request parameter (ignored): output
WARN : Unrecognize request parameter (ignored): format
WARN : Unrecognize request parameter (ignored): results
2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?