From 893fa12818772eb782de3b1e24ebb6aacd3546d9 Mon Sep 17 00:00:00 2001 From: Marc Maynou Date: Mon, 15 Jul 2024 17:35:25 +0200 Subject: [PATCH] Changed ontology generation (addedd NN) --- .../api/functions.py | 20 +--- .../ontology_populator/cbox_generator.py | 2 + .../implementations/knime/__init__.py | 8 ++ .../implementations/knime/nn.py | 109 ++++++++++++++++++ 4 files changed, 123 insertions(+), 16 deletions(-) create mode 100644 Modules/IntentSpecification2WorkflowGenerator/ontology_populator/implementations/knime/nn.py diff --git a/Modules/IntentSpecification2WorkflowGenerator/api/functions.py b/Modules/IntentSpecification2WorkflowGenerator/api/functions.py index 8a2a92af..05fe076d 100644 --- a/Modules/IntentSpecification2WorkflowGenerator/api/functions.py +++ b/Modules/IntentSpecification2WorkflowGenerator/api/functions.py @@ -167,14 +167,8 @@ def get_custom_ontology(path): graph = get_graph_xp() ontologies = [ r'ontologies/tbox.ttl', - # r'ontologies/cbox.ttl', - # r'ontologies/abox.ttl', - - # r'ontologies/cbox_new.ttl', - # r'ontologies/abox_new.ttl', - - r'ontologies/cbox_new_2.ttl', - r'ontologies/abox_new_2.ttl', + r'ontologies/cbox.ttl', + r'ontologies/abox.ttl', path ] for o in ontologies: @@ -187,14 +181,8 @@ def get_custom_ontology_only_problems(): graph = get_graph_xp() ontologies = [ r'ontologies/tbox.ttl', - # r'ontologies/cbox.ttl', - # r'ontologies/abox.ttl', - - # r'ontologies/cbox_new.ttl', - # r'ontologies/abox_new.ttl', - - r'ontologies/cbox_new_2.ttl', - r'ontologies/abox_new_2.ttl', + r'ontologies/cbox.ttl', + r'ontologies/abox.ttl', ] for o in ontologies: graph.parse(o, format="turtle") diff --git a/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/cbox_generator.py b/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/cbox_generator.py index 9ed43a58..ed532b04 100644 --- a/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/cbox_generator.py +++ b/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/cbox_generator.py @@ -57,6 +57,7 @@ def add_algorithms(cbox): (cb.NaiveBayes, cb.Classification), (cb.SVM, cb.Classification), (cb.KNN, cb.Classification), + (cb.NN, cb.Classification), # Anomaly Detection (cb.OneClassSVM, cb.AnomalyDetection), @@ -110,6 +111,7 @@ def add_models(cbox): 'DecisionTreeModel', 'NormalizerModel', 'MissingValueModel', + 'NNModel', ] cbox.add((cb.Model, RDFS.subClassOf, tb.Data)) diff --git a/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/implementations/knime/__init__.py b/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/implementations/knime/__init__.py index 44e90c9d..826890d3 100644 --- a/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/implementations/knime/__init__.py +++ b/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/implementations/knime/__init__.py @@ -3,6 +3,7 @@ from .normalization import * from .decision_tree import * from .svm import * +from .nn import * from .missing_values import * from .csv_io import * @@ -18,6 +19,8 @@ missing_value_applier_implementation, csv_reader_implementation, csv_writer_implementation, + nn_learner_implementation, + nn_predictor_implementation, ] components = [ @@ -40,4 +43,9 @@ missing_value_applier_component, csv_reader_local_component, csv_writer_local_component, + feedforward_learner_component, + recurrent_learner_component, + convolutional_learner_component, + lstm_learner_component, + nn_predictor_component, ] diff --git a/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/implementations/knime/nn.py b/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/implementations/knime/nn.py new file mode 100644 index 00000000..a9dceb25 --- /dev/null +++ b/Modules/IntentSpecification2WorkflowGenerator/ontology_populator/implementations/knime/nn.py @@ -0,0 +1,109 @@ +from common import * +from .knime_implementation import KnimeImplementation, KnimeBaseBundle, KnimeParameter +from ..core import * + +nn_learner_implementation = KnimeImplementation( + name='NN Learner', + algorithm=cb.NN, + parameters=[ + KnimeParameter("Class column", XSD.string, "$$LABEL$$", 'classcol'), + KnimeParameter("NN type", XSD.string, None, 'nn_type'), + ], + input=[ + [cb.LabeledTabularDatasetShape, cb.NormalizedTabularDatasetShape, cb.NonNullTabularDatasetShape], + ], + output=[ + cb.NNModel, + ], + implementation_type=tb.LearnerImplementation, + knime_node_factory='org.knime.base.node.mine.svm.predictor2.SVMPredictorNodeFactory', + knime_bundle=KnimeBaseBundle, +) + +feedforward_learner_component = Component( + name='FeedForward NN Learner', + implementation=nn_learner_implementation, + overriden_parameters=[ + ('NN type', 'FeedForward'), + ], + exposed_parameters=[ + 'Class column' + ], + transformations=[ + ], +) + +recurrent_learner_component = Component( + name='Recurrent NN Learner', + implementation=nn_learner_implementation, + overriden_parameters=[ + ('NN type', 'Recurrent'), + ], + exposed_parameters=[ + 'Class column' + ], + transformations=[ + ], +) + +convolutional_learner_component = Component( + name='Convolutional NN Learner', + implementation=nn_learner_implementation, + overriden_parameters=[ + ('NN type', 'Convolutional'), + ], + exposed_parameters=[ + 'Class column' + ], + transformations=[ + ], +) + +lstm_learner_component = Component( + name='LSTM NN Learner', + implementation=nn_learner_implementation, + overriden_parameters=[ + ('NN type', 'LSTM'), + ], + exposed_parameters=[ + 'Class column' + ], + transformations=[ + ], +) + +nn_predictor_implementation = KnimeImplementation( + name='NN Predictor', + algorithm=cb.NN, + parameters=[ + KnimeParameter("Prediction column name", XSD.string, "Prediction ($$LABEL$$)", 'prediction column name'), + KnimeParameter("Change prediction", XSD.boolean, False, 'change prediction'), + KnimeParameter("Add probabilities", XSD.boolean, False, 'add probabilities'), + KnimeParameter("Class probability suffix", XSD.string, "", 'class probability suffix'), + ], + input=[ + cb.NNModel, + [cb.NormalizedTabularDatasetShape, cb.NonNullTabularDatasetShape] + ], + output=[ + cb.LabeledTabularDatasetShape, + ], + implementation_type=tb.ApplierImplementation, + counterpart=nn_learner_implementation, + knime_node_factory='org.knime.base.node.mine.svm.predictor2.SVMPredictorNodeFactory', + knime_bundle=KnimeBaseBundle, +) + +nn_predictor_component = Component( + name='NN Predictor', + implementation=nn_predictor_implementation, + transformations=[ + + ], + counterpart=[ + feedforward_learner_component, + recurrent_learner_component, + convolutional_learner_component, + lstm_learner_component + ], +)