Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding user-defined Namespace #2659

Open
cameronmore opened this issue Dec 8, 2023 · 1 comment
Open

Binding user-defined Namespace #2659

cameronmore opened this issue Dec 8, 2023 · 1 comment

Comments

@cameronmore
Copy link

Hello! I wrote some code that iterates through a CSV which has RDF in it like the following:

cco:Person1 , rdf:type , cco:Person
cco:Person1 rdfs:label , John

But I can't bind my user defined namespace (cco) in the graph. I've tried something like this:

g.bind('cco',cco)

And this:

g.bind('http://www.ontologyrepository.com/CommonCoreOntologies/',cco)

But neither works. Instead, ns1 is bound simply as cco and ns2 is rdfs
How can I bind user-defined prefixes in a graph that don't resort to ns1 ns2?

@WhiteGobo
Copy link
Contributor

WhiteGobo commented Jan 11, 2024

This worked for me:

from rdflib import *

cco = Namespace("http://www.ontologyrepository.com/CommonCoreOntologies/")

g = Graph()
g.add((cco.A, BNode(), BNode()))
g.bind("cco", cco)

print(g.serialize())
#@prefix cco: <http://www.ontologyrepository.com/CommonCoreOntologies/> .
#cco:A [ ] [ ] .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants