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

Parameters
  • 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

Parameters

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

Parameters

distinct_sets – list of lists with disjoint/ different elements

add_dps(dp_tuples: list) None

add datatype properties including their axioms to onto

Parameters

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

Parameters

other_path – path to file of onto to be imported

add_instances(instance_tuples: list) None

add instances and their relations to onto

Parameters

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

Parameters
  • 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

Parameters

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

Parameters

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

Parameters

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

Returns

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

Parameters
  • 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

Returns

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

Parameters
  • 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

Returns

list of restrictions on class

get_elems() list

get classes, object properties, datatype properties, and intances

Returns

nodes and edges from onto

query_onto(query: str) list

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

Parameters

query – SPARQL query

Returns

query results as list

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

run reasoner to check consistency and infer new facts

Parameters
  • 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

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

Parameters

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

Parameters
  • 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

Parameters

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

Parameters

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

Parameters

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

Parameters
  • 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

Returns

None

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

delete all files in the current directory with the extensions specified

Parameters
  • 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

Parameters
  • csv_file – input CSV file

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

Returns

CSV contents as list of lists

ontor.ontor.load_json(json_file: str) dict

load data from JSON file

Parameters

json_file – input JSON file

Returns

JSON contents as dictionary

Indices and tables