Python RDFLib plugin printed unread json

橙三吉。 提交于 2019-12-25 04:16:03

问题


I am trying to reproduce the example code from https://github.com/RDFLib/rdflib-jsonld as below:

from rdflib import Graph, plugin
from rdflib.serializer import Serializer
testrdf = '''
@prefix dc: <http://purl.org/dc/terms/> .
<http://example.org/about>
dc:title "Someone's Homepage"@en .
'''
g = Graph().parse(data=testrdf, format='n3')
print(g.serialize(format='json-ld', indent=4))

However, it seems my python output was not printed as same as the expected result.

The result should be:

{
    "@id": "http://example.org/about",
    "http://purl.org/dc/terms/title": [
        {
             "@language": "en",
             "@value": "Someone's Homepage"
        }
    ]
}

but I got these output

b'[\n    {\n        "@id": "http://example.org/about",\n        "http://purl.org/dc/terms/title": [\n            {\n                "@language": "en",\n                "@value": "Someone\'s Homepage"\n            }\n        ]\n    }\n]'

Is there any extra setup that I have to do in order to get the proper output?

来源:https://stackoverflow.com/questions/39990392/python-rdflib-plugin-printed-unread-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!