Snomed and punning

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

Snomed and punning

anthropomorphism
I have this issue: https://github.com/IHTSDO/snomed-owl-toolkit/issues/49 (that issue isn't posted by me, but I have the same problem)

namely that Snomed ontology has what the Snomed-owl-toolkit developers consider to be a valid structure but which owlready2 considers to be an invalid structure.

The developers say:
[...] that fact that https//snomed.info/id762705008 is modeled as a class and a property is expected and deliberate. This is an unusual situation so we reached out to some industry experts during the design of this change and we had confirmation that this is a legal thing to do. It was a few years back now but I believe this is known in OWL as "punning".

Is there a way I can make owlready2 accept this structure? Failing that, is there a workaround (using Protege or some similar tool, perhaps) so that I can convert the ontology to something that owlready2 will accept?
Reply | Threaded
Open this post in threaded view
|

Re: Snomed and punning

anthropomorphism
Anyone reading this who wants a horribly horrible hack to sort this out, please don't blame me when this entirely fails to work for you.

import re

fn = "with_punning.rdfxml.owl"
fn_out = "without_punning.rdfxml.owl"

# NEVER PARSE XML with regexps! ;-D

re_decl = re.compile(r'.*<owl:(Class|ObjectProperty|DatatypeProperty) rdf:about="http:\/\/snomed\.info\/id\/(\d+)".*')

classes = set()
props = set()
with open(fn, "rt") as f:
    for line in f:
        m = re_decl.match(line)
        if m:
            if m.group(1) == "Class":
                classes.add(m.group(2))
            else:
                props.add(m.group(2))


overlap = classes.intersection(props)
print(overlap)

with open(fn, "rt") as f:
    with open(fn_out, "wt") as fout:
        for line in f:
            m = re_decl.match(line)
            if m and m.group(1) == "Class" and m.group(2) in overlap:
                    line = line.replace(m.group(2), "class_"+m.group(2))
            fout.write(line)
Reply | Threaded
Open this post in threaded view
|

Re: Snomed and punning

Jiba
Administrator
In reply to this post by anthropomorphism
Hi,

Punning is not supported by Owlready; punning is very far from the Python object model and it would be difficult to have a class that also acts as a property or an individual.

Thank you for providing a fix for the problem,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Snomed and punning

anthropomorphism
The fix above does not yield a consisten ontology, unfortunately; I've had it pointed out to me that references to the renamed classes remain unchanged.