Skip to content

Commit

Permalink
Model Repository Parser for UML Diagrams (#144)
Browse files Browse the repository at this point in the history
* Model Repository Parser for UML Diagrams
  • Loading branch information
ismonnar authored Jun 13, 2024
1 parent 49b2894 commit e66a123
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
48 changes: 48 additions & 0 deletions fedot_ind/tools/uml/uml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import re
import os

from fedot_ind.api.utils.path_lib import DEFAULT_PATH_MODELS

with open(DEFAULT_PATH_MODELS, 'r') as file:
file_content = [string for string in file.read().split("\n") if not string.startswith("from")]
file_content = file_content[:next((i for i, line in enumerate(file_content) if line.startswith("def")), None)]
file_content = file_content[next((i for i, line in enumerate(file_content) if line == '}'), None) + 1:]

pattern = re.compile(r'\b[A-Z_]+\b')

substrings = []
for s in file_content:
matches = pattern.findall(s)
substrings.extend(matches)
substrings = list(set(substrings))

res = ["@startuml", "'https://plantuml.com/sequence-diagram", "", "class AtomizedModel {", " Enum", "}", ""]
for ind in substrings:
res += ["abstract " + ind]
res += ["", ""]

res += ["INDUSTRIAL_CLF_PREPROC_MODEL --> AtomizedModel",
"AtomizedModel <-- SKLEARN_CLF_MODELS",
"FEDOT_PREPROC_MODEL --> AtomizedModel",
"AtomizedModel <- INDUSTRIAL_PREPROC_MODEL",
"SKLEARN_REG_MODELS --> AtomizedModel",
"AtomizedModel <-- FORECASTING_MODELS",
"FORECASTING_PREPROC -> AtomizedModel",
"NEURAL_MODEL -> AtomizedModel", ""]

for ind in substrings:
start_index = next((i for i, line in enumerate(file_content) if line.endswith(ind + " = {")), None)
end_index = next((i for i, line in enumerate(file_content[start_index:]) if line.endswith("}")),
None) + 1 + start_index
list_of_strings = file_content[start_index:end_index]
pattern = re.compile(r"': ([^']*)")
formatted_strings = [pattern.search(string).group(1) if pattern.search(string) else ""
for string in list_of_strings]
res = res + ["abstract " + ind + " {"] + [string for string in formatted_strings if
string.strip() and string.strip() != "{"] + ["}", ""]

with open('your_file.puml', 'w') as f:
for line in res + ["@enduml"]:
f.write(f"{line}\n")

os.system('python -m plantuml your_file.puml')
Binary file added fedot_ind/tools/uml/your_file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions fedot_ind/tools/uml/your_file.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
@startuml
'https://plantuml.com/sequence-diagram

class AtomizedModel {
Enum
}

abstract FEDOT_PREPROC_MODEL
abstract NEURAL_MODEL
abstract INDUSTRIAL_PREPROC_MODEL
abstract SKLEARN_CLF_MODELS
abstract INDUSTRIAL_CLF_PREPROC_MODEL
abstract SKLEARN_REG_MODELS
abstract FORECASTING_PREPROC
abstract FORECASTING_MODELS


INDUSTRIAL_CLF_PREPROC_MODEL --> AtomizedModel
AtomizedModel <-- SKLEARN_CLF_MODELS
FEDOT_PREPROC_MODEL --> AtomizedModel
AtomizedModel <- INDUSTRIAL_PREPROC_MODEL
SKLEARN_REG_MODELS --> AtomizedModel
AtomizedModel <-- FORECASTING_MODELS
FORECASTING_PREPROC -> AtomizedModel
NEURAL_MODEL -> AtomizedModel

abstract FEDOT_PREPROC_MODEL {
ScalingImplementation,
NormalizationImplementation,
ImputationImplementation,
KernelPCAImplementation,
TopologicalFeaturesImplementation
}

abstract NEURAL_MODEL {
InceptionTimeModel,
OmniScaleModel,
ResNetModel,
NBeatsModel,
TSTModel,
XCModel,
DummyOverComplicatedNeuralNetwork,
LoraModel
}

abstract INDUSTRIAL_PREPROC_MODEL {
ChannelCentroidFilter,
EigenBasisImplementation,
WaveletBasisImplementation,
FourierBasisImplementation,
RecurrenceExtractor,
QuantileExtractor,
RiemannExtractor,
TopologicalFeaturesImplementation,
MiniRocketExtractor,
ChronosExtractor,
IsolationForestClassImplementation,
IsolationForestRegImplementation,
}

abstract SKLEARN_CLF_MODELS {
GradientBoostingClassifier,
SklearnLogReg,
DecisionTreeClassifier,
RandomForestClassifier,
MLPClassifier,
LGBMClassifier
}

abstract INDUSTRIAL_CLF_PREPROC_MODEL {
DecomposerClassImplementation,
ResampleImplementation,
}

abstract SKLEARN_REG_MODELS {
XGBRegressor,
SklearnSGD,
ExtraTreesRegressor,
SklearnRidgeReg,
SklearnLassoReg,
DecisionTreeRegressor,
LGBMRegressor,
}

abstract FORECASTING_PREPROC {
LaggedTransformationImplementation,
SparseLaggedTransformationImplementation,
TsSmoothingImplementation,
GaussianFilterImplementation,
ExogDataTransformationImplementation,
}

abstract FORECASTING_MODELS {
AutoRegImplementation,
STLForecastARIMAImplementation,
ExpSmoothingImplementation,
CGRUImplementation,
GLMIndustrial
}

@enduml

0 comments on commit e66a123

Please sign in to comment.