diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/Disambiguation.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/Disambiguation.java deleted file mode 100644 index 3a9574bc1..000000000 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/Disambiguation.java +++ /dev/null @@ -1,153 +0,0 @@ -/* Licensed under MIT 2023-2024. */ -package edu.kit.kastel.mcse.ardoco.core.api; - -import java.io.IOException; -import java.io.Serializable; -import java.util.*; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; - -/** - * This class represents an abbreviation with a known set of meanings. An abbreviation is a string such as "ArDoCo" and has the meaning "Architecture - * Documentation Consistency". The abbreviation that is disambiguated by the meanings of this class is final, but the meanings can be changed. An instance of - * this class can be serialized and deserialized into JSON using Jackson. - */ -@Deterministic -@JsonSerialize(using = Disambiguation.DisambiguationSerializer.class) -public class Disambiguation implements Comparable, Serializable { - private final String abbreviation; - private final SortedSet meanings; - - public String getAbbreviation() { - return abbreviation; - } - - public SortedSet getMeanings() { - return new TreeSet<>(meanings); - } - - @Override - public int compareTo(Disambiguation o) { - return abbreviation.compareTo(o.abbreviation); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj instanceof Disambiguation other) { - return getAbbreviation().equals(other.getAbbreviation()); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(getAbbreviation()); - } - - /** - * Used by the Jackson library to serialize a disambiguation into JSON format. - */ - public static class DisambiguationSerializer extends JsonSerializer { - @Override - public void serialize(Disambiguation abbreviation, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { - jsonGenerator.writeStartObject(); - jsonGenerator.writeStringField("abbreviation", abbreviation.abbreviation); - jsonGenerator.writeArrayFieldStart("meanings"); - var meanings = abbreviation.meanings; - for (var meaning : meanings) { - jsonGenerator.writeString(meaning); - } - jsonGenerator.writeEndArray(); - jsonGenerator.writeEndObject(); - } - } - - /** - * Creates a new disambiguation of the provided abbreviation using the given array of meanings. - * - * @param abbreviation the abbreviation that is disambiguated by this instance - * @param meanings an array of meanings for the abbreviation, may be empty - */ - @JsonCreator - public Disambiguation(@JsonProperty("abbreviation") String abbreviation, @JsonProperty("meanings") String[] meanings) { - this(abbreviation, new TreeSet<>(Arrays.stream(meanings).toList())); - } - - /** - * Creates a new disambiguation of the provided abbreviation using the given set of meanings. - * - * @param abbreviation the abbreviation that is disambiguated by this instance - * @param meanings a set of meanings for the abbreviation, may be empty - */ - public Disambiguation(String abbreviation, SortedSet meanings) { - this.abbreviation = abbreviation; - this.meanings = new TreeSet<>(meanings); - } - - /** - * Adds all meanings from another disambiguation to this disambiguation. Be careful, this does not perform any checks regarding the abbreviations. - * - * @param other the other disambiguation - * @return this - */ - public Disambiguation addMeanings(Disambiguation other) { - meanings.addAll(other.meanings); - return this; - } - - /** - * Searches the text for meanings contained by this disambiguation and replaces them with the abbreviation. - * - * @param text the text to search - * @param ignoreCase whether letter case should be ignored when searching for the meanings - * @return the abbreviated text - */ - public String replaceMeaningWithAbbreviation(String text, boolean ignoreCase) { - var abbreviatedText = text; - for (String meaning : meanings) { - String pattern = ignoreCase ? "(?i)" : ""; - pattern += meaning; - abbreviatedText = abbreviatedText.replaceAll(pattern, abbreviation); - } - return abbreviatedText; - } - - /** - * Merges the first map with the second map in a new map. If a key already exists, the disambiguations are merged non-destructively. - * - * @param a the first map - * @param b the second map - * @return a mutable map - */ - - public static SortedMap merge(SortedMap a, SortedMap b) { - var mergedMap = new TreeMap<>(a); - for (var entry : b.entrySet()) { - mergedMap.merge(entry.getKey(), entry.getValue(), Disambiguation::merge); - } - return mergedMap; - } - - /** - * Merges the first disambiguation with the second disambiguation into a new instance. - * - * @param a first ambiguation - * @param b second ambiguation - * @return new merged disambiguation - */ - - public static Disambiguation merge(Disambiguation a, Disambiguation b) { - var temp = new TreeSet<>(a.meanings); - temp.addAll(b.meanings); - return new Disambiguation(a.abbreviation, temp); - } -} diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/legacy/LegacyModelExtractionStateByArCoTL.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/legacy/LegacyModelExtractionStateByArCoTL.java index 8efd5b7e3..c5e5da60a 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/legacy/LegacyModelExtractionStateByArCoTL.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/legacy/LegacyModelExtractionStateByArCoTL.java @@ -83,7 +83,7 @@ private static ImmutableList initCodeInstances(CodeModel codeMode } private static void fillPackages(Collection packages, List instances) { - for (var modelElement : packages) { + for (var modelElement : packages) { String path = modelElement.getName(); CodeModule parent = modelElement.getParent(); while (parent != null) { diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/tracelink/TransitiveTraceLink.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/tracelink/TransitiveTraceLink.java index c6d5d4ef7..a7514a018 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/tracelink/TransitiveTraceLink.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/tracelink/TransitiveTraceLink.java @@ -28,8 +28,8 @@ public static Optional firstTraceLink, TraceLink secondTraceLink) { - var secondEndpointOfFirstTl = firstTraceLink.asPair().second().getId(); - var firstEndpointOfSecondTl = secondTraceLink.asPair().first().getId(); + var secondEndpointOfFirstTl = firstTraceLink.getSecondEndpoint().getId(); + var firstEndpointOfSecondTl = secondTraceLink.getFirstEndpoint().getId(); return secondEndpointOfFirstTl.equals(firstEndpointOfSecondTl); } diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/ConfusablesHelperTest.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/ConfusablesHelperTest.java index bb9b34090..74317fcd0 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/ConfusablesHelperTest.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/ConfusablesHelperTest.java @@ -9,18 +9,15 @@ import org.junit.jupiter.api.Test; -import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.ConfusablesHelper; -import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.UnicodeCharacter; - public class ConfusablesHelperTest { - public static final String example = """ + public static final String EXAMPLE = """ # ! ǃ ⵑ ! """; public static final List homoglyphsExample = Stream.of("!", "ǃ", "ⵑ", "!").map(UnicodeCharacter::valueOf).toList(); @Test void extractHomoglyphsFromLine() { - var homoglyphs = ConfusablesHelper.extractHomoglyphsFromLine(example); + var homoglyphs = ConfusablesHelper.extractHomoglyphsFromLine(EXAMPLE); assertEquals(homoglyphsExample.size(), homoglyphs.size()); assertTrue(homoglyphs.containsAll(homoglyphsExample)); } diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/WordSimUtilsTest.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/WordSimUtilsTest.java index 25deb3657..43886c4ea 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/WordSimUtilsTest.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/WordSimUtilsTest.java @@ -5,8 +5,6 @@ import org.junit.jupiter.api.Test; -import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.WordSimUtils; - class WordSimUtilsTest { @Test diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/jarowinkler/JaroWinklerMeasureTest.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/jarowinkler/JaroWinklerMeasureTest.java index af9bf7531..bc6031a02 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/jarowinkler/JaroWinklerMeasureTest.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/jarowinkler/JaroWinklerMeasureTest.java @@ -8,11 +8,9 @@ import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.ComparisonContext; import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.UnicodeCharacterMatchFunctions; -import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.jarowinkler.JaroWinklerMeasure; -import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.jarowinkler.UnicodeJaroWinklerSimilarity; class JaroWinklerMeasureTest { - private static final double delta = 0.01; + private static final double DELTA = 0.01; /** * These tests were extracted from the original {@link org.apache.commons.text.similarity.JaroWinklerSimilarity} implementation and should @@ -24,30 +22,30 @@ void testSimilarityDirectly() { assertThrows(IllegalArgumentException.class, () -> UnicodeJaroWinklerSimilarity.apply(s, s, UnicodeCharacterMatchFunctions.EQUAL)); assertThrows(IllegalArgumentException.class, () -> UnicodeJaroWinklerSimilarity.apply("foo", null, UnicodeCharacterMatchFunctions.EQUAL)); assertThrows(IllegalArgumentException.class, () -> UnicodeJaroWinklerSimilarity.apply(null, "foo", UnicodeCharacterMatchFunctions.EQUAL)); - assertEquals(1.0, UnicodeJaroWinklerSimilarity.apply("", "", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(1.0, UnicodeJaroWinklerSimilarity.apply("foo", "foo", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.94, UnicodeJaroWinklerSimilarity.apply("foo", "foo ", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.91, UnicodeJaroWinklerSimilarity.apply("foo", "foo ", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.87, UnicodeJaroWinklerSimilarity.apply("foo", " foo ", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.51, UnicodeJaroWinklerSimilarity.apply("foo", " foo", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("", "a", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("aaapppp", "", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.93, UnicodeJaroWinklerSimilarity.apply("frog", "fog", UnicodeCharacterMatchFunctions.EQUAL), delta); + assertEquals(1.0, UnicodeJaroWinklerSimilarity.apply("", "", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(1.0, UnicodeJaroWinklerSimilarity.apply("foo", "foo", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.94, UnicodeJaroWinklerSimilarity.apply("foo", "foo ", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.91, UnicodeJaroWinklerSimilarity.apply("foo", "foo ", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.87, UnicodeJaroWinklerSimilarity.apply("foo", " foo ", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.51, UnicodeJaroWinklerSimilarity.apply("foo", " foo", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("", "a", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("aaapppp", "", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.93, UnicodeJaroWinklerSimilarity.apply("frog", "fog", UnicodeCharacterMatchFunctions.EQUAL), DELTA); assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("fly", "ant", UnicodeCharacterMatchFunctions.EQUAL)); - assertEquals(0.44, UnicodeJaroWinklerSimilarity.apply("elephant", "hippo", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.44, UnicodeJaroWinklerSimilarity.apply("hippo", "elephant", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("hippo", "zzzzzzzz", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.88, UnicodeJaroWinklerSimilarity.apply("hello", "hallo", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.91, UnicodeJaroWinklerSimilarity.apply("ABC Corporation", "ABC Corp", UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.95, UnicodeJaroWinklerSimilarity.apply("D N H Enterprises Inc", "D & H Enterprises, Inc.", UnicodeCharacterMatchFunctions.EQUAL), delta); + assertEquals(0.44, UnicodeJaroWinklerSimilarity.apply("elephant", "hippo", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.44, UnicodeJaroWinklerSimilarity.apply("hippo", "elephant", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("hippo", "zzzzzzzz", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.88, UnicodeJaroWinklerSimilarity.apply("hello", "hallo", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.91, UnicodeJaroWinklerSimilarity.apply("ABC Corporation", "ABC Corp", UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.95, UnicodeJaroWinklerSimilarity.apply("D N H Enterprises Inc", "D & H Enterprises, Inc.", UnicodeCharacterMatchFunctions.EQUAL), DELTA); assertEquals(0.94, UnicodeJaroWinklerSimilarity.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness", - UnicodeCharacterMatchFunctions.EQUAL), delta); - assertEquals(0.89, UnicodeJaroWinklerSimilarity.apply("PENNSYLVANIA", "PENNCISYLVNIA", UnicodeCharacterMatchFunctions.EQUAL), delta); + UnicodeCharacterMatchFunctions.EQUAL), DELTA); + assertEquals(0.89, UnicodeJaroWinklerSimilarity.apply("PENNSYLVANIA", "PENNCISYLVNIA", UnicodeCharacterMatchFunctions.EQUAL), DELTA); } @Test void testHomoglyphSimilarity() { var measure = new JaroWinklerMeasure(); - assertEquals(1d, measure.getSimilarity(new ComparisonContext("ℜ𝘂ᖯʏ", "Ruby", UnicodeCharacterMatchFunctions.EQUAL_OR_HOMOGLYPH)), delta); + assertEquals(1d, measure.getSimilarity(new ComparisonContext("ℜ𝘂ᖯʏ", "Ruby", UnicodeCharacterMatchFunctions.EQUAL_OR_HOMOGLYPH)), DELTA); } } diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/levenshtein/LevenshteinMeasureTest.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/levenshtein/LevenshteinMeasureTest.java index 5b0bbfe49..2be083fd5 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/levenshtein/LevenshteinMeasureTest.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/levenshtein/LevenshteinMeasureTest.java @@ -8,11 +8,9 @@ import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.ComparisonContext; import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.UnicodeCharacterMatchFunctions; -import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.levenshtein.LevenshteinMeasure; -import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.levenshtein.UnicodeLevenshteinDistance; class LevenshteinMeasureTest { - private static final double delta = 0.01; + private static final double DELTA = 0.01; /** * These tests were extracted from the original {@link org.apache.commons.text.similarity.LevenshteinDistance} implementation and should still hold true. @@ -36,6 +34,6 @@ void testSimilarityDirectly() { @Test void testHomoglyphSimilarity() { var measure = new LevenshteinMeasure(); - assertEquals(1d, measure.getSimilarity(new ComparisonContext("ℜ𝘂ᖯʏ", "Ruby", UnicodeCharacterMatchFunctions.EQUAL_OR_HOMOGLYPH)), delta); + assertEquals(1d, measure.getSimilarity(new ComparisonContext("ℜ𝘂ᖯʏ", "Ruby", UnicodeCharacterMatchFunctions.EQUAL_OR_HOMOGLYPH)), DELTA); } } diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/ngram/NgramMeasureTest.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/ngram/NgramMeasureTest.java index b02253915..b7b1dcaf5 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/ngram/NgramMeasureTest.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/measures/ngram/NgramMeasureTest.java @@ -12,7 +12,6 @@ import org.junit.jupiter.api.Test; import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.ComparisonContext; -import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.ngram.NgramMeasure; class NgramMeasureTest { diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/vector/VectorUtilsTest.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/vector/VectorUtilsTest.java index c0b4696bd..218fc5f65 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/vector/VectorUtilsTest.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/similarity/wordsim/vector/VectorUtilsTest.java @@ -11,8 +11,6 @@ import org.junit.jupiter.api.Test; -import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.vector.VectorUtils; - class VectorUtilsTest { record Example(float[] firstVec, float[] secondVec, double expectedCosineSimilarity) { @@ -78,7 +76,7 @@ void testAdd() { assertThrows(NullPointerException.class, () -> VectorUtils.add(new double[0], null)); assertThrows(IllegalArgumentException.class, () -> VectorUtils.add(new double[1], new double[2])); - double[] result = new double[] { 1.0, 2.0 }; + double[] result = { 1.0, 2.0 }; VectorUtils.add(result, new double[] { 3.0, 4.0 }); assertArrayEquals(new double[] { 4.0, 6.0 }, result); } @@ -87,7 +85,7 @@ void testAdd() { void testScale() { assertThrows(NullPointerException.class, () -> VectorUtils.scale(null, 1.0)); - double[] result = new double[] { 1.0, 2.0 }; + double[] result = { 1.0, 2.0 }; VectorUtils.scale(result, 2.0); assertArrayEquals(new double[] { 2.0, 4.0 }, result); }