I'm using the RDFlib to automate the process of creating the DSD. I want to get a format as follows:
_:refPeriodStep1 a qb4o:HierarchyStep;
etc...
but using this:
graph.add((BNode('refPeriodStep1'), RDF.type, URIRef(qb4o + 'HierarchyStep')))
the file is not created as desired.
I tried to use the function n3():
graph.add((BNode('refPeriodStep1').n3(), RDF.type, URIRef(qb4o + 'HierarchyStep')))
but I get the following error:
AssertionError: Subject _:refPeriodStep1 must be an rdflib term
Is there any way to get it as wanted?
As suggested in comment, if the name of the blank node matter, you should probably use an URI instead. Your last comment suggest you are not using URIRef correctly when stating
URIRef('_', 'refPeriodStep1')
(according to my understanding).If you want your
refPeriodStep1
to not be a blank node while keeping it (somehow) unprefixed, you can define an empty prefix using thenamespace_manager
of your graph.For example the following code is creating a
refPeriodStep
of typeqb4o:HierarchyStep
usingNamespace
fonctionnalities instead of URIRef directly (this is probably the easiest way to do if you reuse a lot your namespaces as stated here in the documentation) :This will output the following (in turtle) which is close to what you expect :
Note that if you try to serialize a blank node in
n-triples
format, RDFLib will keep the name used when creating that blank node, such as :