filip.semantics.vocabulary package

Submodules

filip.semantics.vocabulary.combined_relations module

Vocabulary Models for CombinedRelations

pydantic model filip.semantics.vocabulary.combined_relations.CombinedDataRelation[source]

Bases: CombinedRelation

Combines all data relations of a class that share the same DataProperty Represents one Data Field of a class

Fields:
field class_iri: str [Required]

IRI of the class the relations and this CR belongs to

field id: str [Required]

Generated unique ID of the CR

field property_iri: str [Required]

IRI of the property, under which the relations are bundled

field relation_ids: List[str] = []

List of all relations of the class that are bundled; have the same property

get_field_type(vocabulary: Vocabulary) DataFieldType[source]

Get type of CDR (command, devicedata , simple)

Args:

vocabulary (Vocabulary): Vocabulary of the project

Returns:

DataFieldType

get_possible_enum_target_values(vocabulary: Vocabulary) List[str][source]

Get all enum values that are allowed as values for this Data field

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

List[str]

get_property_label(vocabulary: Vocabulary) str[source]

Get the label of the DataProperty

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

str

is_device_relation(vocabulary: Vocabulary) bool[source]

Test if the CDR is a device property(command, or readings)

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

bool

pydantic model filip.semantics.vocabulary.combined_relations.CombinedObjectRelation[source]

Bases: CombinedRelation

Combines all object relations of a class that share the same ObjectProperty Represents one Relation Field of a class

Fields:
field class_iri: str [Required]

IRI of the class the relations and this CR belongs to

field id: str [Required]

Generated unique ID of the CR

field property_iri: str [Required]

IRI of the property, under which the relations are bundled

field relation_ids: List[str] = []

List of all relations of the class that are bundled; have the same property

get_all_possible_target_class_iris(vocabulary) List[str][source]

Get all iris that are valid values for this cor

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

List[str]

get_inverse_of_labels(vocabulary: Vocabulary) List[str][source]

Get the labels of the inverse_of properties of this COR

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

List[str]

get_property_label(vocabulary: Vocabulary) str[source]

Get the label of the ObjectProperty

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

str

pydantic model filip.semantics.vocabulary.combined_relations.CombinedRelation[source]

Bases: BaseModel

Combines all relations of a class that share the same Property Represents one Field of a class. SHORT: CR

It provides the common ground for the specialisations:

CombinedObjectRelation, CombinedDataRelation

Fields:
field class_iri: str [Required]

IRI of the class the relations and this CR belongs to

field id: str [Required]

Generated unique ID of the CR

field property_iri: str [Required]

IRI of the property, under which the relations are bundled

field relation_ids: List[str] = []

List of all relations of the class that are bundled; have the same property

export_rule(vocabulary: Vocabulary, stringify_fields: bool) str[source]

Get the rule as string

Parameters:
  • vocabulary (Vocabulary) – Vocabulary of the project

  • stringify_fields (bool) – If true, all string delimieters will be removed

Returns:

str

get_all_target_iris(vocabulary: Vocabulary) Set[str][source]

Get all iris of referenced targets

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

set(str)

get_all_target_labels(vocabulary: Vocabulary) Set[str][source]

Get all labels of referenced targets

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

set(str)

get_all_targetstatements_as_string(vocabulary: Vocabulary) str[source]

Get a string stating all conditions(target statement) that need to be fulfilled, so that this CR is fulfilled

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

str

get_property_label(vocabulary: Vocabulary) str[source]

Get the label of the Property. Overwritten by children

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

str

get_relations(vocabulary: Vocabulary) List[Relation][source]

filip.semantics.vocabulary.entities module

Vocabulary Models for Ontology Entities

pydantic model filip.semantics.vocabulary.entities.Class[source]

Bases: Entity

Representation of OWL:CLASS

A class has a set of relations that are combined into CombinedRelations

Instances are instantiations of a class

A class can represent Devices, Agents, None or both

Fields:
field ancestor_class_iris: List[str] = []

All class_iris of classes from which this class inherits

field child_class_iris: List[str] = []

All class_iris of classes that inherit from this class

field combined_data_relation_ids: List[str] = []

All combined_data_relations ids defined for this class

field combined_object_relation_ids: List[str] = []

All combined_object_relations ids defined for this class

field parent_class_iris: List[str] = []

All class_iris of classes that are direct parents of this class

field relation_ids: List[str] = []

All ids of relations defined for this class

get_ancestor_classes(vocabulary: Vocabulary) List[Class][source]

