[redland-dev] Are ns names and local names accessible somewhere after parsing?

Dave Beckett dave.beckett at bristol.ac.uk
Wed Sep 1 09:55:14 BST 2004


On Wed, 1 Sep 2004, Stephen Waterbury wrote:
> Hi Dave,

Hello

> I'm using Redland's Python binding's Parser.parse_into_model to
> read an rdf file and then using Model.find to pull out (to begin
> with) any rdfs and owl Class "declarations".  I'd like to
> re-capture if possible (as opposed to guessing by parsing the URI
> strings ;) the namespace names if any "custom" namespaces (like "vs",
> "foaf", "wot", and "dc" below) are explicitly declared in
> the rdf file -- as they are, e.g., in the foaf ontology:
> 
> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>   xmlns:owl="http://www.w3.org/2002/07/owl#"
>   xmlns:vs="http://www.w3.org/2003/06/sw-vocab-status/ns#"
>   xmlns:foaf="http://xmlns.com/foaf/0.1/"
>   xmlns:wot="http://xmlns.com/wot/0.1/"
>   xmlns:dc="http://purl.org/dc/elements/1.1/"
> >
> 
> I.e., after the Parser assembles these into the nodes' full URIs,
> does it discard the xmlns's (and the local names and/or QNames,
> e.g. "owl:Ontology") or can I get to them somehow?

Not at present.  It's on the "todo sometime" list for the
Raptor parser.  It might turn up sooner since I'm tinkering
with improving the serialising part of raptor and that would
benefit from such syntax hints.

> I couldn't find any methods or attributes for that on
> Model (which seemed the most likely place to look) or URI or
> anywhere else in the Redland Python API docs or Python code.
> 
> If I *do* need to extract ns names and local names from the
> URIs, I found this rule in section 8 of the RDF/XML Syntax
> Specification:
> 
> "It is recommended that implementors of RDF serializers,
> in order to break a URI into a namespace name and a local name,
> split it after the last XML non-NCName  character, ensuring that
> the first character of the name is a Letter or '_'."
> 
> Is that a good rule to rely on (assuming the local name contains
> only letters and underscores)?

Yeah, I wrote that sentence.  It works with 99% of all vocabularies
that have been sensibly defined.  I've never seen a failure but
one of the Jena team reported they had a problem with some user
that made some internal database identifiers into URIs that did
not serialize to RDF/XML at all.   Redland's RDF/XML serializer
uses it.

Dave




More information about the redland-dev mailing list