Skip to content

Instantly share code, notes, and snippets.

@epoz
Created December 12, 2025 15:01
Show Gist options
  • Select an option

  • Save epoz/32962ad6ace6d11e9470566955f492ca to your computer and use it in GitHub Desktop.

Select an option

Save epoz/32962ad6ace6d11e9470566955f492ca to your computer and use it in GitHub Desktop.
Nicer prefixes for OBO style properties
import httpx, rdflib
nfdicore = httpx.get('https://github.com/ISE-FIZKarlsruhe/nfdicore/raw/refs/heads/main/nfdicore-full.ttl', follow_redirects=True)
g = rdflib.Graph()
g.parse(data=nfdicore.text, format='turtle')
nfdi4c = httpx.get('https://raw.githubusercontent.com/ISE-FIZKarlsruhe/nfdi4culture/refs/heads/main/cto-full.ttl', follow_redirects=True)
g.parse(data=nfdi4c.text, format='turtle')
labels = sorted([(s, oo) for s,p,o in g.triples((None, rdflib.RDF.type, None)) for ss, pp, oo in g.triples( (s, rdflib.RDFS.label, None) ) if o in (rdflib.OWL.DatatypeProperty, rdflib.OWL.ObjectProperty) and oo.language == 'en' and not str(s).startswith('https://schema.org/')])
prefixes = '\n'.join([f"@prefix {label.replace(' ', '_')}: <{iri}> ." for iri, label in labels])
print(prefixes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment