how to create default prefix with only colon with rdflib?

17 views
Skip to first unread message

wqp.g...@gmail.com

unread,
Jul 15, 2019, 1:55:08 PM7/15/19
to rdflib-dev
Dear community,

How can I create default prefix with only colon with rdflib?

For instance, I hope to have:

@prefix : <https://xxx> .

<yyy>
rdf:type :fff ;
rdfs:label "example" .

Thanks!

Nicholas Car

unread,
Jul 16, 2019, 7:35:20 AM7/16/19
to rdfli...@googlegroups.com
DEFAULT = rdflib.Namespace('http://example.org/')
g.bind('', DEFAULT)

Nick
--
http://github.com/RDFLib
---
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
To post to this group, send email to rdfli...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/fc80b5c7-fd22-488b-9396-d5d3727d1f8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicholas Car

unread,
Jul 16, 2019, 7:36:49 AM7/16/19
to rdfli...@googlegroups.com
Here's a full example:

-----
import rdflib
from rdflib import RDF, URIRef, Literal

g = rdflib.Graph()
SDO = rdflib.Namespace('https://schema.org/')
g.bind('sdo', SDO)

DEFAULT = rdflib.Namespace('http://example.org/')
g.bind('', DEFAULT)

g.add((
URIRef('http://example.org/person/nick'),
RDF.type,
SDO.Person
))

g.add((
URIRef('http://example.org/person/nick'),
SDO.name,
Literal('Nicholas Car')
))

g.add((
DEFAULT.other,
RDF.type,
SDO.Thing
))
-----

print(g.serialize(format='turtle').decode('utf-8'))

prints:
-----
@prefix : <http://example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sdo: <https://schema.org/> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:other a sdo:Thing .

<http://example.org/person/nick> a sdo:Person ;
sdo:name "Nicholas Car" .
-----


Nick
Reply all
Reply to author
Forward
0 new messages