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

How to generate a standard ontology title? #2643

Open
rbuck-som opened this issue Nov 14, 2023 · 3 comments
Open

How to generate a standard ontology title? #2643

rbuck-som opened this issue Nov 14, 2023 · 3 comments

Comments

@rbuck-som
Copy link

How do you generate this EXACT text using the library?

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .

<http://www.w3.org/2000/01/rdf-schema#> a owl:Ontology ;
	dc:title "The RDF Schema vocabulary (RDFS)" .

I have tried all sorts of incantations and I can't get it to work. It either generates URI Refs in quotes (no angle brackets), or it simply emits "rdfs:", no URI.

@LvanWissen
Copy link

But in Turtle syntax the rdfs: translates to a valid URI.

I don't think there is a way to unbind a prefix from the NamespaceManager, which automatically binds some 'core prefixes':

for prefix, ns in _NAMESPACE_PREFIXES_CORE.items():
self.bind(prefix, ns)
)

Either pick a different serialization format (e.g. nt), or write your own custom NamespaceManager. But keep in mind that the rdfs: bit is valid RDF.

@edmondchuc
Copy link
Contributor

Is this what you want?

from rdflib import Graph, URIRef, Literal, RDF, OWL, DC


graph = Graph()
graph.namespace_manager.bind("rdfs", None, replace=True)

rdfs = URIRef("http://www.w3.org/2000/01/rdf-schema#")

graph.add((
    rdfs, RDF.type, OWL.Ontology
))
graph.add((
    rdfs, DC.title, Literal("The RDF Schema vocabulary (RDFS)")
))

graph.print()

Output:

@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

<http://www.w3.org/2000/01/rdf-schema#> a owl:Ontology ;
    dc:title "The RDF Schema vocabulary (RDFS)" .

Looks like binding an existing prefix with None with the optional replace=True will "unbind" the prefix.

@rbuck-som
Copy link
Author

rbuck-som commented Dec 13, 2023 via email

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

3 participants