From 258e8d3c7d4c23200eb5485d3450ada871d847af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Fuch=C3=9F?= Date: Fri, 29 Nov 2024 20:48:13 +0100 Subject: [PATCH] Remove global configuration --- ...xtractionDependentOccurrenceInformant.java | 20 ++++---- .../InstantConnectionInformant.java | 16 +++--- .../NameTypeConnectionInformant.java | 50 +++++++++---------- .../informants/ProjectNameInformant.java | 29 +++++------ .../informants/ReferenceInformant.java | 11 ++-- .../DefaultRecommendationStateStrategy.java | 11 ++-- .../RecommendationGenerator.java | 4 +- .../RecommendationStatesImpl.java | 9 ++-- .../CompoundRecommendationInformant.java | 34 +++++++------ .../informants/NameTypeInformant.java | 36 ++++++------- .../DefaultTextStateStrategy.java | 21 +++----- .../OriginalTextStateStrategy.java | 19 +++---- .../PhraseConcerningTextStateStrategy.java | 18 ++++--- .../tlr/textextraction/TextExtraction.java | 2 +- .../informants/MappingCombinerInformant.java | 23 +++++---- .../agents/MappingCombinerTest.java | 11 ++-- 16 files changed, 156 insertions(+), 158 deletions(-) diff --git a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ExtractionDependentOccurrenceInformant.java b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ExtractionDependentOccurrenceInformant.java index 211a977..7a95311 100644 --- a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ExtractionDependentOccurrenceInformant.java +++ b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ExtractionDependentOccurrenceInformant.java @@ -8,6 +8,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.MappingKind; import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.TextState; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -28,12 +29,12 @@ public ExtractionDependentOccurrenceInformant(DataRepository dataRepository) { @Override public void process() { - DataRepository dataRepository = getDataRepository(); + DataRepository dataRepository = this.getDataRepository(); var text = DataRepositoryHelper.getAnnotatedText(dataRepository); var textState = DataRepositoryHelper.getTextState(dataRepository); var modelStates = DataRepositoryHelper.getModelStatesData(dataRepository); for (var word : text.words()) { - exec(textState, modelStates, word); + this.exec(textState, modelStates, word); } } @@ -41,8 +42,8 @@ private void exec(TextState textState, ModelStates modelStates, Word word) { for (var model : modelStates.modelIds()) { var modelState = modelStates.getModelExtractionState(model); - searchForName(modelState, textState, word); - searchForType(modelState, textState, word); + this.searchForName(modelState, textState, word); + this.searchForType(modelState, textState, word); } } @@ -51,12 +52,12 @@ private void exec(TextState textState, ModelStates modelStates, Word word) { * appears to be a name this is stored in the text extraction state. */ private void searchForName(LegacyModelExtractionState modelState, TextState textState, Word word) { - if (posTagIsUndesired(word) && !wordStartsWithCapitalLetter(word)) { + if (this.posTagIsUndesired(word) && !this.wordStartsWithCapitalLetter(word)) { return; } - var instanceNameIsSimilar = modelState.getInstances().anySatisfy(i -> getMetaData().getSimilarityUtils().isWordSimilarToModelInstance(word, i)); + var instanceNameIsSimilar = modelState.getInstances().anySatisfy(i -> SimilarityUtils.getInstance().isWordSimilarToModelInstance(word, i)); if (instanceNameIsSimilar) { - textState.addNounMapping(word, MappingKind.NAME, this, probability); + textState.addNounMapping(word, MappingKind.NAME, this, this.probability); } } @@ -74,10 +75,9 @@ private boolean posTagIsUndesired(Word word) { * value is taken as reference. */ private void searchForType(LegacyModelExtractionState modelState, TextState textState, Word word) { - var similarityUtils = getMetaData().getSimilarityUtils(); - var instanceTypeIsSimilar = modelState.getInstances().anySatisfy(i -> similarityUtils.isWordSimilarToModelInstanceType(word, i)); + var instanceTypeIsSimilar = modelState.getInstances().anySatisfy(i -> SimilarityUtils.getInstance().isWordSimilarToModelInstanceType(word, i)); if (instanceTypeIsSimilar) { - textState.addNounMapping(word, MappingKind.TYPE, this, probability); + textState.addNounMapping(word, MappingKind.TYPE, this, this.probability); } } diff --git a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/InstantConnectionInformant.java b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/InstantConnectionInformant.java index a8880c5..adba3be 100644 --- a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/InstantConnectionInformant.java +++ b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/InstantConnectionInformant.java @@ -8,6 +8,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.legacy.ModelInstance; import edu.kit.kastel.mcse.ardoco.core.api.stage.connectiongenerator.ConnectionState; import edu.kit.kastel.mcse.ardoco.core.api.stage.recommendationgenerator.RecommendationState; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -25,7 +26,7 @@ public InstantConnectionInformant(DataRepository dataRepository) { @Override public void process() { - DataRepository dataRepository = getDataRepository(); + DataRepository dataRepository = this.getDataRepository(); var modelStates = DataRepositoryHelper.getModelStatesData(dataRepository); var recommendationStates = DataRepositoryHelper.getRecommendationStates(dataRepository); var connectionStates = DataRepositoryHelper.getConnectionStates(dataRepository); @@ -35,8 +36,8 @@ public void process() { var recommendationState = recommendationStates.getRecommendationState(metamodel); var connectionState = connectionStates.getConnectionState(metamodel); - findNamesOfModelInstancesInSupposedMappings(modelState, recommendationState, connectionState); - createLinksForEqualOrSimilarRecommendedInstances(modelState, recommendationState, connectionState); + this.findNamesOfModelInstancesInSupposedMappings(modelState, recommendationState, connectionState); + this.createLinksForEqualOrSimilarRecommendedInstances(modelState, recommendationState, connectionState); } } @@ -47,12 +48,11 @@ public void process() { private void findNamesOfModelInstancesInSupposedMappings(LegacyModelExtractionState modelState, RecommendationState recommendationState, ConnectionState connectionState) { var recommendedInstances = recommendationState.getRecommendedInstances(); - var similarityUtils = getMetaData().getSimilarityUtils(); for (ModelInstance instance : modelState.getInstances()) { - var mostLikelyRi = similarityUtils.getMostRecommendedInstancesToInstanceByReferences(instance, recommendedInstances); + var mostLikelyRi = SimilarityUtils.getInstance().getMostRecommendedInstancesToInstanceByReferences(instance, recommendedInstances); for (var recommendedInstance : mostLikelyRi) { - var riProbability = recommendedInstance.getTypeMappings().isEmpty() ? probabilityWithoutType : probability; + var riProbability = recommendedInstance.getTypeMappings().isEmpty() ? this.probabilityWithoutType : this.probability; connectionState.addToLinks(recommendedInstance, instance, this, riProbability); } } @@ -62,8 +62,8 @@ private void createLinksForEqualOrSimilarRecommendedInstances(LegacyModelExtract ConnectionState connectionState) { for (var recommendedInstance : recommendationState.getRecommendedInstances()) { var sameInstances = modelState.getInstances() - .select(instance -> getMetaData().getSimilarityUtils().isRecommendedInstanceSimilarToModelInstance(recommendedInstance, instance)); - sameInstances.forEach(instance -> connectionState.addToLinks(recommendedInstance, instance, this, probability)); + .select(instance -> SimilarityUtils.getInstance().isRecommendedInstanceSimilarToModelInstance(recommendedInstance, instance)); + sameInstances.forEach(instance -> connectionState.addToLinks(recommendedInstance, instance, this, this.probability)); } } diff --git a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/NameTypeConnectionInformant.java b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/NameTypeConnectionInformant.java index 512efef..abe07b6 100644 --- a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/NameTypeConnectionInformant.java +++ b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/NameTypeConnectionInformant.java @@ -16,6 +16,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.NounMapping; import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.TextState; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.common.util.CommonUtilities; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; @@ -37,13 +38,13 @@ public NameTypeConnectionInformant(DataRepository dataRepository) { @Override public void process() { - DataRepository dataRepository = getDataRepository(); + DataRepository dataRepository = this.getDataRepository(); var text = DataRepositoryHelper.getAnnotatedText(dataRepository); var textState = DataRepositoryHelper.getTextState(dataRepository); var modelStates = DataRepositoryHelper.getModelStatesData(dataRepository); var recommendationStates = DataRepositoryHelper.getRecommendationStates(dataRepository); for (var word : text.words()) { - exec(textState, modelStates, recommendationStates, word); + this.exec(textState, modelStates, recommendationStates, word); } } @@ -51,10 +52,10 @@ private void exec(TextState textState, ModelStates modelStates, RecommendationSt for (var model : modelStates.modelIds()) { var modelState = modelStates.getModelExtractionState(model); var recommendationState = recommendationStates.getRecommendationState(modelState.getMetamodel()); - checkForNameAfterType(textState, word, modelState, recommendationState); - checkForNameBeforeType(textState, word, modelState, recommendationState); - checkForNortBeforeType(textState, word, modelState, recommendationState); - checkForNortAfterType(textState, word, modelState, recommendationState); + this.checkForNameAfterType(textState, word, modelState, recommendationState); + this.checkForNameBeforeType(textState, word, modelState, recommendationState); + this.checkForNortBeforeType(textState, word, modelState, recommendationState); + this.checkForNortAfterType(textState, word, modelState, recommendationState); } } @@ -70,16 +71,16 @@ private void checkForNameBeforeType(TextState textExtractionState, Word word, Le var preWord = word.getPreWord(); - var similarTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState); + var similarTypes = CommonUtilities.getSimilarTypes(word, modelState); if (!similarTypes.isEmpty()) { - textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability); + textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability); var nameMappings = textExtractionState.getMappingsThatCouldBeOfKind(preWord, MappingKind.NAME); var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE); - var instance = tryToIdentify(textExtractionState, similarTypes, preWord, modelState); - addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nameMappings, typeMappings, recommendationState); + var instance = this.tryToIdentify(textExtractionState, similarTypes, preWord, modelState); + this.addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nameMappings, typeMappings, recommendationState); } } @@ -100,15 +101,15 @@ private void checkForNameAfterType(TextState textExtractionState, Word word, Leg var after = word.getNextWord(); - var sameLemmaTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState); + var sameLemmaTypes = CommonUtilities.getSimilarTypes(word, modelState); if (!sameLemmaTypes.isEmpty()) { - textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability); + textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability); var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE); var nameMappings = textExtractionState.getMappingsThatCouldBeOfKind(after, MappingKind.NAME); - var instance = tryToIdentify(textExtractionState, sameLemmaTypes, after, modelState); - addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nameMappings, typeMappings, recommendationState); + var instance = this.tryToIdentify(textExtractionState, sameLemmaTypes, after, modelState); + this.addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nameMappings, typeMappings, recommendationState); } } @@ -124,16 +125,16 @@ private void checkForNortBeforeType(TextState textExtractionState, Word word, Le var preWord = word.getPreWord(); - var sameLemmaTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState); + var sameLemmaTypes = CommonUtilities.getSimilarTypes(word, modelState); if (!sameLemmaTypes.isEmpty()) { - textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability); + textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability); var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE); var nortMappings = textExtractionState.getMappingsThatCouldBeMultipleKinds(preWord, MappingKind.NAME, MappingKind.TYPE); - var instance = tryToIdentify(textExtractionState, sameLemmaTypes, preWord, modelState); - addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nortMappings, typeMappings, recommendationState); + var instance = this.tryToIdentify(textExtractionState, sameLemmaTypes, preWord, modelState); + this.addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nortMappings, typeMappings, recommendationState); } } @@ -149,15 +150,15 @@ private void checkForNortAfterType(TextState textExtractionState, Word word, Leg var after = word.getNextWord(); - var sameLemmaTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState); + var sameLemmaTypes = CommonUtilities.getSimilarTypes(word, modelState); if (!sameLemmaTypes.isEmpty()) { - textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability); + textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability); var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE); var nortMappings = textExtractionState.getMappingsThatCouldBeMultipleKinds(after, MappingKind.NAME, MappingKind.TYPE); - var instance = tryToIdentify(textExtractionState, sameLemmaTypes, after, modelState); - addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nortMappings, typeMappings, recommendationState); + var instance = this.tryToIdentify(textExtractionState, sameLemmaTypes, after, modelState); + this.addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nortMappings, typeMappings, recommendationState); } } @@ -179,7 +180,7 @@ private void addRecommendedInstanceIfNodeNotNull(// for (NounMapping nmapping : nounMappingsByCurrentWord) { var name = instance.getFullName(); var type = nmapping.getReference(); - recommendationState.addRecommendedInstance(name, type, this, probability, nameMappings, typeMappings); + recommendationState.addRecommendedInstance(name, type, this, this.probability, nameMappings, typeMappings); } } } @@ -204,8 +205,7 @@ private ModelInstance tryToIdentify(TextState textExtractionState, ImmutableList } var text = word.getText(); - matchingInstances = matchingInstances.select(i -> getMetaData().getSimilarityUtils() - .areWordsOfListsSimilar(i.getNameParts(), Lists.immutable.with(text))); + matchingInstances = matchingInstances.select(i -> SimilarityUtils.getInstance().areWordsOfListsSimilar(i.getNameParts(), Lists.immutable.with(text))); if (!matchingInstances.isEmpty()) { return matchingInstances.get(0); diff --git a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ProjectNameInformant.java b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ProjectNameInformant.java index 5ef3ddd..8338bc3 100644 --- a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ProjectNameInformant.java +++ b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ProjectNameInformant.java @@ -14,6 +14,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.stage.recommendationgenerator.RecommendedInstance; import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.NounMapping; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -41,7 +42,7 @@ public ProjectNameInformant(DataRepository dataRepository) { @Override public void process() { - DataRepository dataRepository = getDataRepository(); + DataRepository dataRepository = this.getDataRepository(); var projectName = DataRepositoryHelper.getProjectPipelineData(dataRepository).getProjectName(); var modelStates = DataRepositoryHelper.getModelStatesData(dataRepository); var recommendationStates = DataRepositoryHelper.getRecommendationStates(dataRepository); @@ -50,20 +51,20 @@ public void process() { Metamodel metamodel = modelState.getMetamodel(); var recommendationState = recommendationStates.getRecommendationState(metamodel); - checkForProjectNameInRecommendedInstances(projectName, recommendationState); - checkForProjectNameInRecommendedInstances(projectName.toLowerCase(), recommendationState); + this.checkForProjectNameInRecommendedInstances(projectName, recommendationState); + this.checkForProjectNameInRecommendedInstances(projectName.toLowerCase(), recommendationState); } } private void checkForProjectNameInRecommendedInstances(String projectName, RecommendationState recommendationState) { for (var recommendedInstance : recommendationState.getRecommendedInstances()) { - checkForProjectNameInNounMappingsOfRecommendedInstance(projectName, recommendedInstance); + this.checkForProjectNameInNounMappingsOfRecommendedInstance(projectName, recommendedInstance); } } private void checkForProjectNameInNounMappingsOfRecommendedInstance(String projectName, RecommendedInstance recommendedInstance) { for (var nm : recommendedInstance.getNameMappings()) { - checkWordsInNounMapping(projectName, recommendedInstance, nm); + this.checkWordsInNounMapping(projectName, recommendedInstance, nm); } } @@ -71,10 +72,10 @@ private void checkWordsInNounMapping(String projectName, RecommendedInstance rec for (var word : nm.getWords()) { String wordText = word.getText().toLowerCase(); if (projectName.contains(wordText)) { - var words = expandWordForName(projectName, word); - var expandedWord = concatenateWords(words); - if (getMetaData().getSimilarityUtils().areWordsSimilar(projectName, expandedWord)) { - recommendedInstance.addProbability(this, penalty); + var words = this.expandWordForName(projectName, word); + var expandedWord = this.concatenateWords(words); + if (SimilarityUtils.getInstance().areWordsSimilar(projectName, expandedWord)) { + recommendedInstance.addProbability(this, this.penalty); } } } @@ -93,8 +94,8 @@ private MutableList expandWordForName(String projectName, Word word) { MutableList words = Lists.mutable.with(word); var editedProjectName = getEditedProjectName(projectName); - expandWordForNameLeft(editedProjectName, words); - expandWordForNameRight(editedProjectName, words); + this.expandWordForNameLeft(editedProjectName, words); + this.expandWordForNameRight(editedProjectName, words); return words.distinct().sortThisByInt(Word::getPosition); } @@ -106,7 +107,7 @@ private void expandWordForNameLeft(String name, MutableList words) { } Word currWord = words.sortThisByInt(Word::getPosition).getFirstOptional().orElseThrow(IllegalArgumentException::new); - expandWordForName(name, currWord, words, Word::getPreWord, (text, addition) -> addition + text); + this.expandWordForName(name, currWord, words, Word::getPreWord, (text, addition) -> addition + text); } private void expandWordForNameRight(String name, MutableList words) { @@ -116,7 +117,7 @@ private void expandWordForNameRight(String name, MutableList words) { } var currWord = words.sortThisByInt(Word::getPosition).getLastOptional().orElseThrow(IllegalArgumentException::new); - expandWordForName(name, currWord, words, Word::getNextWord, (text, addition) -> text + addition); + this.expandWordForName(name, currWord, words, Word::getNextWord, (text, addition) -> text + addition); } private void expandWordForName(String name, Word currWord, MutableList words, UnaryOperator wordExpansion, @@ -126,7 +127,7 @@ private void expandWordForName(String name, Word currWord, MutableList wor throw new IllegalArgumentException(ERROR_EMPTY_LIST); } - var testWordText = concatenateWords(words); + var testWordText = this.concatenateWords(words); while (name.contains(testWordText)) { words.add(currWord); diff --git a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ReferenceInformant.java b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ReferenceInformant.java index 430e5a7..71290bb 100644 --- a/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ReferenceInformant.java +++ b/stages-tlr/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/connectiongenerator/informants/ReferenceInformant.java @@ -11,6 +11,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.MappingKind; import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.NounMapping; import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.TextState; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -27,14 +28,14 @@ public ReferenceInformant(DataRepository dataRepository) { @Override public void process() { - DataRepository dataRepository = getDataRepository(); + DataRepository dataRepository = this.getDataRepository(); var textState = DataRepositoryHelper.getTextState(dataRepository); var modelStates = DataRepositoryHelper.getModelStatesData(dataRepository); var recommendationStates = DataRepositoryHelper.getRecommendationStates(dataRepository); for (var model : modelStates.modelIds()) { var modelState = modelStates.getModelExtractionState(model); var recommendationState = recommendationStates.getRecommendationState(modelState.getMetamodel()); - findRecommendedInstancesFromNounMappingsThatAreSimilarToInstances(modelState, recommendationState, textState); + this.findRecommendedInstancesFromNounMappingsThatAreSimilarToInstances(modelState, recommendationState, textState); } } @@ -45,10 +46,10 @@ public void process() { private void findRecommendedInstancesFromNounMappingsThatAreSimilarToInstances(LegacyModelExtractionState modelState, RecommendationState recommendationState, TextState textState) { for (ModelInstance instance : modelState.getInstances()) { - var similarToInstanceMappings = getSimilarNounMappings(instance, textState); + var similarToInstanceMappings = this.getSimilarNounMappings(instance, textState); for (NounMapping similarNameMapping : similarToInstanceMappings) { - recommendationState.addRecommendedInstance(similarNameMapping.getReference(), this, probability, similarToInstanceMappings); + recommendationState.addRecommendedInstance(similarNameMapping.getReference(), this, this.probability, similarToInstanceMappings); } } @@ -56,7 +57,7 @@ private void findRecommendedInstancesFromNounMappingsThatAreSimilarToInstances(L private ImmutableList getSimilarNounMappings(ModelInstance instance, TextState textState) { return textState.getNounMappingsOfKind(MappingKind.NAME) - .select(nounMapping -> getMetaData().getSimilarityUtils().isNounMappingSimilarToModelInstance(nounMapping, instance)); + .select(nounMapping -> SimilarityUtils.getInstance().isNounMappingSimilarToModelInstance(nounMapping, instance)); } @Override diff --git a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/DefaultRecommendationStateStrategy.java b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/DefaultRecommendationStateStrategy.java index 33a17ca..2218309 100644 --- a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/DefaultRecommendationStateStrategy.java +++ b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/DefaultRecommendationStateStrategy.java @@ -2,22 +2,17 @@ package edu.kit.kastel.mcse.ardoco.tlr.recommendationgenerator; import edu.kit.kastel.mcse.ardoco.core.api.stage.recommendationgenerator.RecommendationStateStrategy; -import edu.kit.kastel.mcse.ardoco.core.data.GlobalConfiguration; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; public class DefaultRecommendationStateStrategy implements RecommendationStateStrategy { - private final GlobalConfiguration globalConfiguration; - - public DefaultRecommendationStateStrategy(GlobalConfiguration globalConfiguration) { - this.globalConfiguration = globalConfiguration; - } @Override public boolean areRecommendedInstanceTypesSimilar(String typeA, String typeB) { - return globalConfiguration.getSimilarityUtils().areWordsSimilar(typeA, typeB); + return SimilarityUtils.getInstance().areWordsSimilar(typeA, typeB); } @Override public boolean areRecommendedInstanceNamesSimilar(String nameA, String nameB) { - return globalConfiguration.getSimilarityUtils().areWordsSimilar(nameA, nameB); + return SimilarityUtils.getInstance().areWordsSimilar(nameA, nameB); } } diff --git a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationGenerator.java b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationGenerator.java index 68fb69b..052e593 100644 --- a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationGenerator.java +++ b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationGenerator.java @@ -42,7 +42,7 @@ public static RecommendationGenerator get(SortedMap additionalCo @Override protected void initializeState() { - var recommendationStates = RecommendationStatesImpl.build(dataRepository.getGlobalConfiguration()); - getDataRepository().addData(RecommendationStates.ID, recommendationStates); + var recommendationStates = RecommendationStatesImpl.build(); + this.getDataRepository().addData(RecommendationStates.ID, recommendationStates); } } diff --git a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationStatesImpl.java b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationStatesImpl.java index c3e7f5d..4d22b85 100644 --- a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationStatesImpl.java +++ b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationStatesImpl.java @@ -6,19 +6,18 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.Metamodel; import edu.kit.kastel.mcse.ardoco.core.api.stage.recommendationgenerator.RecommendationStateStrategy; import edu.kit.kastel.mcse.ardoco.core.api.stage.recommendationgenerator.RecommendationStates; -import edu.kit.kastel.mcse.ardoco.core.data.GlobalConfiguration; public class RecommendationStatesImpl implements RecommendationStates { private final EnumMap recommendationStates; private RecommendationStatesImpl() { - recommendationStates = new EnumMap<>(Metamodel.class); + this.recommendationStates = new EnumMap<>(Metamodel.class); } - public static RecommendationStates build(GlobalConfiguration globalConfiguration) { + public static RecommendationStates build() { var recStates = new RecommendationStatesImpl(); for (Metamodel mm : Metamodel.values()) { - RecommendationStateStrategy rss = new DefaultRecommendationStateStrategy(globalConfiguration); + RecommendationStateStrategy rss = new DefaultRecommendationStateStrategy(); recStates.recommendationStates.put(mm, new RecommendationStateImpl(rss)); } return recStates; @@ -26,6 +25,6 @@ public static RecommendationStates build(GlobalConfiguration globalConfiguration @Override public RecommendationStateImpl getRecommendationState(Metamodel mm) { - return recommendationStates.get(mm); + return this.recommendationStates.get(mm); } } diff --git a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/informants/CompoundRecommendationInformant.java b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/informants/CompoundRecommendationInformant.java index 5fcd1b8..98feda6 100644 --- a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/informants/CompoundRecommendationInformant.java +++ b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/informants/CompoundRecommendationInformant.java @@ -15,6 +15,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.NounMapping; import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.TextState; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.common.util.CommonUtilities; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; @@ -32,7 +33,7 @@ public CompoundRecommendationInformant(DataRepository dataRepository) { @Override public void process() { - DataRepository dataRepository = getDataRepository(); + DataRepository dataRepository = this.getDataRepository(); var modelStatesData = DataRepositoryHelper.getModelStatesData(dataRepository); var textState = DataRepositoryHelper.getTextState(dataRepository); var recommendationStates = DataRepositoryHelper.getRecommendationStates(dataRepository); @@ -41,9 +42,9 @@ public void process() { var modelState = modelStatesData.getModelExtractionState(model); var recommendationState = recommendationStates.getRecommendationState(modelState.getMetamodel()); - createRecommendationInstancesFromCompoundNounMappings(textState, recommendationState, modelState); - findMoreCompoundsForRecommendationInstances(textState, recommendationState, modelState); - findSpecialNamedEntitities(textState, recommendationState); + this.createRecommendationInstancesFromCompoundNounMappings(textState, recommendationState, modelState); + this.findMoreCompoundsForRecommendationInstances(textState, recommendationState, modelState); + this.findSpecialNamedEntitities(textState, recommendationState); } } @@ -54,8 +55,8 @@ private void createRecommendationInstancesFromCompoundNounMappings(TextState tex LegacyModelExtractionState modelState) { for (var nounMapping : textState.getNounMappings()) { if (nounMapping.isCompound()) { - var typeMappings = getRelatedTypeMappings(nounMapping, textState); - addRecommendedInstance(nounMapping, typeMappings, recommendationState, modelState); + var typeMappings = this.getRelatedTypeMappings(nounMapping, textState); + this.addRecommendedInstance(nounMapping, typeMappings, recommendationState, modelState); } } } @@ -69,10 +70,10 @@ private void findMoreCompoundsForRecommendationInstances(TextState textState, Re for (var nounMapping : textState.getNounMappings()) { for (var word : nounMapping.getWords()) { var prevWord = word.getPreWord(); - addRecommendedInstanceIfCompoundWithOtherWord(nounMapping, prevWord, textState, recommendationState, modelState); + this.addRecommendedInstanceIfCompoundWithOtherWord(nounMapping, prevWord, textState, recommendationState, modelState); var nextWord = word.getNextWord(); - addRecommendedInstanceIfCompoundWithOtherWord(nounMapping, nextWord, textState, recommendationState, modelState); + this.addRecommendedInstanceIfCompoundWithOtherWord(nounMapping, nextWord, textState, recommendationState, modelState); } } } @@ -81,7 +82,7 @@ private void findMoreCompoundsForRecommendationInstances(TextState textState, Re * Find words that use CamelCase or snake_case. */ private void findSpecialNamedEntitities(TextState textState, RecommendationState recommendationState) { - findSpecialNamedEntitiesInNounMappings(textState.getNounMappingsOfKind(MappingKind.NAME), recommendationState); + this.findSpecialNamedEntitiesInNounMappings(textState.getNounMappingsOfKind(MappingKind.NAME), recommendationState); } private void findSpecialNamedEntitiesInNounMappings(ImmutableList nounMappings, RecommendationState recommendationState) { @@ -90,7 +91,8 @@ private void findSpecialNamedEntitiesInNounMappings(ImmutableList n var wordText = word.getText(); if (CommonUtilities.isCamelCasedWord(wordText) || CommonUtilities.nameIsSnakeCased(wordText)) { var localNounMappings = Lists.immutable.of(nounMapping); - recommendationState.addRecommendedInstance(nounMapping.getReference(), "", this, confidence, localNounMappings, Lists.immutable.empty()); + recommendationState.addRecommendedInstance(nounMapping.getReference(), "", this, this.confidence, localNounMappings, Lists.immutable + .empty()); } } } @@ -99,12 +101,12 @@ private void findSpecialNamedEntitiesInNounMappings(ImmutableList n private void addRecommendedInstance(NounMapping nounMapping, ImmutableList typeMappings, RecommendationState recommendationState, LegacyModelExtractionState modelState) { var nounMappings = Lists.immutable.of(nounMapping); - var types = getSimilarModelTypes(typeMappings, modelState); + var types = this.getSimilarModelTypes(typeMappings, modelState); if (types.isEmpty()) { - recommendationState.addRecommendedInstance(nounMapping.getReference(), "", this, confidence, nounMappings, typeMappings); + recommendationState.addRecommendedInstance(nounMapping.getReference(), "", this, this.confidence, nounMappings, typeMappings); } else { for (var type : types) { - recommendationState.addRecommendedInstance(nounMapping.getReference(), type, this, confidence, nounMappings, typeMappings); + recommendationState.addRecommendedInstance(nounMapping.getReference(), type, this, this.confidence, nounMappings, typeMappings); } } } @@ -114,11 +116,11 @@ private ImmutableList getSimilarModelTypes(ImmutableList ty var typeIdentifiers = CommonUtilities.getTypeIdentifiers(modelState); for (var typeMapping : typeMappings) { var currSimilarTypes = Lists.immutable.fromStream(typeIdentifiers.stream() - .filter(typeId -> getMetaData().getSimilarityUtils().areWordsSimilar(typeId, typeMapping.getReference()))); + .filter(typeId -> SimilarityUtils.getInstance().areWordsSimilar(typeId, typeMapping.getReference()))); similarModelTypes.addAll(currSimilarTypes.toList()); for (var word : typeMapping.getWords()) { currSimilarTypes = Lists.immutable.fromStream(typeIdentifiers.stream() - .filter(typeId -> getMetaData().getSimilarityUtils().areWordsSimilar(typeId, word.getLemma()))); + .filter(typeId -> SimilarityUtils.getInstance().areWordsSimilar(typeId, word.getLemma()))); similarModelTypes.addAll(currSimilarTypes.toList()); } } @@ -144,7 +146,7 @@ private void addRecommendedInstanceIfCompoundWithOtherWord(NounMapping nounMappi if (word.getPosTag().isNoun()) { var typeMappings = textState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE); if (!typeMappings.isEmpty()) { - addRecommendedInstance(nounMapping, typeMappings, recommendationState, modelState); + this.addRecommendedInstance(nounMapping, typeMappings, recommendationState, modelState); } } } diff --git a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/informants/NameTypeInformant.java b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/informants/NameTypeInformant.java index 01faf9d..900a4ee 100644 --- a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/informants/NameTypeInformant.java +++ b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/informants/NameTypeInformant.java @@ -35,14 +35,14 @@ public NameTypeInformant(DataRepository dataRepository) { @Override public void process() { - DataRepository dataRepository = getDataRepository(); + DataRepository dataRepository = this.getDataRepository(); var text = DataRepositoryHelper.getAnnotatedText(dataRepository); var textState = DataRepositoryHelper.getTextState(dataRepository); var modelStatesData = DataRepositoryHelper.getModelStatesData(dataRepository); var recommendationStates = DataRepositoryHelper.getRecommendationStates(dataRepository); for (var word : text.words()) { - exec(textState, modelStatesData, recommendationStates, word); + this.exec(textState, modelStatesData, recommendationStates, word); } } @@ -51,10 +51,10 @@ private void exec(TextState textState, ModelStates modelStates, RecommendationSt var modelState = modelStates.getModelExtractionState(model); var recommendationState = recommendationStates.getRecommendationState(modelState.getMetamodel()); - addRecommendedInstanceIfNameAfterType(textState, word, modelState, recommendationState); - addRecommendedInstanceIfNameBeforeType(textState, word, modelState, recommendationState); - addRecommendedInstanceIfNameOrTypeBeforeType(textState, word, modelState, recommendationState); - addRecommendedInstanceIfNameOrTypeAfterType(textState, word, modelState, recommendationState); + this.addRecommendedInstanceIfNameAfterType(textState, word, modelState, recommendationState); + this.addRecommendedInstanceIfNameBeforeType(textState, word, modelState, recommendationState); + this.addRecommendedInstanceIfNameOrTypeBeforeType(textState, word, modelState, recommendationState); + this.addRecommendedInstanceIfNameOrTypeAfterType(textState, word, modelState, recommendationState); } } @@ -71,15 +71,15 @@ private void addRecommendedInstanceIfNameBeforeType(TextState textExtractionStat return; } - var similarTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState); + var similarTypes = CommonUtilities.getSimilarTypes(word, modelState); if (!similarTypes.isEmpty()) { - textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability); + textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability); var nameMappings = textExtractionState.getMappingsThatCouldBeOfKind(word.getPreWord(), MappingKind.NAME); var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE); - CommonUtilities.addRecommendedInstancesFromNounMappings(similarTypes, nameMappings, typeMappings, recommendationState, this, probability); + CommonUtilities.addRecommendedInstancesFromNounMappings(similarTypes, nameMappings, typeMappings, recommendationState, this, this.probability); } } @@ -96,14 +96,14 @@ private void addRecommendedInstanceIfNameAfterType(TextState textExtractionState return; } - var sameLemmaTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState); + var sameLemmaTypes = CommonUtilities.getSimilarTypes(word, modelState); if (!sameLemmaTypes.isEmpty()) { - textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability); + textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability); var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE); var nameMappings = textExtractionState.getMappingsThatCouldBeOfKind(word.getNextWord(), MappingKind.NAME); - CommonUtilities.addRecommendedInstancesFromNounMappings(sameLemmaTypes, nameMappings, typeMappings, recommendationState, this, probability); + CommonUtilities.addRecommendedInstancesFromNounMappings(sameLemmaTypes, nameMappings, typeMappings, recommendationState, this, this.probability); } } @@ -120,15 +120,15 @@ private void addRecommendedInstanceIfNameOrTypeBeforeType(TextState textExtracti return; } - var sameLemmaTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState); + var sameLemmaTypes = CommonUtilities.getSimilarTypes(word, modelState); if (!sameLemmaTypes.isEmpty()) { - textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability); + textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability); var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE); var nortMappings = textExtractionState.getMappingsThatCouldBeMultipleKinds(word.getPreWord(), MappingKind.NAME, MappingKind.TYPE); - CommonUtilities.addRecommendedInstancesFromNounMappings(sameLemmaTypes, nortMappings, typeMappings, recommendationState, this, probability); + CommonUtilities.addRecommendedInstancesFromNounMappings(sameLemmaTypes, nortMappings, typeMappings, recommendationState, this, this.probability); } } @@ -145,14 +145,14 @@ private void addRecommendedInstanceIfNameOrTypeAfterType(TextState textExtractio return; } - var sameLemmaTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState); + var sameLemmaTypes = CommonUtilities.getSimilarTypes(word, modelState); if (!sameLemmaTypes.isEmpty()) { - textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability); + textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability); var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE); var nortMappings = textExtractionState.getMappingsThatCouldBeMultipleKinds(word.getNextWord(), MappingKind.NAME, MappingKind.TYPE); - CommonUtilities.addRecommendedInstancesFromNounMappings(sameLemmaTypes, nortMappings, typeMappings, recommendationState, this, probability); + CommonUtilities.addRecommendedInstancesFromNounMappings(sameLemmaTypes, nortMappings, typeMappings, recommendationState, this, this.probability); } } diff --git a/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/DefaultTextStateStrategy.java b/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/DefaultTextStateStrategy.java index f810653..30ebf00 100644 --- a/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/DefaultTextStateStrategy.java +++ b/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/DefaultTextStateStrategy.java @@ -15,17 +15,16 @@ import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.TextStateStrategy; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.data.Confidence; -import edu.kit.kastel.mcse.ardoco.core.data.GlobalConfiguration; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant; @Deterministic public abstract class DefaultTextStateStrategy implements TextStateStrategy { - protected final GlobalConfiguration globalConfiguration; protected TextStateImpl textState; - protected DefaultTextStateStrategy(GlobalConfiguration globalConfiguration) { - this.globalConfiguration = globalConfiguration; + protected DefaultTextStateStrategy() { + // NOP } @Override @@ -33,11 +32,10 @@ public void setState(TextState textState) { if (this.textState != null) { throw new IllegalStateException("The text state is already set"); } - if (textState instanceof TextStateImpl) { - this.textState = (TextStateImpl) textState; - } else { + if (!(textState instanceof TextStateImpl)) { throw new IllegalArgumentException("The text state must be an instance of TextStateImpl"); } + this.textState = (TextStateImpl) textState; } public TextStateImpl getTextState() { @@ -65,9 +63,7 @@ public NounMapping createNounMappingStateless(ImmutableSortedSet words, Im @Override public ImmutableList getNounMappingsWithSimilarReference(String reference) { - return this.textState.getNounMappings() - .select(nm -> this.globalConfiguration.getSimilarityUtils().areWordsSimilar(reference, nm.getReference())) - .toImmutable(); + return this.textState.getNounMappings().select(nm -> SimilarityUtils.getInstance().areWordsSimilar(reference, nm.getReference())).toImmutable(); } @Override @@ -105,11 +101,10 @@ public NounMapping mergeNounMappings(NounMapping nounMapping, MutableList kind, // - kind -> putAllConfidencesTogether(existingNounMappingDistribution.get(kind), disposableNounMappingDistribution.get(kind)) // + kind -> this.putAllConfidencesTogether(existingNounMappingDistribution.get(kind), disposableNounMappingDistribution.get(kind)) // )); MutableSortedMap mergedDistribution = SortedMaps.mutable.withSortedMap(mergedRawMap); MutableList mergedSurfaceForms = firstNounMapping.getSurfaceForms().toList(); for (var surface : secondNounMapping.getSurfaceForms()) { - if (mergedSurfaceForms.contains(surface)) + if (mergedSurfaceForms.contains(surface)) { continue; + } mergedSurfaceForms.add(surface); } @@ -79,7 +79,8 @@ public NounMappingImpl mergeNounMappingsStateless(NounMapping firstNounMapping, @Override public NounMappingImpl mergeNounMappings(NounMapping firstNounMapping, NounMapping secondNounMapping, ImmutableList referenceWords, String reference, MappingKind mappingKind, Claimant claimant, double probability) { - var mergedNounMapping = mergeNounMappingsStateless(firstNounMapping, secondNounMapping, referenceWords, reference, mappingKind, claimant, probability); + var mergedNounMapping = this.mergeNounMappingsStateless(firstNounMapping, secondNounMapping, referenceWords, reference, mappingKind, claimant, + probability); this.getTextState().removeNounMappingFromState(firstNounMapping, mergedNounMapping); this.getTextState().removeNounMappingFromState(secondNounMapping, mergedNounMapping); diff --git a/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/PhraseConcerningTextStateStrategy.java b/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/PhraseConcerningTextStateStrategy.java index 72f9f35..42adff7 100644 --- a/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/PhraseConcerningTextStateStrategy.java +++ b/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/PhraseConcerningTextStateStrategy.java @@ -17,13 +17,15 @@ import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.NounMapping; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; import edu.kit.kastel.mcse.ardoco.core.data.Confidence; -import edu.kit.kastel.mcse.ardoco.core.data.GlobalConfiguration; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant; +/** + * @deprecated not used + */ +@Deprecated public class PhraseConcerningTextStateStrategy extends DefaultTextStateStrategy { - public PhraseConcerningTextStateStrategy(GlobalConfiguration globalConfiguration) { - super(globalConfiguration); + public PhraseConcerningTextStateStrategy() { } @Override @@ -60,14 +62,15 @@ public NounMappingImpl mergeNounMappingsStateless(NounMapping firstNounMapping, var mergedRawMap = Arrays.stream(MappingKind.values()) .collect(Collectors.toMap( // kind -> kind, // - kind -> putAllConfidencesTogether(distribution1.get(kind), distribution2.get(kind)) // + kind -> this.putAllConfidencesTogether(distribution1.get(kind), distribution2.get(kind)) // )); MutableSortedMap mergedDistribution = SortedMaps.mutable.withSortedMap(mergedRawMap); MutableList mergedSurfaceForms = firstNounMapping.getSurfaceForms().toList(); for (var surface : secondNounMapping.getSurfaceForms()) { - if (mergedSurfaceForms.contains(surface)) + if (mergedSurfaceForms.contains(surface)) { continue; + } mergedSurfaceForms.add(surface); } @@ -87,7 +90,7 @@ public NounMappingImpl mergeNounMappingsStateless(NounMapping firstNounMapping, if (firstNounMapping.getReference().equalsIgnoreCase(secondNounMapping.getReference())) { mergedReference = firstNounMapping.getReference(); } else { - mergedReference = calculateNounMappingReference(mergedReferenceWords); + mergedReference = this.calculateNounMappingReference(mergedReferenceWords); } } @@ -102,7 +105,8 @@ public NounMappingImpl mergeNounMappingsStateless(NounMapping firstNounMapping, @Override public NounMappingImpl mergeNounMappings(NounMapping firstNounMapping, NounMapping secondNounMapping, ImmutableList referenceWords, String reference, MappingKind mappingKind, Claimant claimant, double probability) { - var mergedNounMapping = mergeNounMappingsStateless(firstNounMapping, secondNounMapping, referenceWords, reference, mappingKind, claimant, probability); + var mergedNounMapping = this.mergeNounMappingsStateless(firstNounMapping, secondNounMapping, referenceWords, reference, mappingKind, claimant, + probability); this.getTextState().removeNounMappingFromState(firstNounMapping, mergedNounMapping); this.getTextState().removeNounMappingFromState(secondNounMapping, mergedNounMapping); diff --git a/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/TextExtraction.java b/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/TextExtraction.java index ee3d5a4..ca788ac 100644 --- a/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/TextExtraction.java +++ b/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/TextExtraction.java @@ -41,7 +41,7 @@ protected void initializeState() { var dataRepository = this.getDataRepository(); var optionalTextState = dataRepository.getData(TextState.ID, TextStateImpl.class); if (optionalTextState.isEmpty()) { - TextStateStrategy tts = new OriginalTextStateStrategy(dataRepository.getGlobalConfiguration()); + TextStateStrategy tts = new OriginalTextStateStrategy(); var textState = new TextStateImpl(tts); dataRepository.addData(TextState.ID, textState); } diff --git a/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/informants/MappingCombinerInformant.java b/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/informants/MappingCombinerInformant.java index 73c5afb..c16845a 100644 --- a/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/informants/MappingCombinerInformant.java +++ b/stages-tlr/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/informants/MappingCombinerInformant.java @@ -12,6 +12,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.TextState; import edu.kit.kastel.mcse.ardoco.core.api.text.Phrase; import edu.kit.kastel.mcse.ardoco.core.common.similarity.PhraseMappingAggregatorStrategy; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.common.tuple.Pair; import edu.kit.kastel.mcse.ardoco.core.common.util.Comparators; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; @@ -30,8 +31,8 @@ public MappingCombinerInformant(DataRepository dataRepository) { @Override public void process() { - TextState textState = DataRepositoryHelper.getTextState(getDataRepository()); - combineSimilarPhraseMappings(textState); + TextState textState = DataRepositoryHelper.getTextState(this.getDataRepository()); + this.combineSimilarPhraseMappings(textState); } private void combineSimilarPhraseMappings(TextState textState) { @@ -39,14 +40,14 @@ private void combineSimilarPhraseMappings(TextState textState) { ImmutableList phraseMappings = textState.getPhraseMappings(); for (PhraseMapping phraseMapping : phraseMappings) { - ImmutableList similarPhraseMappings = phraseMappings.select(p -> getMetaData().getSimilarityUtils() - .getPhraseMappingSimilarity(textState, phraseMapping, p, PhraseMappingAggregatorStrategy.MAX_SIMILARITY) > minCosineSimilarity); + ImmutableList similarPhraseMappings = phraseMappings.select(p -> SimilarityUtils.getInstance() + .getPhraseMappingSimilarity(textState, phraseMapping, p, PhraseMappingAggregatorStrategy.MAX_SIMILARITY) > this.minCosineSimilarity); // Remove the phrase mapping from the list of similar phrase mappings // Comment: This would break the logic but seems to be logical .. // similarPhraseMappings = similarPhraseMappings.newWithout(phraseMapping); - processPhraseMappingForSimilarPhraseMappings(textState, similarPhraseMappings, phraseMapping); + this.processPhraseMappingForSimilarPhraseMappings(textState, similarPhraseMappings, phraseMapping); } } @@ -61,13 +62,13 @@ private void processPhraseMappingForSimilarPhraseMappings(TextState textState, I if (Comparators.collectionsEqualsAnyOrder(similarPhraseMapping.getPhrases().collect(Phrase::getText), phraseMapping.getPhrases() .collect(Phrase::getText))) { - processSimilarPhraseMappingWhenEqualPhraseText(textState, phraseMapping, nounMappingsOfSimilarPhraseMapping); + this.processSimilarPhraseMappingWhenEqualPhraseText(textState, phraseMapping, nounMappingsOfSimilarPhraseMapping); continue; } if (nounMappingsOfPhraseMapping.size() == nounMappingsOfSimilarPhraseMapping.size()) { - processSimilarPhraseMappingWhenEquallySized(textState, similarPhraseMappings, phraseMapping, nounMappingsOfPhraseMapping, similarPhraseMapping, - nounMappingsOfSimilarPhraseMapping); + this.processSimilarPhraseMappingWhenEquallySized(textState, similarPhraseMappings, phraseMapping, nounMappingsOfPhraseMapping, + similarPhraseMapping, nounMappingsOfSimilarPhraseMapping); } } } @@ -78,7 +79,7 @@ private void processSimilarPhraseMappingWhenEquallySized(TextState textState, Im MutableList> similarNounMappings = Lists.mutable.empty(); for (NounMapping nounMapping : nounMappingsOfPhraseMapping) { - NounMapping similarNounMapping = getMostSimilarNounMappingOverThreshold(nounMapping, nounMappingsOfSimilarPhraseMapping); + NounMapping similarNounMapping = this.getMostSimilarNounMappingOverThreshold(nounMapping, nounMappingsOfSimilarPhraseMapping); if (similarNounMapping != null) { similarNounMappings.add(new Pair<>(nounMapping, similarNounMapping)); } @@ -102,7 +103,7 @@ private void processSimilarPhraseMappingWhenEqualPhraseText(TextState textState, .contains(nounMapping)) { continue; } - if (getMetaData().getSimilarityUtils().areNounMappingsSimilar(nounMapping, nounMappingOfSimilarPhraseMapping)) { + if (SimilarityUtils.getInstance().areNounMappingsSimilar(nounMapping, nounMappingOfSimilarPhraseMapping)) { textState.mergeNounMappings(nounMapping, nounMappingOfSimilarPhraseMapping, this); } } @@ -114,7 +115,7 @@ private NounMapping getMostSimilarNounMappingOverThreshold(NounMapping nounMappi MutableList similarNounMappings = Lists.mutable.empty(); for (NounMapping nounMappingOfSimilarPhraseMapping : nounMappingsOfSimilarPhraseMapping) { - if (getMetaData().getSimilarityUtils().areNounMappingsSimilar(nounMapping, nounMappingOfSimilarPhraseMapping)) { + if (SimilarityUtils.getInstance().areNounMappingsSimilar(nounMapping, nounMappingOfSimilarPhraseMapping)) { similarNounMappings.add(nounMappingOfSimilarPhraseMapping); } } diff --git a/stages-tlr/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/agents/MappingCombinerTest.java b/stages-tlr/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/agents/MappingCombinerTest.java index 4a3b679..cfd20f0 100644 --- a/stages-tlr/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/agents/MappingCombinerTest.java +++ b/stages-tlr/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/textextraction/agents/MappingCombinerTest.java @@ -19,6 +19,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.text.PhraseType; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; import edu.kit.kastel.mcse.ardoco.core.common.similarity.PhraseMappingAggregatorStrategy; +import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant; import edu.kit.kastel.mcse.ardoco.tlr.text.providers.informants.corenlp.PhraseImpl; @@ -62,7 +63,7 @@ class MappingCombinerTest implements Claimant { void setup() { this.data = new DataRepository(); this.agent = new MappingCombiner(this.data); - PhraseConcerningTextStateStrategy strategy = new PhraseConcerningTextStateStrategy(this.data.getGlobalConfiguration()); + PhraseConcerningTextStateStrategy strategy = new PhraseConcerningTextStateStrategy(); this.preTextState = new TextStateImpl(strategy); Word a0 = Mockito.mock(Word.class); @@ -208,8 +209,7 @@ void addTextualEqualNounMappingWithSimilarPhrase() { this.preTextState.addNounMapping(this.dog3, MappingKind.NAME, this, 0.5); Assertions.assertTrue(this.phraseMappingsAreSimilar(this.preTextState, this.dog1, this.dog3)); - Assertions.assertTrue(this.data.getGlobalConfiguration() - .getSimilarityUtils() + Assertions.assertTrue(SimilarityUtils.getInstance() .areNounMappingsSimilar(this.preTextState.getNounMappingByWord(this.dog1), this.preTextState.getNounMappingByWord(this.dog3))); Assertions.assertEquals(2, this.preTextState.getNounMappings().size()); @@ -400,8 +400,7 @@ private boolean phraseMappingsAreSimilar(TextStateImpl textState, Word word1, Wo var pm0 = textState.getPhraseMappingByNounMapping(nm0); var pm1 = textState.getPhraseMappingByNounMapping(nm1); - return this.data.getGlobalConfiguration() - .getSimilarityUtils() + return SimilarityUtils.getInstance() .getPhraseMappingSimilarity(textState, pm0, pm1, PhraseMappingAggregatorStrategy.MAX_SIMILARITY) > MappingCombinerTest.MIN_COSINE_SIMILARITY; } @@ -456,7 +455,7 @@ private void mockWord(Word word, String text, String lemma, int sentenceNumber, } private TextStateImpl createCopy(TextStateImpl textState) { - PhraseConcerningTextStateStrategy strategy = new PhraseConcerningTextStateStrategy(this.data.getGlobalConfiguration()); + PhraseConcerningTextStateStrategy strategy = new PhraseConcerningTextStateStrategy(); TextStateImpl newTextState = new TextStateImpl(strategy); MutableList nounMappings = this.getField(textState, "nounMappings");