Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Bug in the rdflib graph representation while using turtle format

オープン
#109 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
data

調査の方向性

Graph.serialize(format='turtle') と、issue に示されている rdflib の Namespace および URIRef の値を使用した最小限の Python 再現コードから始めます。数字で始まる識別子と文字で始まる識別子について Turtle 出力を比較し、その後 test1.xml を経由したラウンドトリップでグラフが保持されることを確認します。URI 値の Turtle シリアライゼーションが一貫しており、グラフを変更しないことを確認できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

RDF

The bug was found in the rdflib graph representation while using the turtle format. Depending on the first symbol of the string (in our case id) that was being added to the namespace (while creating url), the turtle format prints it as a simple string instead of the URI. In case of a digit everything works good. But for a letter it fails. Yet the problem was found only in the turtle format. rdf/xml works well. (See the code sniped)

The issue was tested to see if this problem influences the initial graph when opening the file that was previously saved in the turtle format. The result is that it influences only visual representation but not the graph itself. (See the code for the test)

The issue was created for tutorial or documentation purposes.

from rdflib import Graph, Namespace, RDF, URIRef
g = Graph()
ns = Namespace("http://g-node.org/odml-rdf#")
g.bind('odml', ns)
hubNode = URIRef(ns + uuid.uuid4().urn[9:])
docNode = URIRef(ns + uuid.uuid4().urn[9:])
g.add((hubNode, RDF.type, ns.Hub))
g.add((docNode, RDF.type, ns.Document))
g.add((hubNode, ns.hasDocument, docNode))
print(g.serialize(format='turtle').decode("utf-8"))

Graph outputs for various ids:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://g-node.org/odml-rdf#173dac73-2ffc-46d5-9635-52b3d08c1e9a> a odml:Hub ;
    
	odml:hasDocument odml:e818923e-7765-428e-88cd-4b5eb5b5b06d .

odml:e818923e-7765-428e-88cd-4b5eb5b5b06d a odml:Document .
		
###############################
		
odml:e7888eee-5041-4cea-aea1-b95a32a71c85 a odml:Hub ;
    odml:hasDocument <http://g-node.org/odml-rdf#4e5fdd78-5d4f-4f88-ac82-bd22ca4eb1ce> .

<http://g-node.org/odml-rdf#4e5fdd78-5d4f-4f88-ac82-bd22ca4eb1ce> a odml:Document .
	
#################################

odml:e4871192-282c-4f2b-882c-67e5f690d550 a odml:Hub ;
    odml:hasDocument odml:ac5a6f45-2f9e-4439-a84d-b2f1c23f2c37 .

odml:ac5a6f45-2f9e-4439-a84d-b2f1c23f2c37 a odml:Document .

The test that was used to analyze the problem:

from rdflib import Graph, Namespace, RDF, URIRef
g = Graph()
ns = Namespace("http://g-node.org/odml-rdf#")
g.bind('odml', ns)
hubNode = URIRef(ns + uuid.uuid4().urn[9:])
docNode = URIRef(ns + uuid.uuid4().urn[9:])
g.add((hubNode, RDF.type, ns.Hub))
g.add((docNode, RDF.type, ns.Document))
g.add((hubNode, ns.hasDocument, docNode))
print(g.serialize(format='turtle').decode("utf-8"))

data = g.serialize(format='turtle').decode("utf-8")
f = open("./python-odml/rdf_dev/example_odmls/test1.xml", "w")
f.write(data)
f.close()

g = Graph()
g.parse(source="./python-odml/rdf_dev/example_odmls/test1.xml", format="turtle")

f = open("./python-odml/rdf_dev/example_odmls/test2.xml", "w")
data = g.serialize(format='turtle').decode("utf-8")
print(data)
print(list(g.subject_objects(predicate=ns.hasDocument)))
f.write(data)
f.close()

The output of the test2.xml (same as test1.xml):

<http://g-node.org/odml-rdf#0e06bd34-2670-4a19-ba59-6a3118a6c8ed> a odml:Hub ;
    odml:hasDocument odml:c7c57f18-7642-4344-bc49-eb1b9903cb7d .

odml:c7c57f18-7642-4344-bc49-eb1b9903cb7d a odml:Document .

## Output: subject and object in the triple with hasDocument predicate 
[(rdflib.term.URIRef('http://g-node.org/odml-rdf#0e06bd34-2670-4a19-ba59-6a3118a6c8ed'),
rdflib.term.URIRef('http://g-node.org/odml-rdf#c7c57f18-7642-4344-bc49-eb1b9903cb7d'))]
主要言語
Python
スター
25
フォーク
30
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

G-Node/python-odml のほかの issue

G-Node/python-odml の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。