Get all ancestor classes of this class

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

List[Class]

get_combined_data_relation_with_property_iri(property_iri, vocabulary)[source]

Get the CombinedDataRelation of this class that combines the relations of the given DataProperty

Parameters:
  • property_iri (str) – Iri of the DataProperty

  • vocabulary (Vocabulary) – Vocabulary of this project

Returns:

CombinedDataRelation

get_combined_data_relations(vocabulary: Vocabulary) List[CombinedDataRelation][source]

Get all combined data relations belonging to this class

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

List[CombinedDataRelation]

get_combined_object_relation_with_property_iri(obj_prop_iri: str, vocabulary: Vocabulary) CombinedObjectRelation[source]

Get the CombinedObjectRelation of this class that combines the relations of the given ObjectProperty

Parameters:
  • obj_prop_iri (str) – Iri of the ObjectProperty

  • vocabulary (Vocabulary) – Vocabulary of this project

Returns:

CombinedObjectRelation

get_combined_object_relations(vocabulary: Vocabulary) List[CombinedObjectRelation][source]

Get all combined object relations belonging to this class

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

List[CombinedObjectRelation]

get_combined_relation_with_property_iri(property_iri, vocabulary) CombinedRelation | None[source]

Get the CombinedRelation of this class that combines the relations of the given Property

If possible use the more specific access functions to save runtime.

Parameters:
  • property_iri (str) – Iri of the Property

  • vocabulary (Vocabulary) – Vocabulary of this project

Returns:

CombinedRelation, None if iri is unknown

get_combined_relations(vocabulary: Vocabulary) List[CombinedRelation][source]

Get all combined relations belonging to this class

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

List[CombinedRelation]

get_next_combined_relation_id(current_cr_id: str, object_relations: bool) str[source]

Get the alphabetically(Property label) next CombinedRelation.

If no CR is after the given one, the first is returned

Parameters:
  • current_cr_id (str) – ID of the CombinedRelation of which the next should be found

  • object_relations (bool) – True if Searching for CombinedObjectRelations

Returns:

ID of next CR

Return type:

str

get_parent_classes(vocabulary: Vocabulary, remove_redundancy: bool = False) List[Class][source]

Get all parent classes of this class

Parameters:
  • vocabulary (Vocabulary) – Vocabulary of this project

  • remove_redundancy (bool) – if true the parents that are child of other parents are not included

Returns:

List[Class]

get_previous_combined_relation_id(current_cr_id: str, object_relations: bool) str[source]

Get the alphabetically(Property label) previous CombinedRelation.

If no CR is before the given one, the last is returned

Parameters:
  • current_cr_id (str) – ID of the CombinedRelation of which the previous should be found

  • object_relations (bool) – True if Searching for CombinedObjectRelations

Returns:

ID of previous CR

Return type:

str

get_relation_ids() List[str][source]

Get all ids of relations belonging to this class

Returns:

List[str]

get_relations(vocabulary: Vocabulary) List[Relation][source]

Get all relations belonging to this class

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

List[Relation]

is_child_of_all_classes(target_list: List[str]) bool[source]

Tests if this class is a child class for each of the given classes

Parameters:

target_list (List[str]) – List of ancestor class_iris

Returns:

bool

is_iot_class(vocabulary: Vocabulary) bool[source]

A class is an iot/device class if it contains one CDR, where the relation is marked as a device relation: DeviceAttribute/Command

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

bool

is_logically_equivalent_to(class_: Class, vocabulary: Vocabulary, old_vocabulary: Vocabulary) bool[source]

Test if a class is logically equivalent in two vocabularies.

Parameters:
  • class (Class) – Class to be tested against, from the old_vocabulary

  • vocabulary (Vocabulary) – New project vocabulary

  • old_vocabulary (Vocabulary) – Old project vocabulary

Returns:

bool

treat_dependency_statements(vocabulary: Vocabulary) List[DependencyStatement][source]

Purge and list all pointers/iris that are not contained in the vocabulary

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

List of purged statements dicts with keys: Parent Class, class, dependency, fulfilled

Return type:

List[Dict[str, str]]

class filip.semantics.vocabulary.entities.DataFieldType(value)[source]

Bases: str, Enum

Type of the field that represents the DataProperty

command = 'command'
device_attribute = 'device_attribute'
simple = 'simple'
pydantic model filip.semantics.vocabulary.entities.DataProperty[source]

Bases: Entity

Representation of OWL:DataProperty

