我在本地web服务器上托管了一个小JSON文件,其中包含以下内容:
json_source = {"key1": "azerty", "key2": "qwerty", "key3": "lorem", "key4": "ipsum"}
使用RDFLib库,我正在解析JSON,使用上下文添加一些语义并将其序列化为N个三元组:
^{pr2}$输出结果为空节点:
_:N6dc3aa6a68e34c36beade27af204cb6c <http://purl.org/dc/terms/language> "azerty" .
_:N6dc3aa6a68e34c36beade27af204cb6c <http://purl.org/dc/terms/title> "qwerty" .
_:N6dc3aa6a68e34c36beade27af204cb6c <http://xmlns.com/foaf/0.1/name> "ipsum" .
_:N6dc3aa6a68e34c36beade27af204cb6c <http://purl.org/dc/terms/title> "lorem" .
不知何故,@id没有解析为http://example.org/test
但是,当将JSON-LD添加到JSON-LD Playground时:
{
"@id": "http://example.org/test",
"@context": {
"dct": "http://purl.org/dc/terms/",
"foaf": "http://xmlns.com/foaf/0.1/",
"key1": {"@id": "dct:language"},
"key2": {"@id": "dct:title"},
"key3": {"@id": "dct:title"},
"key4": {"@id": "foaf:name"}
},
"key1": "azerty",
"key2": "qwerty",
"key3": "lorem",
"key4": "ipsum"
}
。。。决议如下:
<http://example.org/test> <http://purl.org/dc/terms/language> "azerty" .
<http://example.org/test> <http://purl.org/dc/terms/title> "lorem" .
<http://example.org/test> <http://purl.org/dc/terms/title> "qwerty" .
<http://example.org/test> <http://xmlns.com/foaf/0.1/name> "ipsum" .
有人对如何解释这种差异有什么建议吗? 谢谢。在
问题是传递给rdflib的上下文不仅包含上下文(
@context
),而且还包含@id
。但是,该方法忽略了除上下文之外的所有内容,这是正确的,在JSON-LD操场中这样做的原因是您将@id
属性添加到文档的body中,而不是上下文。当您传递给游乐场的文件打印成这样时,就会变得很清楚:如果您将
@id
添加到test.json
中,它也适用于RDFlib。在相关问题 更多 >
编程相关推荐