diff --git a/vocabulary_lib/classes/class_elements.py b/vocabulary_lib/classes/class_elements.py new file mode 100644 index 0000000..8375e69 --- /dev/null +++ b/vocabulary_lib/classes/class_elements.py @@ -0,0 +1,203 @@ +from rdflib import URIRef, Graph + +from vocabulary_lib.classes.class_term import OUTerm +from vocabulary_lib.functions.func_rdf_utils import create_list_objects + +class OUCardinality: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.cardinality_value: URIRef = ontouml_model.value(object_id, OUTerm.cardinalityValue) + self.lower_bound: URIRef = ontouml_model.value(object_id, OUTerm.lowerBound) + self.upper_bound: URIRef = ontouml_model.value(object_id, OUTerm.upperBound) + +class OUClass: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.name: URIRef = ontouml_model.value(object_id, OUTerm.name) + self.attribute: list[URIRef] = create_list_objects(ontouml_model, object_id, OUTerm.attribute) + self.description: URIRef = ontouml_model.value(object_id, OUTerm.description) + self.is_abstract: URIRef = ontouml_model.value(object_id, OUTerm.isAbstract) + self.is_derived: URIRef = ontouml_model.value(object_id, OUTerm.isDerived) + self.is_powertype: URIRef = ontouml_model.value(object_id, OUTerm.isPowertype) + self.literal: URIRef = ontouml_model.value(object_id, OUTerm.literal) + self.order: URIRef = ontouml_model.value(object_id, OUTerm.order) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + self.restricted_to: list[URIRef] = create_list_objects(ontouml_model, object_id, OUTerm.restrictedTo) + self.stereotype: URIRef = ontouml_model.value(object_id, OUTerm.stereotype) + +class OUClassView: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.is_view_of: URIRef = ontouml_model.value(object_id, OUTerm.isViewOf) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + self.shape: URIRef = ontouml_model.value(object_id, OUTerm.shape) + +class OUDiagram: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.name: URIRef = ontouml_model.value(object_id, OUTerm.name) + self.containsView: list[URIRef] = create_list_objects(ontouml_model, object_id, OUTerm.containsView) + self.owner: URIRef = ontouml_model.value(object_id, OUTerm.owner) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + + + + + + + + + + +class OUGeneralization: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.general: URIRef = ontouml_model.value(object_id, OUTerm.general) + self.specific: URIRef = ontouml_model.value(object_id, OUTerm.specific) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + + +class OUGeneralizationSet: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.generalization: list[URIRef] = create_list_objects(ontouml_model, object_id, OUTerm.generalization) + self.is_complete: URIRef = ontouml_model.value(object_id, OUTerm.isComplete) + self.is_disjoint: URIRef = ontouml_model.value(object_id, OUTerm.isDisjoint) + self.name: URIRef = ontouml_model.value(object_id, OUTerm.name) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + +class OUGeneralizationSetView: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.is_view_of: URIRef = ontouml_model.value(object_id, OUTerm.isViewOf) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + self.shape: URIRef = ontouml_model.value(object_id, OUTerm.shape) + + +# TODO (@pedropaulofb): Verify which properties apply to this type +class OULiteral: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + + +class OUGeneralizationView: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.is_view_of: URIRef = ontouml_model.value(object_id, OUTerm.isViewOf) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + self.shape: URIRef = ontouml_model.value(object_id, OUTerm.shape) + self.source_view: URIRef = ontouml_model.value(object_id, OUTerm.sourceView) + self.target_view: URIRef = ontouml_model.value(object_id, OUTerm.targetView) + +class OUNote: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.text: list[URIRef] = create_list_objects(ontouml_model, object_id, OUTerm.text) + + +class OUNoteView: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.is_view_of: URIRef = ontouml_model.value(object_id, OUTerm.isViewOf) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + self.shape: URIRef = ontouml_model.value(object_id, OUTerm.shape) + self.source_view: URIRef = ontouml_model.value(object_id, OUTerm.sourceView) + self.target_view: URIRef = ontouml_model.value(object_id, OUTerm.targetView) + +class OUPackage: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.contains_model_element: list[URIRef] = create_list_objects( + ontouml_model, object_id, OUTerm.containsModelElement + ) + self.name: URIRef = ontouml_model.value(object_id, OUTerm.name) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + +class OUPackageView: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.is_view_of: URIRef = ontouml_model.value(object_id, OUTerm.isViewOf) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + self.shape: URIRef = ontouml_model.value(object_id, OUTerm.shape) + self.source_view: URIRef = ontouml_model.value(object_id, OUTerm.sourceView) + self.target_view: URIRef = ontouml_model.value(object_id, OUTerm.targetView) + +class OUPath: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.point: list[URIRef] = create_list_objects(ontouml_model, object_id, OUTerm.point) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + + +class OUPoint: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.x_coordinate: URIRef = ontouml_model.value(object_id, OUTerm.xCoordinate) + self.y_coordinate: URIRef = ontouml_model.value(object_id, OUTerm.yCoordinate) + + + + +class OUProject: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.name: URIRef = ontouml_model.value(object_id, OUTerm.name) + self.diagram: list[URIRef] = create_list_objects(ontouml_model, object_id, OUTerm.diagram) + self.model: URIRef = ontouml_model.value(object_id, OUTerm.model) + +class OUProperty: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.aggregation_kind: URIRef = ontouml_model.value(object_id, OUTerm.aggregationKind) + self.cardinality: URIRef = ontouml_model.value(object_id, OUTerm.cardinality) + self.is_derived: URIRef = ontouml_model.value(object_id, OUTerm.isDerived) + self.is_ordered: URIRef = ontouml_model.value(object_id, OUTerm.isOrdered) + self.is_read_only: URIRef = ontouml_model.value(object_id, OUTerm.isReadOnly) + self.name: URIRef = ontouml_model.value(object_id, OUTerm.name) + self.property_type: URIRef = ontouml_model.value(object_id, OUTerm.propertyType) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + +class OURectangle: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.top_left_position: URIRef = ontouml_model.value(object_id, OUTerm.topLeftPosition) + self.height: URIRef = ontouml_model.value(object_id, OUTerm.height) + self.width: URIRef = ontouml_model.value(object_id, OUTerm.width) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + +class OURelation: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.description: URIRef = ontouml_model.value(object_id, OUTerm.description) + self.is_abstract: URIRef = ontouml_model.value(object_id, OUTerm.isAbstract) + self.is_derived: URIRef = ontouml_model.value(object_id, OUTerm.isDerived) + self.name: URIRef = ontouml_model.value(object_id, OUTerm.name) + self.relation_end: list[URIRef] = create_list_objects(ontouml_model, object_id, OUTerm.relationEnd) + self.source_end: URIRef = ontouml_model.value(object_id, OUTerm.sourceEnd) + self.stereotype: URIRef = ontouml_model.value(object_id, OUTerm.stereotype) + self.target_end: URIRef = ontouml_model.value(object_id, OUTerm.targetEnd) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + + +class OURelationView: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.is_view_of: URIRef = ontouml_model.value(object_id, OUTerm.isViewOf) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + self.shape: URIRef = ontouml_model.value(object_id, OUTerm.shape) + self.source_view: URIRef = ontouml_model.value(object_id, OUTerm.sourceView) + self.target_view: URIRef = ontouml_model.value(object_id, OUTerm.targetView) + + +class OUText: + def __init__(self, ontouml_model: Graph, object_id: URIRef): + self.id: URIRef = object_id + self.height: URIRef = ontouml_model.value(object_id, OUTerm.height) + self.project: URIRef = ontouml_model.value(object_id, OUTerm.project) + self.text: URIRef = ontouml_model.value(object_id, OUTerm.text) + self.top_left_position: URIRef = ontouml_model.value(object_id, OUTerm.topLeftPosition) + self.width: URIRef = ontouml_model.value(object_id, OUTerm.width) + + + diff --git a/vocabulary_lib/classes/class_graph.py b/vocabulary_lib/classes/class_graph.py new file mode 100644 index 0000000..2cf374a --- /dev/null +++ b/vocabulary_lib/classes/class_graph.py @@ -0,0 +1,69 @@ +from rdflib import Graph + +from vocabulary_lib.classes.class_elements import ( + OUCardinality, + OUClass, + OUClassView, + OUDiagram, + OUGeneralization, + OUGeneralizationSet, + OUGeneralizationSetView, + OUGeneralizationView, + OUNote, + OUPackage, + OUPath, + OUPoint, + OUProject, + OUProperty, + OURectangle, + OURelation, + OURelationView, + OUText, + OUNoteView, +) +from vocabulary_lib.functions.func_load_specific import ( + create_list_ou_cardinality, + create_list_ou_class, + create_list_ou_classview, + create_list_ou_diagram, + create_list_ou_generalization, + create_list_ou_generalizationset, + create_list_ou_generalizationsetview, + create_list_ou_generalizationview, + create_list_ou_note, + create_list_ou_package, + create_list_ou_path, + create_list_ou_point, + create_list_ou_project, + create_list_ou_property, + create_list_ou_rectangle, + create_list_ou_relation, + create_list_ou_relationview, + create_list_ou_text, + create_list_ou_noteview, +) + + +class OUGraph: + def __init__(self, ontouml_graph: Graph): + self.list_OUCardinality: list[OUCardinality] = create_list_ou_cardinality(ontouml_graph) + self.list_OUClass: list[OUClass] = create_list_ou_class(ontouml_graph) + self.list_OUClassView: list[OUClassView] = create_list_ou_classview(ontouml_graph) + self.list_OUDiagram: list[OUDiagram] = create_list_ou_diagram(ontouml_graph) + self.list_OUGeneralization: list[OUGeneralization] = create_list_ou_generalization(ontouml_graph) + self.list_OUGeneralizationSet: list[OUGeneralizationSet] = create_list_ou_generalizationset(ontouml_graph) + self.list_OUGeneralizationSetView: list[OUGeneralizationSetView] = create_list_ou_generalizationsetview( + ontouml_graph + ) + self.list_OUGeneralizationView: list[OUGeneralizationView] = create_list_ou_generalizationview(ontouml_graph) + self.list_OUNote: list[OUNote] = create_list_ou_note(ontouml_graph) + self.list_OUNoteView: list[OUNoteView] = create_list_ou_noteview(ontouml_graph) + self.list_OUPackage: list[OUPackage] = create_list_ou_package(ontouml_graph) + self.list_OUPath: list[OUPath] = create_list_ou_path(ontouml_graph) + self.list_OUPoint: list[OUPoint] = create_list_ou_point(ontouml_graph) + self.list_OUProject: list[OUProject] = create_list_ou_project(ontouml_graph) + self.list_OUProperty: list[OUProperty] = create_list_ou_property(ontouml_graph) + self.list_OURectangle: list[OURectangle] = create_list_ou_rectangle(ontouml_graph) + self.list_OURelation: list[OURelation] = create_list_ou_relation(ontouml_graph) + self.list_OURelationView: list[OURelationView] = create_list_ou_relationview(ontouml_graph) + self.list_OUText: list[OUText] = create_list_ou_text(ontouml_graph) diff --git a/vocabulary_lib/classes/class_objects.py b/vocabulary_lib/classes/class_objects.py deleted file mode 100644 index 3d3204a..0000000 --- a/vocabulary_lib/classes/class_objects.py +++ /dev/null @@ -1,165 +0,0 @@ -from rdflib import URIRef, Graph - -from vocabulary_lib.classes.class_term import OUTerm - - -class OUProject: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.name: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.name) - self.diagram: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.diagram) - self.model: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.model) - - -class OUDiagram: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.name: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.name) - self.containsView: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.containsView) - self.owner: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.owner) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - - -class OUCardinality: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.cardinality_value: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.cardinalityValue) - self.lower_bound: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.lowerBound) - self.upper_bound: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.upperBound) - - -class OUClass: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.name: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.name) - self.attributes: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.attribute) - self.description: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.description) - self.is_abstract: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isAbstract) - self.is_derived: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isDerived) - self.is_powertype: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isPowertype) - self.order: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.order) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - self.restricted_to: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.restrictedTo) - self.stereotype: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.stereotype) - - -class OUGeneralization: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.general: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.general) - self.specific: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.specific) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - - -class OUGeneralizationSet: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.generalization: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.generalization) - self.is_complete: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isComplete) - self.is_disjoint: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isDisjoint) - self.name: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.name) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - - -class OUPackage: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.contains_model_element: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.containsModelElement) - self.name: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.name) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - - -class OUProperty: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.aggregation_kind: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.aggregationKind) - self.cardinality: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.cardinality) - self.is_derived: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isDerived) - self.is_ordered: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isOrdered) - self.is_read_only: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isReadOnly) - self.name: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.name) - self.property_type: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.propertyType) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - - -class OURelation: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.description: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.description) - self.is_abstract: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isAbstract) - self.is_derived: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isDerived) - self.name: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.name) - self.relation_end: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.relationEnd) - self.source_end: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.sourceEnd) - self.stereotype: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.stereotype) - self.target_end: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.targetEnd) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - - -class OUClassView: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.is_view_of: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isViewOf) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - self.shape: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.shape) - - -class OUGeneralizationSetView: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.is_view_of: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isViewOf) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - self.shape: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.shape) - - -class OUGeneralizationView: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.is_view_of: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isViewOf) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - self.shape: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.shape) - self.source_view: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.sourceView) - self.target_view: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.targetView) - - -class OURelationView: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.is_view_of: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.isViewOf) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - self.shape: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.shape) - self.source_view: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.sourceView) - self.target_view: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.targetView) - - -class OUPath: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.point: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.point) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - - -class OUPoint: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.x_coordinate: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.xCoordinate) - self.y_coordinate: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.yCoordinate) - - -class OURectangle: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.top_left_position: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.topLeftPosition) - self.height: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.height) - self.width: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.width) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - - -class OUText: - def __init__(self, ontouml_model: Graph, object_id: URIRef): - self.id: URIRef = object_id - self.height: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.height) - self.project: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.project) - self.text: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.text) - self.top_left_position: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.topLeftPosition) - self.width: URIRef = ou_get_element(ontouml_model, object_id, OUTerm.width) diff --git a/vocabulary_lib/functions/func_class.py b/vocabulary_lib/functions/func_class.py index fff80a7..1f13f62 100644 --- a/vocabulary_lib/functions/func_class.py +++ b/vocabulary_lib/functions/func_class.py @@ -3,58 +3,58 @@ from vocabulary_lib.classes.class_term import OUTerm -def ou_get_direct_superclasses(ontouml_graph: Graph, ontouml_class: URIRef) -> list[URIRef]: - """Retrieve direct superclasses of a specified OntoUML class from a given OntoUML RDF graph. +def ou_get_direct_superclasses(ontouml_graph: Graph, ou_class_id: URIRef) -> list[URIRef]: + """Retrieve a list of IDs (as URIRefs) of the direct superclasses of a specified OntoUML class from a given OntoUML RDF graph. Allows the user to specify a list of restricted types. Superclasses of those types will not be included in the returned list. :param ontouml_graph: The RDF graph containing OntoUML model data. :type ontouml_graph: rdflib.Graph - :param ontouml_class: The URI of the OntoUML class for which to retrieve superclasses. - :type ontouml_class: str + :param ou_class_id: The URI of the OntoUML class for which to retrieve superclasses. + :type ou_class_id: str :return: A list of URIRefs representing the direct superclasses of the specified OntoUML class. The list may be empty. :rtype: list[URIRef] """ superclasses: list[URIRef] = [] - for gen in ontouml_graph.subjects(OUTerm.specific, ontouml_class): + for gen in ontouml_graph.subjects(OUTerm.specific, ou_class_id): for superclass in ontouml_graph.objects(gen, OUTerm.general): superclasses.append(superclass) return superclasses -def ou_get_direct_subclasses(ontouml_graph: Graph, ontouml_class: URIRef) -> list[URIRef]: - """Retrieve direct subclasses of a specified OntoUML class from a given OntoUML RDF graph. +def ou_get_direct_subclasses(ontouml_graph: Graph, ou_class_id: URIRef) -> list[URIRef]: + """Retrieve a list of IDs (as URIRefs) of the direct subclasses of a specified OntoUML class from a given OntoUML RDF graph. :param ontouml_graph: The RDF graph containing OntoUML model data. :type ontouml_graph: rdflib.Graph - :param ontouml_class: The URI of the OntoUML class for which to retrieve subclasses. - :type ontouml_class: str + :param ou_class_id: The URI of the OntoUML class for which to retrieve subclasses. + :type ou_class_id: str :return: A list of URIRefs representing the direct subclasses of the specified OntoUML class. :rtype: list[URIRef] """ subclasses: list[URIRef] = [] - for gen in ontouml_graph.subjects(OUTerm.general, ontouml_class): + for gen in ontouml_graph.subjects(OUTerm.general, ou_class_id): for subclass in ontouml_graph.objects(gen, OUTerm.specific): subclasses.append(subclass) return subclasses -def ou_get_all_superclasses(ontouml_graph: Graph, ontouml_class: URIRef) -> list[URIRef]: - """Retrieve all (direct and indirect) superclasses of a specified OntoUML class from a given OntoUML RDF graph. +def ou_get_all_superclasses(ontouml_graph: Graph, ou_class_id: URIRef) -> list[URIRef]: + """Retrieve a list of IDs (as URIRefs) of the all (direct and indirect) superclasses of a specified OntoUML class from a given OntoUML RDF graph. :param ontouml_graph: The RDF graph containing OntoUML model data. :type ontouml_graph: Graph - :param ontouml_class: The URI of the OntoUML class for which to retrieve superclasses. - :type ontouml_class: URIRef + :param ou_class_id: The URI of the OntoUML class for which to retrieve superclasses. + :type ou_class_id: URIRef :return: A list of URIRefs representing the direct superclasses of the specified OntoUML class. :rtype: list[URIRef] """ - direct_super = ou_get_direct_superclasses(ontouml_graph, ontouml_class) + direct_super = ou_get_direct_superclasses(ontouml_graph, ou_class_id) all_superclasses = [] all_superclasses.extend(direct_super) @@ -65,17 +65,17 @@ def ou_get_all_superclasses(ontouml_graph: Graph, ontouml_class: URIRef) -> list return all_superclasses -def ou_get_all_subclasses(ontouml_graph: Graph, ontouml_class: URIRef) -> list[URIRef]: - """Retrieve all (direct and indirect) subclasses of a specified OntoUML class from a given OntoUML RDF graph. +def ou_get_all_subclasses(ontouml_graph: Graph, ou_class_id: URIRef) -> list[URIRef]: + """Retrieve a list of IDs (as URIRefs) of the all (direct and indirect) subclasses of a specified OntoUML class from a given OntoUML RDF graph. :param ontouml_graph: The RDF graph containing OntoUML model data. :type ontouml_graph: rdflib.Graph - :param ontouml_class: The URI of the OntoUML class for which to retrieve subclasses. - :type ontouml_class: URIRef + :param ou_class_id: The URI of the OntoUML class for which to retrieve subclasses. + :type ou_class_id: URIRef :return: A list of URIRefs representing the direct subclasses of the specified OntoUML class. :rtype: list[URIRef] """ - direct_sub = ou_get_direct_subclasses(ontouml_graph, ontouml_class) + direct_sub = ou_get_direct_subclasses(ontouml_graph, ou_class_id) all_subclasses = [] all_subclasses.extend(direct_sub) diff --git a/vocabulary_lib/functions/func_general.py b/vocabulary_lib/functions/func_general.py deleted file mode 100644 index e69de29..0000000 diff --git a/vocabulary_lib/functions/func_load_specific.py b/vocabulary_lib/functions/func_load_specific.py new file mode 100644 index 0000000..3630e5c --- /dev/null +++ b/vocabulary_lib/functions/func_load_specific.py @@ -0,0 +1,196 @@ +from rdflib import Graph, RDF + +from vocabulary_lib.classes.class_elements import ( + OUCardinality, + OUClass, + OUClassView, + OUDiagram, + OUGeneralization, + OUGeneralizationSet, + OUGeneralizationView, + OUGeneralizationSetView, + OUNote, + OUPackage, + OUPath, + OUPoint, + OUProject, + OUProperty, + OURectangle, + OURelation, + OURelationView, + OUText, + OUNoteView, +) +from vocabulary_lib.classes.class_term import OUTerm +from vocabulary_lib.functions.func_rdf_utils import create_list_subjects + + +def create_list_ou_cardinality(ontouml_graph: Graph) -> list[OUCardinality]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Cardinality) + for element in all_elements: + element_obj = OUCardinality(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_class(ontouml_graph: Graph) -> list[OUClass]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Class) + for element in all_elements: + element_obj = OUClass(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_classview(ontouml_graph: Graph) -> list[OUClassView]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.ClassView) + for element in all_elements: + element_obj = OUClassView(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_diagram(ontouml_graph: Graph) -> list[OUDiagram]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Diagram) + for element in all_elements: + element_obj = OUDiagram(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_generalization(ontouml_graph: Graph) -> list[OUGeneralization]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Generalization) + for element in all_elements: + element_obj = OUGeneralization(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_generalizationset(ontouml_graph: Graph) -> list[OUGeneralizationSet]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.GeneralizationSet) + for element in all_elements: + element_obj = OUGeneralizationSet(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_generalizationsetview(ontouml_graph: Graph) -> list[OUGeneralizationSetView]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.GeneralizationSetView) + for element in all_elements: + element_obj = OUGeneralizationSetView(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_generalizationview(ontouml_graph: Graph) -> list[OUGeneralizationView]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.GeneralizationView) + for element in all_elements: + element_obj = OUGeneralizationView(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_note(ontouml_graph: Graph) -> list[OUNote]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Note) + for element in all_elements: + element_obj = OUNote(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_noteview(ontouml_graph: Graph) -> list[OUNoteView]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.NoteView) + for element in all_elements: + element_obj = OUNoteView(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_package(ontouml_graph: Graph) -> list[OUPackage]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Package) + for element in all_elements: + element_obj = OUPackage(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_path(ontouml_graph: Graph) -> list[OUPath]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Path) + for element in all_elements: + element_obj = OUPath(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_point(ontouml_graph: Graph) -> list[OUPoint]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Point) + for element in all_elements: + element_obj = OUPoint(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_project(ontouml_graph: Graph) -> list[OUProject]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Project) + for element in all_elements: + element_obj = OUProject(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_property(ontouml_graph: Graph) -> list[OUProperty]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Property) + for element in all_elements: + element_obj = OUProperty(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_rectangle(ontouml_graph: Graph) -> list[OURectangle]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Rectangle) + for element in all_elements: + element_obj = OURectangle(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_relation(ontouml_graph: Graph) -> list[OURelation]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Relation) + for element in all_elements: + element_obj = OURelation(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_relationview(ontouml_graph: Graph) -> list[OURelationView]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.RelationView) + for element in all_elements: + element_obj = OURelationView(element) + list_elements.append(element_obj) + return list_elements + + +def create_list_ou_text(ontouml_graph: Graph) -> list[OUText]: + list_elements = [] + all_elements = create_list_subjects(ontouml_graph, RDF.type, OUTerm.Text) + for element in all_elements: + element_obj = OUText(element) + list_elements.append(element_obj) + return list_elements diff --git a/vocabulary_lib/functions/func_rdf_utils.py b/vocabulary_lib/functions/func_rdf_utils.py index 94cb1f3..9682980 100644 --- a/vocabulary_lib/functions/func_rdf_utils.py +++ b/vocabulary_lib/functions/func_rdf_utils.py @@ -1,28 +1,28 @@ from rdflib import Graph, URIRef -def create_list_subjects(graph: Graph, predicate: URIRef, object: URIRef) -> list[URIRef]: +def create_list_subjects(graph: Graph, graph_predicate: URIRef, graph_object: URIRef) -> list[URIRef]: return_list = [] - for element in graph.subjects(predicate, object): + for element in graph.subjects(graph_predicate, graph_object): return_list.append(element) return return_list -def create_list_predicates(graph: Graph, subject: URIRef, object: URIRef) -> list[URIRef]: +def create_list_predicates(graph: Graph, graph_subject: URIRef, graph_object: URIRef) -> list[URIRef]: return_list = [] - for element in graph.predicates(subject, object): + for element in graph.predicates(graph_subject, graph_object): return_list.append(element) return return_list -def create_list_objects(graph: Graph, subject: URIRef, predicate: URIRef) -> list[URIRef]: +def create_list_objects(graph: Graph, graph_subject: URIRef, graph_predicate: URIRef) -> list[URIRef]: return_list = [] - for element in graph.objects(subject, predicate): + for element in graph.objects(graph_subject, graph_predicate): return_list.append(element) return return_list