2016-04-15 27 views
0

我正在尋找使用pyLD將數據從NoSQL數據庫轉換爲RDF。這是代碼的一個片段:擺脫使用pyLD生成的三元組主題中的空白節點

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

所有我需要的是@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