Fields:
field field_type: DataFieldType = DataFieldType.simple

Type of the dataproperty; set by the user while configuring the vocabulary

pydantic model filip.semantics.vocabulary.entities.Datatype[source]

Bases: Entity, DatatypeFields

Represents OWL:Datatype

A Datatype is the target of a DataRelation. The Datatype stats a set of values that are valid. This can be an ENUM, a number range, or a check for black/whitelisted chars

In the Parsing PostProcesseor predefined datatype_catalogue are added to the vocabulary

Fields:
field comment: str = ''

Comment extracted from the ontology/source

field iri: str [Required]

Unique Internationalized Resource Identifier

field label: str = ''

Label (displayname) extracted from source file (multiple Entities could have the same label)

field predefined: bool = False

Stats if the entity is not extracted from a source, but predefined in the program (Standard Datatypes)

field source_ids: Set[str] = {}

IDs of the sources that influenced this class

field user_set_label: Any = ''

Given by user and overwrites ‘label’. Needed to make labels unique

export() Dict[str, str][source]

Export datatype as dict

Returns:

Dict[str,str]

is_logically_equivalent_to(datatype: Datatype, vocabulary: Vocabulary, old_vocabulary: Vocabulary) bool[source]

Test if this datatype is logically equivalent to the given datatype

Parameters:
  • datatype (Datatype) – Datatype to compare against

  • vocabulary (Vocabulary) – Not used, but needed to keep signature the same as other entities

  • old_vocabulary (Vocabulary) – Not used, but needed to keep signature the same as other entities

Returns:

bool

value_is_valid(value: str) bool[source]

Test if value is valid for this datatype. Numbers are also given as strings

Parameters:

value (str) – value to be tested

Returns:

bool

pydantic model filip.semantics.vocabulary.entities.DatatypeFields[source]

Bases: BaseModel

Key Fields describing a Datatype

Fields:
field allowed_chars: List[str] = []

If Type==String: Whitelisted chars

field enum_values: List[str] = []

If Type==Enum: Enum values

field forbidden_chars: List[str] = []

If Type==String: Blacklisted chars

field number_decimal_allowed: bool = False

If Type==Number: Are decimal numbers allowed?

field number_has_range: Any = False

If Type==Number: Does the datatype define a range

field number_range_max: int | str = '/'

If Type==Number: Max value of the datatype range, if a range is defined

field number_range_min: int | str = '/'

If Type==Number: Min value of the datatype range, if a range is defined

field type: DatatypeType = DatatypeType.string

Type of the datatype

class filip.semantics.vocabulary.entities.DatatypeType(value)[source]

Bases: str, Enum

Types of a Datatype

date = 'date'
enum = 'enum'
number = 'number'
string = 'string'
pydantic model filip.semantics.vocabulary.entities.Entity[source]

Bases: BaseModel

Representing an OWL Entity (Class, Datatype, DataProperty, ObjectProperty,

Individual)

An Entity is characterised by a unique IRI and originates from a source

An Entity needs a unique Label (displayname) as it is used in FIWARE as field key. The user can overwrite the given label

Fields:
field comment: str = ''

Comment extracted from the ontology/source

field iri: str [Required]

Unique Internationalized Resource Identifier

field label: str = ''

Label (displayname) extracted from source file (multiple Entities could have the same label)

field predefined: bool = False

Stats if the entity is not extracted from a source, but predefined in the program (Standard Datatypes)

field source_ids: Set[str] = {}

IDs of the sources that influenced this class

field user_set_label: Any = ''

Given by user and overwrites ‘label’. Needed to make labels unique

get_label() str[source]

Get the label for the entity. If the user has set a label it is returned, else the label extracted from the source

Returns:

str

get_ontology_iri() str[source]

Get the IRI of the ontology that this entity belongs to (extracted from IRI)

Returns:

str

get_original_label() str[source]

Get label as defined in the source It can be that the label is empty, then extract the label from the iri

Returns:

str

get_source_names(vocabulary: Vocabulary) List[str][source]

Get the names of all the sources

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

str

get_sources(vocabulary: Vocabulary) List[Source][source]

Get all the source objects that influenced this entity. The sources are sorted according to their names

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

str

is_renamed() bool[source]

Check if the entity was renamed by the user

Returns:

bool

set_label(label: str)[source]

Change the display label of the entity

Parameters:

label (str) – Label that the label should have

pydantic model filip.semantics.vocabulary.entities.Individual[source]

Bases: Entity

Represents OWL:Individual

