Problem with missing xml:base when saving in RDF/XML

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with missing xml:base when saving in RDF/XML

ChrisWroe
I'm using version 0.33 and Python 3.8.5.

I'm creating a little ontology in a SNOMED-CT namespace http://snomed.info/id/

world = World()
sct_namespace = world.get_ontology("http://snomed.info/id/")

with sct_namespace:
  # create some classes here

sct_namespace.save(file='snomedct_plus.rdf')  

I've run into problems when viewing in Protege. The RDF/XML file is missing an xml:base attribute which means Protege puts the classes in a file based IRI namespace rather than the http://snomed.info/id/ namespace.

It comes out with this:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:owl="http://www.w3.org/2002/07/owl#"
         xmlns:core="http://www.w3.org/2004/02/skos/core#"
         xmlns="http://snomed.info/id/">

<owl:Ontology rdf:about="http://snomed.info/id"/>

<owl:ObjectProperty rdf:about="SCT_609096000">
  <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">role group</rdfs:label>
  <core:altLabel xml:lang="en">Role group (attribute)</core:altLabel>
  <core:prefLabel xml:lang="en">Role group</core:prefLabel>
</owl:ObjectProperty>...

I can fix it by modifying driver.py line 324-325 from:

xmln = xmlns.get(left)
if not xmln:


to

xmln = xmlns.get(left)
if left not in xmlns:


I think what is happening is that the base uri has an empty string to denote no prefix but empty string evaluates to False and so the abbrev(storid) function goes ahead creates a new 'id:' prefix for the SNOMED namespace. As the prefix is no longer "" for the base uri no xml:base attribute is created in the XML root element.

I could be wrong though as in some situations it has been working without the fix in the past.






Reply | Threaded
Open this post in threaded view
|

Re: Problem with missing xml:base when saving in RDF/XML

Jiba
Administrator
Hi,

I tried the example below, but I was unable to reproduce the problem. Could you improve it so as it causes the problem you report?

When saving RDF/XML, in driver.py, xml:base is normally added for the item in the xmlns dict that has an empty string "" as value. At line 306 and below, such an item is systematically added, unless the base_iri of the ontology is not a string (that might append in rare cases, e.g. RDF file that do not really define an ontology). So an xml:base should always be present.

Jiba

world = World()
sct_namespace = world.get_ontology("http://snomed.info/id/")

with sct_namespace:
  pass
  # create some classes here
  class MyClass(Thing):
    pass

sct_namespace.save(file='/tmp/snomedct_plus.rdf')  

print(open('/tmp/snomedct_plus.rdf').read())
Reply | Threaded
Open this post in threaded view
|

Re: Problem with missing xml:base when saving in RDF/XML

ChrisWroe
Hi,

Thanks for looking. I'll try and create a fuller example to replicate and post back here. It is happening when I have more than one ontology in the world with one importing the other.
It could well be my issue getting things into a 'strange' state.

Chris