我正在使用rdflibjsonld解析一些NoSQL数据并插入到Sesame中。这是代码中有问题的部分:
context = {
"@context": {
"isGiven": URIRef('<'+'http://purl.org/net/something#isGiven'+rdfLizerItem['FooByBar']+'>'),
"administeredAs": URIRef('<'+'http://purl.org/net/something#administeredAs'+'>'),
"type":URIRef('<'+'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'+'>'),
}
}
recipient=URIRef('<'+someUrl+rdfLizerItem['FooRecipient']+'>')
jsonldOutputIsAdmin = {"@id": recipient,"isGiven": URIRef('<'+someUrl+ rdfLizerItem['Quantity']+'>')}
print jsonldOutputIsAdmin
g = Graph()
g.parse(data=json.dumps(jsonldOutputIsAdmin), format='json-ld', context=context)
g.close()
for s,p,o in g:
pprint.pprint ((s,p,o))
问题是在<
和>
添加到@id
的URL之后,主题的URL就变成了它的完整路径。例如:
(rdflib.term.URIRef(u'file:///C:/path/to/the/url/<http:/purl.org/net/ontologyName#subject>'),
rdflib.term.URIRef(u'<http://purl.org/net/ontologyName#predicate>'),
rdflib.term.Literal(u'<http://purl.org/net/ontologyName#object>'))
我只想在主题的网址,而不是文件路径。是什么导致了这个问题?我该如何解决它?你知道吗
我需要<
和>
将三元组导出到Sesame。你知道吗
为了避免将文件系统路径作为前缀应用,需要为上下文提供base IRI的值
例如,如果您这样修改上下文:
context['@context']['@base'] = '.'
您将看不到以@id值为前缀的路径。你知道吗
相关问题 更多 >
编程相关推荐