An individual is a predefined “instance” of a class But they are here only used as values for Relations

They are not instances, no value can be assigned to them, they are no agents or devices

Fields:
field parent_class_iris: List[str] = []

List of all parent class iris, an individual can have multiple parents

get_ancestor_iris(vocabulary: Vocabulary) List[str][source]

Get all iris of ancestor classes

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

List[str]

get_parent_classes(vocabulary: Vocabulary) List[Class][source]

Get all parent class objects

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

List[Class]

is_logically_equivalent_to(individual: Individual, vocabulary: Vocabulary, old_vocabulary: Vocabulary) bool[source]

Test if this individal is logically equivalent in two vocabularies.

Parameters:
  • individual (Individual) – Individual to be tested against, from the old vocabulary

  • vocabulary (Vocabulary) – New project vocabulary, not used but needed to keep signature the same

  • old_vocabulary (Vocabulary) – Old project vocabulary, not used but needed to keep signature the same

Returns:

bool

to_string() str[source]

Get a string representation of the Individual

Returns:

str

treat_dependency_statements(vocabulary: Vocabulary) List[DependencyStatement][source]

Purge and list all pointers/iris that are not contained in the vocabulary

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

List of purged statements dicts with keys: Parent Class, class, dependency, fulfilled

Return type:

List[Dict[str, str]]

pydantic model filip.semantics.vocabulary.entities.ObjectProperty[source]

Bases: Entity

Representation of OWL:ObjectProperty

Fields:
field inverse_property_iris: Set[str] = {}

List of property iris that are inverse:Of; If an instance i2 is added in an instance i1 for this property. Then i1 is added to i2 under the inverseProperty (if the class has that property)

add_inverse_property_iri(iri: str)[source]

Add an inverse property

Parameters:

iri (str) – Iri of the inverse objectProperty

Returns:

None

is_logically_equivalent_to(object_property: ObjectProperty, vocabulary: Vocabulary, old_vocabulary: Vocabulary) bool[source]

Test if this Property in the new_vocabulary is logically equivalent to the object_property in the old_vocabulary

Parameters:
  • object_property (ObjectProperty) – ObjectProperty to be tested against, from the old vocabulary

  • vocabulary (Vocabulary) – New project vocabulary, not used but needed to keep signature the same

  • old_vocabulary (Vocabulary) – Old project vocabulary, not used but needed to keep signature the same

Returns:

bool

filip.semantics.vocabulary.relation module

Vocabulary Models for Relations

pydantic model filip.semantics.vocabulary.relation.Relation[source]

Bases: BaseModel

A Relation is defined in the source for a class. It has the form: RestrictionType property target_statement

It defines a set of allowed/required values which each instance of this class can/should have under this property

A Relation is defined in a OWL:class, but all child classes of that class inherit it

Fields:
field id: str [Required]

Unique generated Relation ID, for internal use

field property_iri: str = ''

IRI of the property (data- or object-)

field restriction_cardinality: int = -1

Only needed for min, max, equaly states the ‘n’

field restriction_type: RestrictionType = None

Restriction type of this relation

field target_statement: TargetStatement = None

Complex statement which classes/datatype_catalogue are allowed/required

export_rule(vocabulary: Vocabulary) -> (<class 'str'>, <class 'str'>)[source]

Get the rule as string

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

str

get_all_possible_target_class_iris(vocabulary: Vocabulary) Set[str][source]

Get a set of class iris that are possible values for an objectRelation

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

class_iris

Return type:

Set[str]

get_all_target_iris() Set[str][source]

Get all iris of targets

Returns:

Set(str)

get_dependency_statements(vocabulary: Vocabulary, ontology_iri: str, class_iri: str) List[DependencyStatement][source]
Get a list of all pointers/iris that are not contained in the

vocabulary Purging is done in class

Parameters:
  • vocabulary (Vocabulary) – Vocabulary of this project

  • ontology_iri (str) – IRI of the source ontology

  • class_iri (str) – IRI of class (legacy)

Returns:

List of purged statements dicts with keys:

Parent Class, class, dependency, fulfilled

Return type:

List[Dict[str, str]]

get_possible_enum_target_values(vocabulary: Vocabulary) List[str][source]

Get all allowed enum target values for a data relation

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

List[str]

get_targets() List[List[str]][source]

Get all targets specified in the target statement in AND-OR Notation

Returns:

[[a,b],[c]] either a and b needs to present, or c

Return type:

List[List[str]]

