Welcome to ontor’s documentation!

ontor (ONTology editOR) is a Python library built on Owlready2 for creating, editing, extending, debugging, and visualizing OWL2 ontologies

ONTology editOR (ontor) module

class ontor.ontor.OntoEditor(iri: str, path: str, import_paths: Optional[list] = None)

create, load, and edit ontologies

add_annotation(name: str, comment: str, lang: Optional[str] = None) None

add annotation in language specified as localized string, defaults to regular string if no language is specified

  • name – entity name

  • comment – annotation to append

  • lang – annotation’s language (optional)

add_axioms(axiom_tuples: list) None

add entire axioms to onto NOTE: only one axiom may be specified at once NOTE: no error handling implemented for input tuples NOTE: complex axioms, i.e., intersections and unions, are currently not supported


axiom_tuples – list of tuples of the form [class, superclass, property, inverted(bool), cardinality type, cardinality, op-object, dp-range, dp-min-ex, dp-min-in, dp-exact, dp-max-in, dp-max-ex, negated(bool), equivalence(bool)]

add_distinctions(distinct_sets: list) None

make classes disjoint and instances distinct NOTE: distinctions may lead to inconsistencies reasoners cannot handle


distinct_sets – list of lists with disjoint/ different elements

add_dps(dp_tuples: list) None

add datatype properties including their axioms to onto


dp_tuples – list of input tuples of the form [dp, super-dp, functional, domain, range, minex, minin, exact, maxin, maxex]

add_import(other_path: str) None

load an additional onto


other_path – path to file of onto to be imported

add_instances(instance_tuples: list) None

add instances and their relations to onto


instance_tuples – list of tuples of the form [instance, class, property, range, range-type]

add_label(name: str, label: str, lang: Optional[str] = None) None

add label in language specified as localized string, defaults to regular string if no language is specified

  • name – entity name

  • label – label to be appended

  • lang – label’s language (optional)

add_ops(op_tuples: list) None

add object properties including their axioms to onto NOTE: only one inverse_prop can be processed per tuple


op_tuples – list of tuples of the form [op, super-op, domain, range, functional, inverse functional, transitive, symmetric, asymmetric, reflexive, irreflexive, inverse_prop]

add_taxo(class_tuples: list) None

add taxonomy to onto


class_tuples – list of 2-tuples of the form [class, superclass]

static class_dict_to_tuple_list(cls_dict: dict) list

helper function to convert dict with class definitions to list of tuples as required by add_taxo function


cls_dict – dictionary for taxonomy definition of the form {superclass: [subclasses]}


list of class definition 2-tuples of the form [[subclass, superclass], …]

debug_onto(reasoner: str = 'hermit', assume_correct_taxo: bool = True) None

interactively (CLI) fix inconsistencies

  • assume_correct_taxo – if True, the user interactions will be limited to restrictions, i.e., options to delete taxonomical relations are not included, e.g., A rdfs:subClassOf B

  • reasoner – reasoner to be used for inferences

export_ntriples() None

saves with same filename, but as ntriples

get_axioms() list

identify all axioms included in the onto


list of class, op, and dp axioms

get_class_restrictions(class_name: str, res_type: str = 'is_a', res_only: bool = True) list

retrieve restrictions on specific class by restriction type

  • class_name – name of the class for which restrictions shall be returned

  • res_only – only returns Restrictions if set to True, if set to False parent class(es) are also included

  • res_type – restriction type, either is_a or equivalent_to


list of restrictions on class

get_elems() list

get classes, object properties, datatype properties, and intances


nodes and edges from onto

query_onto(query: str) list

query onto using SPARQL NOTE: use of query_owlready messes up ranges of dps


query – SPARQL query


query results as list

reasoning(reasoner: str = 'hermit', save: bool = False, debug: bool = False) list

run reasoner to check consistency and infer new facts

  • reasoner – reasoner can be eiter hermit or pellet

  • save – bool - save inferences into original file

  • debug – bool - log pellet explanations for inconsistencies; only works with Pellet


returns list of inconsistent classes if there are any

remove_elements(elem_list: list) None

remove elements, all their descendents and (in case of classes) instances, and all references from axioms


elem_list – list of elements to be removed from onto

remove_from_taxo(elem_list: list, reassign: bool = True) None

remove a class from the taxonomy, but keep all subclasses and instances by relating them to parent NOTE: elem is not replaced in axioms bc this may be semantically incorrect

  • elem_list – list of elements to be removed from onto

  • reassign – add all restrictions to subclasses via is_a

remove_restrictions_including_prop(prop_name: str) None

remove class restrictions that include a certain property


prop_name – name of the property for which all class restrictions shall be removed

remove_restrictions_on_class(class_name: str) None

remove all restrictions on a given class


class_name – name of the class for which restrictions shall be removed

save_as(new_path: str) None

safe ontology as new file helpful, e.g., if multiple ontos were loaded


new_path – path including filename for saving the onto

visualize(classes: Optional[list] = None, properties: Optional[list] = None, focusnode: Optional[str] = None, radius: Optional[int] = None, bylabel: bool = False, lang: Optional[str] = None, open_html: bool = False) None

visualize onto as a graph; generates html

  • classes – list of classes to be included in plot

  • properties – list of properties to be included in plot

  • radius – maximum number of relations between a node and a node of one of the classes specified

  • bylabel – render visualization by labels (if available)

  • lang – language of the labels to be displayed



ontor.ontor.cleanup(complete: bool, *extensions: str) None

delete all files in the current directory with the extensions specified

  • extensions – extensions of files to be deleted

  • complete – do not delete current log file if set to False

ontor.ontor.load_csv(csv_file: str, load_first_line: bool = False) list

load data from CSV file

  • csv_file – input CSV file

  • load_first_line – indicates whether content from first row is also returned


CSV contents as list of lists

ontor.ontor.load_json(json_file: str) dict

load data from JSON file


json_file – input JSON file


JSON contents as dictionary

Indices and tables