Skip to content

Commit

Permalink
use literals for data properties
Browse files Browse the repository at this point in the history
  • Loading branch information
cmungall committed May 30, 2024
1 parent 2f3e320 commit a6a67d1
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 128 deletions.
15 changes: 11 additions & 4 deletions linkml_owl/dumpers/owl_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,23 @@ def transform(self, element: YAMLRoot, schema: SchemaDefinition, is_element_an_o
if element is None:
return None
try:
# naive method to test if an object is an enum:
# try accessing the `meaning` field. If this fails,
# an exception is thrown, and we carry on.
# (when owl_duper is refactored to not be dependent on
# python dataclasses this will no longer be necessary)
meaning = element.meaning
# translate Enum
if is_element_an_object or True:
if is_element_an_object:
# enum is used in an object context: translate to URI
if not meaning:
enum_uri = schema.default_prefix + ":" + type(element).__name__
meaning = enum_uri + "#" + str(element).replace(" ", "+")
return self._get_IRI_str(meaning)
else:
# enum is used in a data context - stringify
return str(element)
except AttributeError:
# not an enum - carry on
pass
if not self._instance_of_linkml_class(element):
# TODO: better way of detecting atoms
Expand Down Expand Up @@ -330,8 +337,8 @@ def transform(self, element: YAMLRoot, schema: SchemaDefinition, is_element_an_o
slot_interps = self._get_slot_interpretations(slot, linkml_class_name)
logging.debug(f'OWL interpretations for {k}={slot_interps}')
is_object_ref = slot.range in self.schema.classes
#if "ObjectPropertyAssertion" in slot_interps or "ObjectProperty" in slot_interps:
# is_object_ref = True
if "ObjectPropertyAssertion" in slot_interps or "ObjectProperty" in slot_interps:
is_object_ref = True
# normalize input_vals to a list, then recursively transform
if isinstance(v, list):
input_vals = v
Expand Down
57 changes: 57 additions & 0 deletions tests/inputs/monsters_and_magic.expected.ofn
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,23 @@ Ontology( <https://w3id.org/cmungall/monsters-and-magic>
SubClassOf( mnm:Humanoid mnm:Creature )
Declaration( Class( mnm:Orc ) )
AnnotationAssertion( schema:description mnm:Orc "An orc is a humanoid creature from Middle-earth." )
DataPropertyAssertion( mnm:armor_class mnm:Orc "13"^^xsd:integer )
DataPropertyAssertion( mnm:strength mnm:Orc "16"^^xsd:integer )
DataPropertyAssertion( mnm:dexterity mnm:Orc "11"^^xsd:integer )
DataPropertyAssertion( mnm:constitution mnm:Orc "12"^^xsd:integer )
DataPropertyAssertion( mnm:intelligence mnm:Orc "10"^^xsd:integer )
DataPropertyAssertion( mnm:wisdom mnm:Orc "8"^^xsd:integer )
DataPropertyAssertion( mnm:charisma mnm:Orc "8"^^xsd:integer )
SubClassOf( mnm:Orc mnm:Humanoid )
Declaration( Class( mnm:Goblin ) )
AnnotationAssertion( schema:description mnm:Goblin "A goblin is a humanoid creature from Middle-earth." )
DataPropertyAssertion( mnm:armor_class mnm:Goblin "15"^^xsd:integer )
DataPropertyAssertion( mnm:strength mnm:Goblin "8"^^xsd:integer )
DataPropertyAssertion( mnm:dexterity mnm:Goblin "14"^^xsd:integer )
DataPropertyAssertion( mnm:constitution mnm:Goblin "10"^^xsd:integer )
DataPropertyAssertion( mnm:intelligence mnm:Goblin "10"^^xsd:integer )
DataPropertyAssertion( mnm:wisdom mnm:Goblin "8"^^xsd:integer )
DataPropertyAssertion( mnm:charisma mnm:Goblin "8"^^xsd:integer )
SubClassOf( mnm:Goblin mnm:Humanoid )
Declaration( Class( mnm:SerpentineCreature ) )
AnnotationAssertion( schema:description mnm:SerpentineCreature "A serpentine creature is a creature that has a snake-like body." )
Expand Down Expand Up @@ -67,24 +81,66 @@ Ontology( <https://w3id.org/cmungall/monsters-and-magic>
SubClassOf( mnm:MagicallyCreatedCreature mnm:Creature )
Declaration( Class( mnm:RugOfSmothering ) )
AnnotationAssertion( schema:description mnm:RugOfSmothering "A rug of smothering is a rug that can be used to suffocate a creature." )
DataPropertyAssertion( mnm:armor_class mnm:RugOfSmothering "13"^^xsd:integer )
DataPropertyAssertion( mnm:strength mnm:RugOfSmothering "16"^^xsd:integer )
DataPropertyAssertion( mnm:dexterity mnm:RugOfSmothering "11"^^xsd:integer )
DataPropertyAssertion( mnm:constitution mnm:RugOfSmothering "12"^^xsd:integer )
DataPropertyAssertion( mnm:intelligence mnm:RugOfSmothering "10"^^xsd:integer )
DataPropertyAssertion( mnm:wisdom mnm:RugOfSmothering "8"^^xsd:integer )
DataPropertyAssertion( mnm:charisma mnm:RugOfSmothering "8"^^xsd:integer )
SubClassOf( mnm:RugOfSmothering mnm:MagicallyCreatedCreature )
Declaration( Class( mnm:Basilisk ) )
AnnotationAssertion( schema:description mnm:Basilisk "A basilisk is a legendary serpent-like creature with the body of a snake and the head of a king cobra." )
DataPropertyAssertion( mnm:armor_class mnm:Basilisk "13"^^xsd:integer )
DataPropertyAssertion( mnm:strength mnm:Basilisk "16"^^xsd:integer )
DataPropertyAssertion( mnm:dexterity mnm:Basilisk "11"^^xsd:integer )
DataPropertyAssertion( mnm:constitution mnm:Basilisk "12"^^xsd:integer )
DataPropertyAssertion( mnm:intelligence mnm:Basilisk "10"^^xsd:integer )
DataPropertyAssertion( mnm:wisdom mnm:Basilisk "8"^^xsd:integer )
DataPropertyAssertion( mnm:charisma mnm:Basilisk "8"^^xsd:integer )
SubClassOf( mnm:Basilisk mnm:SerpentineCreature )
Declaration( Class( mnm:UndeadCreature ) )
AnnotationAssertion( schema:description mnm:UndeadCreature "An undead creature is a creature that is dead, but has been brought back to life by magic." )
SubClassOf( mnm:UndeadCreature mnm:Humanoid )
Declaration( Class( mnm:WhiteWalker ) )
AnnotationAssertion( schema:description mnm:WhiteWalker "A white walker is an undead creature from the Game of Thrones universe." )
DataPropertyAssertion( mnm:armor_class mnm:WhiteWalker "13"^^xsd:integer )
DataPropertyAssertion( mnm:strength mnm:WhiteWalker "16"^^xsd:integer )
DataPropertyAssertion( mnm:dexterity mnm:WhiteWalker "11"^^xsd:integer )
DataPropertyAssertion( mnm:constitution mnm:WhiteWalker "12"^^xsd:integer )
DataPropertyAssertion( mnm:intelligence mnm:WhiteWalker "10"^^xsd:integer )
DataPropertyAssertion( mnm:wisdom mnm:WhiteWalker "8"^^xsd:integer )
DataPropertyAssertion( mnm:charisma mnm:WhiteWalker "8"^^xsd:integer )
SubClassOf( mnm:WhiteWalker mnm:UndeadCreature )
Declaration( Class( mnm:Lich ) )
AnnotationAssertion( schema:description mnm:Lich "A lich is a fictional undead creature in the Dungeons & Dragons fantasy role-playing game." )
DataPropertyAssertion( mnm:armor_class mnm:Lich "13"^^xsd:integer )
DataPropertyAssertion( mnm:strength mnm:Lich "16"^^xsd:integer )
DataPropertyAssertion( mnm:dexterity mnm:Lich "11"^^xsd:integer )
DataPropertyAssertion( mnm:constitution mnm:Lich "12"^^xsd:integer )
DataPropertyAssertion( mnm:intelligence mnm:Lich "10"^^xsd:integer )
DataPropertyAssertion( mnm:wisdom mnm:Lich "8"^^xsd:integer )
DataPropertyAssertion( mnm:charisma mnm:Lich "8"^^xsd:integer )
SubClassOf( mnm:Lich mnm:UndeadCreature )
Declaration( Class( mnm:Vampire ) )
AnnotationAssertion( schema:description mnm:Vampire "A vampire is a fictional undead creature in the Dungeons & Dragons fantasy role-playing game." )
DataPropertyAssertion( mnm:armor_class mnm:Vampire "13"^^xsd:integer )
DataPropertyAssertion( mnm:strength mnm:Vampire "16"^^xsd:integer )
DataPropertyAssertion( mnm:dexterity mnm:Vampire "11"^^xsd:integer )
DataPropertyAssertion( mnm:constitution mnm:Vampire "12"^^xsd:integer )
DataPropertyAssertion( mnm:intelligence mnm:Vampire "10"^^xsd:integer )
DataPropertyAssertion( mnm:wisdom mnm:Vampire "8"^^xsd:integer )
DataPropertyAssertion( mnm:charisma mnm:Vampire "8"^^xsd:integer )
SubClassOf( mnm:Vampire mnm:UndeadCreature )
Declaration( Class( mnm:Zombie ) )
AnnotationAssertion( schema:description mnm:Zombie "A zombie is a fictional undead creature in the Dungeons & Dragons fantasy role-playing game." )
DataPropertyAssertion( mnm:armor_class mnm:Zombie "13"^^xsd:integer )
DataPropertyAssertion( mnm:strength mnm:Zombie "16"^^xsd:integer )
DataPropertyAssertion( mnm:dexterity mnm:Zombie "11"^^xsd:integer )
DataPropertyAssertion( mnm:constitution mnm:Zombie "12"^^xsd:integer )
DataPropertyAssertion( mnm:intelligence mnm:Zombie "10"^^xsd:integer )
DataPropertyAssertion( mnm:wisdom mnm:Zombie "8"^^xsd:integer )
DataPropertyAssertion( mnm:charisma mnm:Zombie "8"^^xsd:integer )
SubClassOf( mnm:Zombie mnm:UndeadCreature )
Declaration( NamedIndividual( mnm:Smaug ) )
Declaration( Class( mnm:Smaug ) )
Expand All @@ -98,6 +154,7 @@ Ontology( <https://w3id.org/cmungall/monsters-and-magic>
ClassAssertion( mnm:WhiteWalker mnm:TheNightKing )
Declaration( Class( mnm:Paladin ) )
AnnotationAssertion( schema:description mnm:Paladin "A paladin is a holy warrior who fights evil using divine magic." )
DataPropertyAssertion( mnm:hit_dice mnm:Paladin "D10" )
Declaration( Class( mnm:Wizard ) )
AnnotationAssertion( schema:description mnm:Wizard "A wizard is a person who practices magic." )
Declaration( Class( mnm:Rogue ) )
Expand Down
Loading

0 comments on commit a6a67d1

Please sign in to comment.