Skip to content

Commit

Permalink
OUGraph re-implemented for better performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropaulofb committed Oct 2, 2023
1 parent da5f775 commit 41cbc33
Show file tree
Hide file tree
Showing 7 changed files with 955 additions and 930 deletions.
28 changes: 14 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ repos:
hooks:
- id: black
args: [ --line-length=120 ]
# - repo: https://github.com/PyCQA/flake8
# rev: 6.1.0
# hooks:
# - id: flake8
# args: [ --max-line-length=120 ]
# - repo: https://github.com/pycqa/pydocstyle
# rev: 6.3.0
# hooks:
# - id: pydocstyle
# name: pydocstyle
# description: pydocstyle is a static analysis tool for checking compliance with Python docstring conventions.
# entry: pydocstyle
# language: python
# types: [ python ]
# - repo: https://github.com/PyCQA/flake8
# rev: 6.1.0
# hooks:
# - id: flake8
# args: [ --max-line-length=120 ]
# - repo: https://github.com/pycqa/pydocstyle
# rev: 6.3.0
# hooks:
# - id: pydocstyle
# name: pydocstyle
# description: pydocstyle is a static analysis tool for checking compliance with Python docstring conventions.
# entry: pydocstyle
# language: python
# types: [ python ]
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
rev: v1.3.2
hooks:
Expand Down
1,676 changes: 838 additions & 838 deletions poetry.lock

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions vocabulary_lib/classes/class_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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
Expand All @@ -25,13 +27,15 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -41,14 +45,6 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -66,6 +62,7 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -74,7 +71,6 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -90,6 +86,7 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -105,6 +102,7 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -114,6 +112,7 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -123,6 +122,7 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -137,15 +137,14 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -158,6 +157,7 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand All @@ -166,6 +166,7 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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
Expand Down Expand Up @@ -198,6 +199,3 @@ def __init__(self, ontouml_model: Graph, object_id: URIRef):
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)



114 changes: 71 additions & 43 deletions vocabulary_lib/classes/class_graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rdflib import Graph
from loguru import logger
from rdflib import Graph, RDF

from vocabulary_lib.classes.class_elements import (
OUCardinality,
Expand All @@ -20,50 +21,77 @@
OURelationView,
OUText,
OUNoteView,
OULiteral,
)
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,
)
from vocabulary_lib.classes.class_term import OUTerm


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)
self.list_OUCardinality = []
self.list_OUClass = []
self.list_OUClassView = []
self.list_OUDiagram = []
self.list_OUGeneralization = []
self.list_OUGeneralizationSet = []
self.list_OUGeneralizationSetView = []
self.list_OUGeneralizationView = []
self.list_OULiteral = []
self.list_OUNote = []
self.list_OUNoteView = []
self.list_OUPackage = []
self.list_OUPath = []
self.list_OUPoint = []
self.list_OUProject = []
self.list_OUProperty = []
self.list_OURectangle = []
self.list_OURelation = []
self.list_OURelationView = []
self.list_OUText = []

for s, _, o in ontouml_graph.triples((None, RDF.type, None)):
if o == OUTerm.Cardinality:
self.list_OUCardinality.append(OUCardinality(ontouml_graph, s))
elif o == OUTerm.Class:
self.list_OUClass.append(OUClass(ontouml_graph, s))
elif o == OUTerm.ClassView:
self.list_OUClassView.append(OUClassView(ontouml_graph, s))
elif o == OUTerm.Diagram:
self.list_OUDiagram.append(OUDiagram(ontouml_graph, s))
elif o == OUTerm.Generalization:
self.list_OUGeneralization.append(OUGeneralization(ontouml_graph, s))
elif o == OUTerm.GeneralizationSet:
self.list_OUGeneralizationSet.append(OUGeneralizationSet(ontouml_graph, s))
elif o == OUTerm.GeneralizationSetView:
self.list_OUGeneralizationSetView.append(OUGeneralizationSetView(ontouml_graph, s))
elif o == OUTerm.GeneralizationView:
self.list_OUGeneralizationView.append(OUGeneralizationView(ontouml_graph, s))
elif o == OUTerm.Literal:
self.list_OULiteral.append(OULiteral(ontouml_graph, s))
elif o == OUTerm.Note:
self.list_OUNote.append(OUNote(ontouml_graph, s))
elif o == OUTerm.NoteView:
self.list_OUNoteView.append(OUNoteView(ontouml_graph, s))
elif o == OUTerm.Package:
self.list_OUPackage.append(OUPackage(ontouml_graph, s))
elif o == OUTerm.Path:
self.list_OUPath.append(OUPath(ontouml_graph, s))
elif o == OUTerm.Point:
self.list_OUPoint.append(OUPoint(ontouml_graph, s))
elif o == OUTerm.Project:
self.list_OUProject.append(OUProject(ontouml_graph, s))
elif o == OUTerm.Property:
self.list_OUProperty.append(OUProperty(ontouml_graph, s))
elif o == OUTerm.Rectangle:
self.list_OURectangle.append(OURectangle(ontouml_graph, s))
elif o == OUTerm.Relation:
self.list_OURelation.append(OURelation(ontouml_graph, s))
elif o == OUTerm.RelationView:
self.list_OURelationView.append(OURelationView(ontouml_graph, s))
elif o == OUTerm.Text:
self.list_OUText.append(OUText(ontouml_graph, s))
else:
logger.warning(
f"Graph's element {s} of type {o} was not loaded into any OUGraph's list "
f"because it is not an OntoUML element."
)
1 change: 0 additions & 1 deletion vocabulary_lib/classes/class_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,4 @@ class OUTerm(DefinedNamespace):

_NS = Namespace(ONTOUML_NAMESPACE)


# 17 classes 93 att
2 changes: 1 addition & 1 deletion vocabulary_lib/constants/const_st_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
OU_CLASS_ST_SEMI_RIGIDS = [OUTerm.mixin]

OU_CLASS_ST_ALL = (
OU_CLASS_ST_SORTALS + OU_CLASS_ST_NON_SORTALS + OU_CLASS_ST_ABSTRACTS + [OUTerm.event, OUTerm.situation]
OU_CLASS_ST_SORTALS + OU_CLASS_ST_NON_SORTALS + OU_CLASS_ST_ABSTRACTS + [OUTerm.event, OUTerm.situation]
)
Loading

0 comments on commit 41cbc33

Please sign in to comment.