问题
I have an RDF dataset where triples are stored in N-Triples format like follows:
<http://ebola.ndssl.bi.vt.edu/country/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ebola.ndssl.bi.vt.edu/vocab/country> .
_:AmapX3aXcountryX5fXcountryX5fXnameX5fXclassMapX40XX40X1 <http://ebola.ndssl.bi.vt.edu/vocab/hasValue> "Guinea" .
I want to do some processing with the blank nodes. I am writing a program to reading this file in Python. I am using Python RDFLib library. After reading the file, I print its content. However, the problem is blank node name is coming out differently. For example:
_:AmapX3aXcountryX5fXcountryX5fXnameX5fXclassMapX40XX40X1
is showing like following
N75424221e7df43708c3e2a135e3e888b
I need original RDF file blank node name as follows:
_:AmapX3aXcountryX5fXcountryX5fXnameX5fXclassMapX40XX40X1
How can I print original RDF file blank node name?
回答1:
You (probably) can't. Blank node ids are local to the specific file they are in, they're not guaranteed preserved between different serializations. RDFLib simply replaces the id with its own new internal id.
Some tools have a parser setting to optionally preserve node ids. I don't know if RDFLib supports this, but even if it does: unless you have a very specific use case you should not be relying on blank node ids being preserved. They are called blank for a reason: their id is for all intents and purposes "unknown".
来源:https://stackoverflow.com/questions/38962190/rdflib-blank-node-printing