如何在python的owlready2中实现一个类的子类列表?



我想在protege上构建的本体中获得每个类的所有子类,并使用owlready2导入到python中。如何为这个本体的集合类创建一个所有子类的列表?

只需使用list(class_name.subclasses())

You can dynamically create classes or sub classes.
import types
class_name = "MyClass"
parent_class = [Thing]
with onto:
NewClass = types.new_class(class_name, tuple(parent_class))

Please note the new_class() function expects a tuple with the parent
classes and reference of parent class will be passed not string. If your parent class present inside the ontology you can access (onto["parent_class"])

相关内容

  • 没有找到相关文章

最新更新