G-Node / G-Node/python-odml

Bug in the rdflib graph representation while using turtle format

未关闭
#109 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
RDF
主要语言
Python
星标
25
派生
30
PR 合并指标
30 天内没有已合并 PR

描述

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.

```import uuid
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 odml: .
@prefix rdf: .
@prefix rdfs: .
@prefix xml: .
@prefix xsd: .

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 .

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:

```import uuid
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):

```
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'))]
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。