is_fulfilled_with_iris(vocabulary: Vocabulary, values: List[str], ancestor_values: List[List[str]]) bool[source]

Test if a set of values fulfills the rules of the relation

Parameters:
  • vocabulary (Vocabulary) – Vocabulary of the project

  • values (List[str]) – List of values to check

  • ancestor_values (List[List[str]]) – List containing the ancestors iris for each value (linked over index)

Returns:

bool

is_fulfilled_with_values(vocabulary: Vocabulary, values: List[str]) bool[source]

Test if a set of values fulfills the rules of the relation. Used if property is a data property

Parameters:
  • vocabulary (Vocabulary) – Vocabulary of the project

  • values (List[str]) – List of values to check

Returns:

bool

is_restriction_fulfilled(number_of_fulfilling_values: int, total_number_of_values: int) bool[source]

Test if the restriction type is fulfilled by comparing the number of fulfilling values against the total number of values given

Parameters:
  • number_of_fulfilling_values (int) – Number of values that fulfill the relation

  • total_number_of_values (int) – the number of values given for this relation

Returns:

bool

to_string(vocabulary: Vocabulary) str[source]

Get a string representation of the relation

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

str

class filip.semantics.vocabulary.relation.RestrictionType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

RestrictionTypes, as defined for OWL

exactly = 'exactly'
max = 'max'
min = 'min'
only = 'only'
some = 'some'
value = 'value'
class filip.semantics.vocabulary.relation.StatementType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

A statement is either a leaf and holds an iri/label or it is a combination of leafs with or / and

AND = 'and'
LEAF = 'leaf'
OR = 'or'
pydantic model filip.semantics.vocabulary.relation.TargetStatement[source]

Bases: BaseModel

A target statement is the statement the sits in a relation statement behind the restrictionType: E.g: consists_of some Device or Sensor. here Device or Sensor is the targetstatement as it sits behind “some”

A targetstatement is build recursively: It is either a Leaf: str or a union (or) or an intersection(and) of targetstatements

the combination of statements is purely logical and not numerical: device

and device is true as soon as one device is given, it does not need two separate devices.

Fields:
field target_data_value: str | None = None

Holds the value if the relation is a hasValue (LEAF only)

field target_iri: str = ''

The IRI of the target (LEAF only)

field target_statements: List[TargetStatement] = []

The targetstatements that are combined with this targetstatement (and/or only)

field type: StatementType = StatementType.LEAF

Statement types

get_all_targets() List[List[str]][source]

Extract possible targets out of statements interpretation: [[a,b], [c]]-> (a and b) or c -> the target needs to have ancestors(or be): (both a anb b) or c

items inside the inner brackets are connected via and the innerbrackets are all connect over or

Returns:

List[List[str]]

get_dependency_statements(vocabulary: Vocabulary, ontology_iri: str, class_iri: str) List[DependencyStatement][source]

Get a list of all pointers/iris that are not contained in the vocabulary. Purging is done in class

Parameters:
  • vocabulary (Vocabulary) – Vocabulary of this project

  • ontology_iri (str) – IRI of the source ontology

  • class_iri (str) – IRI of class (legacy)

Returns:

List of purged statements dicts with keys: Parent Class, class, dependency, fulfilled

Return type:

List[Dict[str, str]]

is_fulfilled_by_data_value(value: str, vocabulary: Vocabulary) bool[source]

Test if a set of values fulfills the targetstatement; Only for dataRelations

Parameters:
  • value (List[str]) – value to check

  • vocabulary (Vocabulary) –

Returns:

bool

is_fulfilled_by_iri_value(value: str, ancestor_values: List[str]) bool[source]

Test if a set of values fulfills the targetstatement; Only for objectRelations

Parameters:
  • value (str) – value to check: Class_iri of instance/individual

  • ancestor_values (List[List[str]]) – List containing the ancestors iris for each value (linked over index)

Returns:

bool

retrieve_label(vocabulary: Vocabulary) str[source]

Get the label of the target_iri. Only logical for Leaf statements

Parameters:

vocabulary (Vocabulary) – Vocabulary of the project

Returns:

str

set_target(target_iri: str, target_data_value: str | None = None)[source]

Set target for this statement and make it a LEAF statement

Parameters:
  • target_iri (str) – iri of the target (class or datatype iri)

  • target_data_value (str) – Value of the targetstatment if no IRI but a fixed default value is given

Returns:

None

to_string(vocabulary: Vocabulary) str[source]

Get a string representation of the targetstatment

Parameters:

vocabulary (Vocabulary) – vocabulary of the project

