我希望使用pyLD将NoSQL数据库中的数据转换为RDF。这是代码的片段:
doc = {
'http://example.com': 'test',
'http://purl.org/net/something#isGiven':'dose'}
context = {
'dose':{'@id':'http://purl.org/net/something#isGiven','@type':'@id'}
}
norm = jsonld.normalize(
doc,{'algorithm': 'URDNA2015', 'format': 'application/nquads'})
print norm
这是生成的输出:
_:c14n0 <http://example.com> "test" .
_:c14n0 <http://purl.org/net/something#isGiven> "dose" .
因此JSON的键成为属性,而对象的值。现在,如何主张这个主题?
我希望我的输出为:
<http://example.com/person> <http://example.com> "test" .
<http://example.com/person> <http://purl.org/net/something#isGiven> "dose" .
答案 0 :(得分:0)
我需要的只是@id,如下所示:
doc = {
'http://example.com': 'test',
'http://purl.org/net/something#isGiven':'dose',
'@id':'http://example.com'}
context = {
'dose':{'@id':'http://purl.org/net/something#isGiven','@type':'@id'}
}
norm = jsonld.normalize(
doc,{'algorithm': 'URDNA2015', 'format': 'application/nquads'})
print norm