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)