How to handle class names that include periods ('.')?

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

How to handle class names that include periods ('.')?

jeffrey.staples
I have using Owlready2 to parse and augment to the ICD10CM ontology available on Bioportal (https://bioportal.bioontology.org/ontologies/ICD10CM). Unfortunately, the class names in their ontology include '.'s in the names, e.g. "H90.2". I can load this ontology into Owlready2, but I am not able to use some of the class building functions due to syntax errors:

>>> class H90.6(Phe10_H906):
  File "<stdin>", line 1
    class H90.6(Phe10_H906):
              ^
SyntaxError: invalid syntax

I have tried the following, but each provides some form of syntax error:
1. putting single and double quotes: class "H90\.6"(Phe10_H906):
2. escaping the period: class H90\.6(Phe10_H906):
3. adding the onto in front: "class onto["H90.6"](Phe10_H906):
4. a few other things

Is there a way to handle class names with periods in the name?

Thanks,

Jeff

Reply | Threaded
Open this post in threaded view
|

Re: How to handle class names that include periods ('.')?

Jiba
Administrator
Hi,

You can access classes with special characters in their name as follows:

onto["H90.2"]

Python does not allow the creation of classes with special characters in their name, but you can work around this problem by creating the class with a different name, and then changing its name:

class H90_6(Phe10_H906):
    ...
H90_6.name = "H90.6"

Jiba