From 5a4c627aa0c2177b403bdc5c9895923fd7e957b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Fuch=C3=9F?= Date: Fri, 6 Dec 2024 13:31:25 +0100 Subject: [PATCH] Remove RecommendationStateStrategy, since not used --- .../DefaultRecommendationStateStrategy.java | 18 --------- .../RecommendationStateImpl.java | 37 +++++++++---------- .../RecommendationStatesImpl.java | 5 +-- 3 files changed, 20 insertions(+), 40 deletions(-) delete mode 100644 stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/DefaultRecommendationStateStrategy.java 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 deleted file mode 100644 index 2218309..0000000 --- a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/DefaultRecommendationStateStrategy.java +++ /dev/null @@ -1,18 +0,0 @@ -/* Licensed under MIT 2024. */ -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.common.similarity.SimilarityUtils; - -public class DefaultRecommendationStateStrategy implements RecommendationStateStrategy { - - @Override - public boolean areRecommendedInstanceTypesSimilar(String typeA, String typeB) { - return SimilarityUtils.getInstance().areWordsSimilar(typeA, typeB); - } - - @Override - public boolean areRecommendedInstanceNamesSimilar(String nameA, String nameB) { - return SimilarityUtils.getInstance().areWordsSimilar(nameA, nameB); - } -} diff --git a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationStateImpl.java b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationStateImpl.java index cbe4a63..0693d98 100644 --- a/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationStateImpl.java +++ b/stages-tlr/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/tlr/recommendationgenerator/RecommendationStateImpl.java @@ -8,9 +8,9 @@ import org.eclipse.collections.api.set.sorted.MutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.stage.recommendationgenerator.RecommendationState; -import edu.kit.kastel.mcse.ardoco.core.api.stage.recommendationgenerator.RecommendationStateStrategy; 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.common.similarity.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.data.AbstractState; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant; @@ -19,16 +19,15 @@ */ public class RecommendationStateImpl extends AbstractState implements RecommendationState { - private final RecommendationStateStrategy recommendationStateStrategy; + private static final long serialVersionUID = 3088770775218314854L; private MutableSortedSet recommendedInstances; /** * Creates a new recommendation state. */ - public RecommendationStateImpl(RecommendationStateStrategy recommendationStateStrategy) { + public RecommendationStateImpl() { super(); - this.recommendationStateStrategy = recommendationStateStrategy; - recommendedInstances = SortedSets.mutable.empty(); + this.recommendedInstances = SortedSets.mutable.empty(); } /** @@ -38,7 +37,7 @@ public RecommendationStateImpl(RecommendationStateStrategy recommendationStateSt */ @Override public ImmutableList getRecommendedInstances() { - return Lists.immutable.withAll(recommendedInstances); + return Lists.immutable.withAll(this.recommendedInstances); } /** @@ -77,15 +76,15 @@ public RecommendedInstance addRecommendedInstance(String name, String type, Clai * recommendedInstance with the same name can be found it is extended. Elsewhere a new recommended instance is created. */ private void addRecommendedInstance(RecommendedInstance ri) { - if (recommendedInstances.contains(ri)) { + if (this.recommendedInstances.contains(ri)) { return; } - var risWithExactName = recommendedInstances.select(r -> r.getName().equalsIgnoreCase(ri.getName())).toImmutable().toImmutableList(); + var risWithExactName = this.recommendedInstances.select(r -> r.getName().equalsIgnoreCase(ri.getName())).toImmutable().toImmutableList(); var risWithExactNameAndType = risWithExactName.select(r -> r.getType().equalsIgnoreCase(ri.getType())); if (risWithExactNameAndType.isEmpty()) { - processRecommendedInstancesWithNoExactNameAndType(ri, risWithExactName); + this.processRecommendedInstancesWithNoExactNameAndType(ri, risWithExactName); } else { risWithExactNameAndType.get(0).addMappings(ri.getNameMappings(), ri.getTypeMappings()); } @@ -93,12 +92,12 @@ private void addRecommendedInstance(RecommendedInstance ri) { private void processRecommendedInstancesWithNoExactNameAndType(RecommendedInstance ri, ImmutableList risWithExactName) { if (risWithExactName.isEmpty()) { - recommendedInstances.add(ri); + this.recommendedInstances.add(ri); } else { var added = false; for (RecommendedInstance riWithExactName : risWithExactName) { - var areWordsSimilar = recommendationStateStrategy.areRecommendedInstanceTypesSimilar(riWithExactName.getType(), ri.getType()); + var areWordsSimilar = SimilarityUtils.getInstance().areWordsSimilar(riWithExactName.getType(), ri.getType()); if (areWordsSimilar || recommendedInstancesHasEmptyType(ri, riWithExactName)) { riWithExactName.addMappings(ri.getNameMappings(), ri.getTypeMappings()); added = true; @@ -107,7 +106,7 @@ private void processRecommendedInstancesWithNoExactNameAndType(RecommendedInstan } if (!added && !ri.getType().isBlank()) { - recommendedInstances.add(ri); + this.recommendedInstances.add(ri); } } } @@ -124,7 +123,7 @@ private static boolean recommendedInstancesHasEmptyType(RecommendedInstance ri, */ @Override public ImmutableList getRecommendedInstancesByTypeMapping(NounMapping mapping) { - return recommendedInstances.select(sinstance -> sinstance.getTypeMappings().contains(mapping)).toImmutableList(); + return this.recommendedInstances.select(sinstance -> sinstance.getTypeMappings().contains(mapping)).toImmutableList(); } /** @@ -135,7 +134,7 @@ public ImmutableList getRecommendedInstancesByTypeMapping(N */ @Override public ImmutableList getAnyRecommendedInstancesByMapping(NounMapping mapping) { - return recommendedInstances // + return this.recommendedInstances // .select(sinstance -> sinstance.getTypeMappings().contains(mapping) || sinstance.getNameMappings().contains(mapping)) .toImmutableList(); } @@ -148,7 +147,7 @@ public ImmutableList getAnyRecommendedInstancesByMapping(No */ @Override public ImmutableList getRecommendedInstancesByName(String name) { - return recommendedInstances.select(ri -> ri.getName().toLowerCase().contentEquals(name.toLowerCase())).toImmutableList(); + return this.recommendedInstances.select(ri -> ri.getName().toLowerCase().contentEquals(name.toLowerCase())).toImmutableList(); } /** @@ -160,8 +159,8 @@ public ImmutableList getRecommendedInstancesByName(String n @Override public ImmutableList getRecommendedInstancesBySimilarName(String name) { MutableList ris = Lists.mutable.empty(); - for (RecommendedInstance ri : recommendedInstances) { - if (recommendationStateStrategy.areRecommendedInstanceNamesSimilar(ri.getName(), name)) { + for (RecommendedInstance ri : this.recommendedInstances) { + if (SimilarityUtils.getInstance().areWordsSimilar(ri.getName(), name)) { ris.add(ri); } } @@ -177,7 +176,7 @@ public ImmutableList getRecommendedInstancesBySimilarName(S */ @Override public ImmutableList getRecommendedInstancesByType(String type) { - return recommendedInstances.select(ri -> ri.getType().toLowerCase().contentEquals(type.toLowerCase())).toImmutableList(); + return this.recommendedInstances.select(ri -> ri.getType().toLowerCase().contentEquals(type.toLowerCase())).toImmutableList(); } /** @@ -188,6 +187,6 @@ public ImmutableList getRecommendedInstancesByType(String t */ @Override public ImmutableList getRecommendedInstancesBySimilarType(String type) { - return recommendedInstances.select(ri -> recommendationStateStrategy.areRecommendedInstanceTypesSimilar(ri.getType(), type)).toImmutableList(); + return this.recommendedInstances.select(ri -> SimilarityUtils.getInstance().areWordsSimilar(ri.getType(), type)).toImmutableList(); } } 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 4d22b85..84680e7 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 @@ -4,10 +4,10 @@ import java.util.EnumMap; 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; public class RecommendationStatesImpl implements RecommendationStates { + private static final long serialVersionUID = -6792479283538202394L; private final EnumMap recommendationStates; private RecommendationStatesImpl() { @@ -17,8 +17,7 @@ private RecommendationStatesImpl() { public static RecommendationStates build() { var recStates = new RecommendationStatesImpl(); for (Metamodel mm : Metamodel.values()) { - RecommendationStateStrategy rss = new DefaultRecommendationStateStrategy(); - recStates.recommendationStates.put(mm, new RecommendationStateImpl(rss)); + recStates.recommendationStates.put(mm, new RecommendationStateImpl()); } return recStates; }