OWL Api, move class from parent A to B

前提是你 提交于 2020-01-03 02:25:33

问题


I'm having a quick question regarding the usage of the owl api.

Say I have a class called Species, which has a Subclass mammal, which has a Subclass Primate, which has a subclass Human.

species -> mammal -> primate -> human

For some reason, I would like to reclassify this in our software and say that Primates are not longer considered Mammals, instead they should be a direct subclass of a Species.

Meaning our graph should look like this now

species -> primate -> human

can anybody please point me in the right direction?

Finding our the parent class is easy enough, using the owl-api

reasoner.getSuperClasses(chield, true).entities().collect(Collectors.toSet[OWLClass])

but how can I 'detach' my class now from it's parent?


回答1:


If you have an ontology where the relations :

  • species -> mammal
  • mammal -> primate
  • primate -> human

are directly asserted (not the result of a reasoning computation).

Then in owlapi this is represented as axioms :

  1. OWLSubClass(mammal, species)
  2. OWLSubClass(primate, mammal)
  3. OWLSubClass(human, primate)

The solution could be to remove the old subClass assertion and add the new one (unless you are playing with Allen-temporal).

OWLDataFactory factory = manager.getOWLDataFactory();
ontology.remove(factory.getOWLSubClassOfAxiom(primate, mammal));
ontology.add(factory.getOWLSubClassOfAxiom(primate, species));

Note : if you are using a version older than 5 of owlapi then we must use the OWLOntologyManager to remove/add axioms in an ontology :

manager.remove(ontology, axiom)
manager.add(ontology, axiom)

If the specialization relation aren't directly asserted in your ontology; it will be far more complex. You have to know why 'human' is view a subclass of 'mammal'. Maybe the 'explanation' system of the 'reasoner' can help you.



来源:https://stackoverflow.com/questions/43216048/owl-api-move-class-from-parent-a-to-b

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!