Skip to content

Commit

Permalink
Remove RecommendationStateStrategy, since not used
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Dec 6, 2024
1 parent 9a2eac4 commit 5a4c627
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,16 +19,15 @@
*/
public class RecommendationStateImpl extends AbstractState implements RecommendationState {

private final RecommendationStateStrategy recommendationStateStrategy;
private static final long serialVersionUID = 3088770775218314854L;
private MutableSortedSet<RecommendedInstance> 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();
}

/**
Expand All @@ -38,7 +37,7 @@ public RecommendationStateImpl(RecommendationStateStrategy recommendationStateSt
*/
@Override
public ImmutableList<RecommendedInstance> getRecommendedInstances() {
return Lists.immutable.withAll(recommendedInstances);
return Lists.immutable.withAll(this.recommendedInstances);
}

/**
Expand Down Expand Up @@ -77,28 +76,28 @@ 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());
}
}

private void processRecommendedInstancesWithNoExactNameAndType(RecommendedInstance ri, ImmutableList<RecommendedInstance> 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;
Expand All @@ -107,7 +106,7 @@ private void processRecommendedInstancesWithNoExactNameAndType(RecommendedInstan
}

if (!added && !ri.getType().isBlank()) {
recommendedInstances.add(ri);
this.recommendedInstances.add(ri);
}
}
}
Expand All @@ -124,7 +123,7 @@ private static boolean recommendedInstancesHasEmptyType(RecommendedInstance ri,
*/
@Override
public ImmutableList<RecommendedInstance> getRecommendedInstancesByTypeMapping(NounMapping mapping) {
return recommendedInstances.select(sinstance -> sinstance.getTypeMappings().contains(mapping)).toImmutableList();
return this.recommendedInstances.select(sinstance -> sinstance.getTypeMappings().contains(mapping)).toImmutableList();
}

/**
Expand All @@ -135,7 +134,7 @@ public ImmutableList<RecommendedInstance> getRecommendedInstancesByTypeMapping(N
*/
@Override
public ImmutableList<RecommendedInstance> getAnyRecommendedInstancesByMapping(NounMapping mapping) {
return recommendedInstances //
return this.recommendedInstances //
.select(sinstance -> sinstance.getTypeMappings().contains(mapping) || sinstance.getNameMappings().contains(mapping))
.toImmutableList();
}
Expand All @@ -148,7 +147,7 @@ public ImmutableList<RecommendedInstance> getAnyRecommendedInstancesByMapping(No
*/
@Override
public ImmutableList<RecommendedInstance> 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();
}

/**
Expand All @@ -160,8 +159,8 @@ public ImmutableList<RecommendedInstance> getRecommendedInstancesByName(String n
@Override
public ImmutableList<RecommendedInstance> getRecommendedInstancesBySimilarName(String name) {
MutableList<RecommendedInstance> 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);
}
}
Expand All @@ -177,7 +176,7 @@ public ImmutableList<RecommendedInstance> getRecommendedInstancesBySimilarName(S
*/
@Override
public ImmutableList<RecommendedInstance> 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();
}

/**
Expand All @@ -188,6 +187,6 @@ public ImmutableList<RecommendedInstance> getRecommendedInstancesByType(String t
*/
@Override
public ImmutableList<RecommendedInstance> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Metamodel, RecommendationStateImpl> recommendationStates;

private RecommendationStatesImpl() {
Expand All @@ -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;
}
Expand Down

0 comments on commit 5a4c627

Please sign in to comment.