May 02, 2015

pathutils

RDF- and RDFlib-centric file and URL path utilities.

uri_leaf()

rdfextras.utils.pathutils.uri_leaf(uri)[source]

Get the “leaf” - fragment id or last segment - of a URI. Useful e.g. for getting a term from a “namespace like” URI. Examples:

>>> uri_leaf('http://example.org/ns/things#item')
'item'
>>> uri_leaf('http://example.org/ns/stuff/item')
'item'
>>> uri_leaf('http://example.org/ns/stuff/')
>>>
>>> uri_leaf('urn:example.org:stuff')
'stuff'
>>> uri_leaf('example.org')
>>>

guess_format()

rdfextras.utils.pathutils.guess_format(fpath, fmap=None)[source]

Guess RDF serialization based on file suffix. Uses SUFFIX_FORMAT_MAP unless fmap is provided. Examples:

>>> guess_format('path/to/file.rdf')
'xml'
>>> guess_format('path/to/file.owl')
'xml'
>>> guess_format('path/to/file.ttl')
'n3'
>>> guess_format('path/to/file.xhtml')
'rdfa'
>>> guess_format('path/to/file.svg')
'rdfa'
>>> guess_format('path/to/file.xhtml', {'xhtml': 'grddl'})
'grddl'

This also works with just the suffixes, with or without leading dot, and regardless of letter case:

>>> guess_format('.rdf')
'xml'
>>> guess_format('rdf')
'xml'
>>> guess_format('RDF')
'xml'

Table Of Contents

Previous topic

cmdlineutils

Next topic

Parsing RDF into rdflib graphs