Returns:

str

filip.semantics.vocabulary.source module

Vocabulary Models for Ontology Sources

pydantic model filip.semantics.vocabulary.source.DependencyStatement[source]

Bases: BaseModel

Information about one dependency statement in the source A dependency is a reference of one iri in an other entity definition

Fields:
field class_iri: str [Required]

Iri of the class containing the statement

field dependency_iri: str [Required]

Entity Iri of the dependency

field fulfilled: bool [Required]

True if the dependency_iri is registered in the vocabulary

field source_iri: str = ''

Iri of the source containing the statement

field source_name: str = ''

Name of the source containing the statement

field type: str [Required]

Possible types: Parent Class, Relation Property, Relation Target

pydantic model filip.semantics.vocabulary.source.ParsingError[source]

Bases: BaseModel

Object represents one issue that arose while parsing a source, and holds all relevant details for that issue

Config:
  • use_enum_values: bool = True

Fields:
field entity_iri: str [Required]

Iri of the problematic entity

field entity_label: str | None = None

Name of the source, only set in get_function

field entity_type: str [Required]

Type of the problematic entity: Class, Individual,..ID_type in string form

field level: LogLevel [Required]

Severity of error

field message: str [Required]

Message describing the error

field source_iri: str [Required]

Iri of the source containing the error

field source_name: str | None = None

Name of the source, only set in get_function

pydantic model filip.semantics.vocabulary.source.Source[source]

Bases: BaseModel

A source represent one file that was provided via file upload or link to the project and is parsed into the vocabulary

Fields:
field content: str = ''

File content of the provided ontology file

field dependency_statements: List[DependencyStatement] = []

List of all statements in source

field id: str = ''

unique ID of the source; for internal use

field ontology_iri: str = None

Iri of the ontology of the source

field parsing_log: List[ParsingError] = []

Log containing all issues that were discovered while parsing

field predefined: bool = False

Stating if the source is a predefined source; a predefined source is added to each project containing owl:Thing and predefined Datatypes

field source_name: str = ''

Name of the source

field timestamp: datetime [Required]

timestamp when the source was added to the project

add_parsing_log_entry(level: LoggingLevel, entity_type: IdType, entity_iri: str, msg: str)[source]

Add a parsing log entry for an entity, if an issue in parsing was discovered

Parameters:
  • level (LoggingLevel) – Logging level of the entry

  • entity_type (IdType) – Type of the enitity (Class, Individual,..)

  • entity_iri (str) – iri of the entity

  • msg (str) – message to display in log

Returns:

None

clear()[source]

Clear all logging and dependency data of the source

Returns:

None

get_name() str[source]

Get the name of the source

Returns:

str

get_number_of_id_type(vocabulary: Vocabulary, id_type: IdType) int[source]

Get the number how many entities of a given type are created by or influenced by this source

Parameters:
  • vocabulary (Vocabulary) – Vocabulary of this project

  • id_type (IdType) – Idtype that should be counted

Returns:

int

get_parsing_log(vocabulary: Vocabulary) List[ParsingError][source]

Get the Parsinglog, where the labels of the entities are filled in

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

List[Dict[str, Union[LoggingLevel,’IdType’,str]]]

treat_dependency_statements(vocabulary: Vocabulary)[source]

Log and purge all pointers/iris in entities that are not contained in the vocabulary

Parameters:

vocabulary (Vocabulary) – Vocabulary of this project

Returns:

None

filip.semantics.vocabulary.vocabulary module

Main Vocabulary Model, and Submodels

class filip.semantics.vocabulary.vocabulary.IdType(value)[source]

Bases: str, Enum

Type of object that is referenced by an id/iri

class_ = 'Class'
combined_relation = 'Combined Relation'
data_property = 'Data Property'
datatype = 'Datatype'
individual = 'Individual'
object_property = 'Object Property'
relation = 'Relation'
source = 'Source'
pydantic model filip.semantics.vocabulary.vocabulary.LabelSummary[source]

Bases: BaseModel

Model holding all information for label conflicts in a vocabulary

Fields:
field blacklisted_labels: List[Tuple[str, Entity]] [Required]

All Labels that are blacklisted, Tuple(Label, Entity with label)

field class_label_duplicates: Dict[str, List[Entity]] [Required]

All Labels that are used more than once for class_names on export.Key: Label, Values: List of entities with key label

field datatype_label_duplicates: Dict[str, List[Entity]] [Required]

All Labels that are used more than once for datatype on export.Key: Label, Values: List of entities with key label

field field_label_duplicates: Dict[str, List[Entity]] [Required]

All Labels that are used more than once for property_nameson export.Key: Label, Values: List of entities with key label

field labels_with_illegal_chars: List[Tuple[str, Entity]] [Required]

All Labels that contain illegal characters, Tuple(Label, Entity with label)

is_valid() bool[source]

Test if Labels are valid

Returns:

bool, True if no entries exist

pydantic model filip.semantics.vocabulary.vocabulary.Vocabulary[source]

Bases: BaseModel

Semantic Vocabulary of a project

This class holds all objects in a vocabulary as central unit. These objects can be accessed with the according ids/iris

The vocabulary consists out of multiple sources, that each contribute objects

From the vocabulary nothing should be added or deleted manually. The sources are added and removed through the respective methods. Everything else should be used as READ-ONLY

Fields:
field classes: Dict[str, Class] = {}

Classes of the vocabulary. Key: class_iri

field combined_data_relations: Dict[str, CombinedDataRelation] = {}

CombinedDataRelations of classes in the vocabulary.Key: combined_data_id

field combined_object_relations: Dict[str, CombinedObjectRelation] = {}

CombinedObjectRelations of classes in the vocabulary. Key: combined_relation_id

field data_properties: Dict[str, DataProperty] = {}

DataProperties of the vocabulary. Key: data_property_iri

field datatypes: Dict[str, Datatype] = {}

Datatypes of the vocabulary. Key: datatype_iri

field id_types: Dict[str, IdType] = {}

Maps all entity iris and (combined)relations to their Entity/Object type, to speed up lookups

field individuals: Dict[str, Individual] = {}

Individuals in the vocabulary. Key: individual_iri

field object_properties: Dict[str, ObjectProperty] = {}

ObjectProperties of the vocabulary. Key: object_property_iri

field original_label_summary: LabelSummary | None = None

Original label after parsing, before the user made changes

field relations: Dict[str, Relation] = {}

Relations of classes in the vocabulary. Key: relation_id

field settings: VocabularySettings = VocabularySettings(pascal_case_class_labels=True, pascal_case_individual_labels=True, camel_case_property_labels=True, camel_case_datatype_labels=True, pascal_case_datatype_enum_labels=True)

Settings how to auto transform the entity labels

field sources: Dict[str, Source] = {}

Sources of the vocabulary. Key: source_id

get_all_entities() List[Entity][source]

Get all registered Entities

Returns:

List[Entity]

get_all_individuals_of_class(class_iri: str) List[Individual][source]

Get all individual that have the class_iri as parent

Parameters:

class_iri (str) – iri of parent class

Returns:

List[Individual]

static get_base_out_of_iri(iri: str)[source]

Extract out of a given iri the base aka ontology name

Parameters:

iri (str) –

Returns:

str, base of iri

get_class_by_iri(class_iri: str) Class | None[source]

Get the class belonging to the class_iri

Parameters:

class_iri (str) – iri

Returns:

Class or None if iri not a registered class

get_classes() List[Class][source]

Get all classes in this vocabulary

Returns:

List[Class]

get_classes_sorted_by_label() List[Class][source]

Get all classes sorted by their labels

Returns:

sorted classes, ascending

Return type:

List[Class]

get_combined_data_relation_by_id(id: str) CombinedDataRelation[source]

Get CombinedDataRelation by id

Parameters:

id (str) – combined_relation_id

Returns:

CombinedDataRelation

Raises:

KeyError – if id not registered as CombinedDataRelation

get_combined_object_relation_by_id(id: str) CombinedObjectRelation[source]

Get CombinedObjectRelation by id

Parameters:

id (str) – combined_relation_id

Returns:

CombinedObjectRelation

Raises:

KeyError – if id not registered as CombinedObjectRelation

get_combined_relation_by_id(id: str) CombinedRelation[source]

Get CombinedRelation by id

Parameters:

id (str) – combined_relation_id

Returns:

CombinedRelation

Raises:

KeyError – if id not registered as CombinedObjectRelation or CombinedDataRelation

get_data_properties_sorted_by_label() List[DataProperty][source]

Get all data properties of the vocabulary sorted by their labels

Returns:

List[DataProperty], sorted by ascending labels

get_data_property(data_prop_iri: str) DataProperty[source]

Get the data property belonging to the iri

Parameters:

data_prop_iri (str) – iri

Returns:

DataProperty

Raises:

KeyError – if not a registered obj property

get_datatype(datatype_iri: str) Datatype[source]

Get the datatype belonging to the iri

Parameters:

datatype_iri (str) – iri

Returns:

DataType

Raises:

KeyError – if not a registered datatype

get_datatypes_sorted_by_label() List[Datatype][source]

Get all datatypes of the vocabulary sorted by their labels

Returns:

List[Datatype], sorted by ascending labels

get_entity_by_iri(iri: str) None | Entity[source]

Get the entity with the given iri Fast efficient methode

Parameters:

iri (str) –

Returns:

Entity or None if iri does not belong to an Entity

get_entity_list_sorted_by_label(list: List[Entity]) List[Entity][source]

Sort a given entity list by their labels

Parameters:

list (List[Entity]) – entities to be sorted

Returns:

sorted list

Return type:

List[Entity]

get_enum_dataytypes() Dict[str, Datatype][source]

Get all datatypes of vocabularies that are of type ENUM

Returns:

Datatype}

Return type:

Dict[str, Datatype], {datatype.iri

get_individual(individual_iri: str) Individual[source]

Get the individual belonging to the iri

Parameters:

individual_iri (str) – iri

Returns:

Individual

Raises:

KeyError – if not a registered Individual

get_individuals_sorted_by_label() List[Individual][source]

Get all individuals of the vocabulary sorted by their labels

Returns:

List[Individual], sorted by ascending labels

get_label_for_entity_iri(iri: str) str[source]

Get the label of the entity with the given iri Fast efficient methode

Parameters:

iri (str) –

Returns:

str, “” if iri does not belong to an entity

get_object_properties_sorted_by_label() List[ObjectProperty][source]

Get all object properties of the vocabulary sorted by their labels

Returns:

List[ObjectProperty], sorted by ascending labels

get_object_property(obj_prop_iri: str) ObjectProperty[source]

Get the object property beloning to the iri

Parameters:

obj_prop_iri (str) – iri

Returns:

ObjectProperty

Raises:

KeyError – if not a registered obj property

get_relation_by_id(id: str) Relation[source]

Get Relation by relation id

Parameters:

id (str) – relation_id

Returns:

Relation

Raises:

KeyError – if id not registered as relation

get_source(source_id: str) Source[source]

Get the source with the given id

Parameters:

source_id (str) – id

Returns:

Source

Raises:

KeyError – if source_id is not registered

get_source_list() List[Source][source]

Get all source objects of the vocabulary as list

Returns:

List[Source]

get_type_of_id(id: str) IdType | None[source]

Get the type (class, relation,…) of an iri/id

Parameters:

id (str) – id/iri of which the type should be returned

Returns:

IdType or None if id/iri not registered

has_source(source_id: str) bool[source]

Test if the vocabulary contains a source with the given id

Parameters:

source_id (str) – id to test

Returns:

bool

iri_is_predefined_datatype(iri: str) bool[source]

Test if an iri belongs to a predefined datatype

Parameters:

iri (str) – Iri to test

Returns:

bool

is_id_from_individual(id: str) bool[source]

Test if an id is from an Individual. Used to distinguish between instances and individuals

Parameters:

id (str) – id

Returns:

bool

is_id_of_type(id: str, type: IdType) bool[source]

Test if an iri/id is of a given type

Parameters:
  • id (str) – id to test

  • type (str) – Type to test against

Returns:

bool

Raises:

KeyError – if id not registered

is_iri_registered(iri: str) bool[source]

Test if iri/id is registered (Entities or (Combined)relations)

Parameters:

iri (str) – iri to test

Returns:

bool

set_label_for_entity(iri: str, label: str)[source]

Set a userset label for the given entity

Parameters:
  • iri (str) – entity iri

  • label (str) – new label

Returns:

None

pydantic model filip.semantics.vocabulary.vocabulary.VocabularySettings[source]

Bases: BaseModel

Settings that state how labels of ontology entities should be automatically converted on parsing

Fields:
field camel_case_datatype_labels: bool = True

If true, convert all labels of datatypes given in the ontologies to camelCase

field camel_case_property_labels: bool = True

If true, convert all labels of properties given in the ontologies to camelCase

field pascal_case_class_labels: bool = True

If true, convert all class labels given in the ontologies to PascalCase

field pascal_case_datatype_enum_labels: bool = True

If true, convert all values of enum datatypes given in the to PascalCase

field pascal_case_individual_labels: bool = True

If true, convert all labels of individuals given in the ontologies to PascalCase

Module contents