diff --git a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/TraceLinkEvaluationIT.java b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/TraceLinkEvaluationIT.java index 2ef5234..72143f7 100644 --- a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/TraceLinkEvaluationIT.java +++ b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/TraceLinkEvaluationIT.java @@ -34,7 +34,7 @@ import edu.kit.kastel.mcse.ardoco.core.tests.eval.GoldStandardProject; import edu.kit.kastel.mcse.ardoco.core.tests.eval.Project; import edu.kit.kastel.mcse.ardoco.core.tests.eval.results.EvaluationResults; -import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelSentenceLink; +import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelElementSentenceLink; import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.files.TLDiffFile; import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.files.TLLogFile; import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.files.TLModelFile; @@ -52,7 +52,7 @@ class TraceLinkEvaluationIT { protected static final String LOGGING_ARDOCO_CORE = "org.slf4j.simpleLogger.log.edu.kit.kastel.mcse.ardoco.core"; protected static AtomicBoolean analyzeCodeDirectly = ANALYZE_CODE_DIRECTLY; - protected static final List>> RESULTS = new ArrayList<>(); + protected static final List>> RESULTS = new ArrayList<>(); protected static final Map DATA_MAP = new LinkedHashMap<>(); @BeforeAll diff --git a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/TraceLinkEvaluationSadCodeDirectIT.java b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/TraceLinkEvaluationSadCodeDirectIT.java index f6e3832..9735312 100644 --- a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/TraceLinkEvaluationSadCodeDirectIT.java +++ b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/TraceLinkEvaluationSadCodeDirectIT.java @@ -27,7 +27,7 @@ import edu.kit.kastel.mcse.ardoco.core.tests.eval.CodeProject; import edu.kit.kastel.mcse.ardoco.core.tests.eval.GoldStandardProject; import edu.kit.kastel.mcse.ardoco.core.tests.eval.results.EvaluationResults; -import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelSentenceLink; +import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelElementSentenceLink; import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.files.TLDiffFile; import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.files.TLLogFile; import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.files.TLModelFile; @@ -42,7 +42,7 @@ class TraceLinkEvaluationSadCodeDirectIT { protected static final String LOGGING_ARDOCO_CORE = "org.slf4j.simpleLogger.log.edu.kit.kastel.mcse.ardoco.core"; - protected static final List>> RESULTS = new ArrayList<>(); + protected static final List>> RESULTS = new ArrayList<>(); protected static final Map DATA_MAP = new LinkedHashMap<>(); @BeforeAll diff --git a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/ModelSentenceLink.java b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/ModelElementSentenceLink.java similarity index 51% rename from tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/ModelSentenceLink.java rename to tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/ModelElementSentenceLink.java index ac7b803..44fd3bd 100644 --- a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/ModelSentenceLink.java +++ b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/ModelElementSentenceLink.java @@ -8,15 +8,15 @@ /** * Represents a simple trace link by the id of the model and number of the sentence involved. */ -public record ModelSentenceLink(String modelId, int sentenceNr) implements Comparable { +public record ModelElementSentenceLink(String modelElementId, int sentenceNr) implements Comparable { - public ModelSentenceLink(SadSamTraceLink traceLink) { + public ModelElementSentenceLink(SadSamTraceLink traceLink) { this(traceLink.getModelElementUid(), traceLink.getSentenceNumber()); } @Override - public int compareTo(ModelSentenceLink o) { - return Comparator.comparing(ModelSentenceLink::modelId).thenComparing(ModelSentenceLink::sentenceNr).compare(this, o); + public int compareTo(ModelElementSentenceLink o) { + return Comparator.comparing(ModelElementSentenceLink::modelElementId).thenComparing(ModelElementSentenceLink::sentenceNr).compare(this, o); } } diff --git a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/TLRUtil.java b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/TLRUtil.java index e245182..e21bf0d 100644 --- a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/TLRUtil.java +++ b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/TLRUtil.java @@ -28,8 +28,8 @@ private TLRUtil() { * @param data the {@link EvaluationResults} * @return the trace links */ - public static ImmutableList getTraceLinks(DataRepository data) { - var traceLinks = Lists.mutable.empty(); + public static ImmutableList getTraceLinks(DataRepository data) { + var traceLinks = Lists.mutable.empty(); var connectionStates = data.getData(ConnectionStates.ID, ConnectionStates.class).orElseThrow(); var modelStates = data.getData(ModelStates.ID, ModelStates.class).orElseThrow(); @@ -40,7 +40,7 @@ public static ImmutableList getTraceLinks(DataRepository data .map(connectionStates::getConnectionState) .toList(); for (var connectionState : connectionStatesList) { - traceLinks.addAll(connectionState.getTraceLinks().stream().map(ModelSentenceLink::new).toList()); + traceLinks.addAll(connectionState.getTraceLinks().stream().map(ModelElementSentenceLink::new).toList()); } return traceLinks.toImmutable(); } diff --git a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLDiffFile.java b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLDiffFile.java index 43d0257..cf8516d 100644 --- a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLDiffFile.java +++ b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLDiffFile.java @@ -17,7 +17,7 @@ import edu.kit.kastel.mcse.ardoco.core.common.util.CommonUtilities; import edu.kit.kastel.mcse.ardoco.core.tests.eval.GoldStandardProject; import edu.kit.kastel.mcse.ardoco.core.tests.eval.results.EvaluationResults; -import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelSentenceLink; +import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelElementSentenceLink; /** * This is a helper class to write out a diff-file for the evaluation results of TLR. @@ -40,9 +40,9 @@ private TLDiffFile() { * @param dataMap the mapping of Project to ArDoCoResult of the new run * @throws IOException if writing fails */ - public static void save(Path targetFile, Collection>> newProjectResults, - Collection>> oldProjectResults, Map dataMap) - throws IOException { + public static void save(Path targetFile, Collection>> newProjectResults, + Collection>> oldProjectResults, + Map dataMap) throws IOException { // Assumption: Both collections contain the same projects newProjectResults = newProjectResults.stream().sorted(Comparator.comparing(x -> x.getOne().getProjectName())).toList(); @@ -71,7 +71,7 @@ public static void save(Path targetFile, Collection> oldProjectResult : oldProjectResults) { + for (Pair> oldProjectResult : oldProjectResults) { var project = oldProjectResult.getOne(); var newResultOptional = newProjectResults.stream().filter(r -> r.getOne().equals(project)).findAny(); if (newResultOptional.isEmpty()) { @@ -107,15 +107,15 @@ public static void save(Path targetFile, Collection findNewLinks(List oldLinks, List newLinks) { + private static List findNewLinks(List oldLinks, List newLinks) { return newLinks.stream().filter(link -> !oldLinks.contains(link)).toList(); } - private static List findMissingLinks(List oldLinks, List newLinks) { + private static List findMissingLinks(List oldLinks, List newLinks) { return oldLinks.stream().filter(link -> !newLinks.contains(link)).toList(); } - private static void appendList(StringBuilder builder, String description, List links, ArDoCoResult arDoCoResult) { + private static void appendList(StringBuilder builder, String description, List links, ArDoCoResult arDoCoResult) { var text = arDoCoResult.getText(); if (links.isEmpty()) { return; @@ -124,7 +124,7 @@ private static void appendList(StringBuilder builder, String description, List loadLinks(GoldStandardProject goldStandardProject) throws IOException { + public static MutableList loadLinks(GoldStandardProject goldStandardProject) throws IOException { Path path = goldStandardProject.getTlrGoldStandardFile().toPath(); List lines = Files.readAllLines(path); return Lists.mutable.ofAll(lines.stream() .skip(1) // skip csv header .map(line -> line.split(",")) // modelElementId,sentenceNr - .map(array -> new ModelSentenceLink(array[0], Integer.parseInt(array[1]))) - .map(link -> new ModelSentenceLink(link.modelId(), link.sentenceNr() - 1)) + .map(array -> new ModelElementSentenceLink(array[0], Integer.parseInt(array[1]))) + .map(link -> new ModelElementSentenceLink(link.modelElementId(), link.sentenceNr() - 1)) // ^ goldstandard sentences start with 1 while ISentences are zero indexed .toList()); } diff --git a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLLogFile.java b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLLogFile.java index 1cba93a..9d1d81a 100644 --- a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLLogFile.java +++ b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLLogFile.java @@ -15,7 +15,7 @@ import edu.kit.kastel.mcse.ardoco.core.common.util.CommonUtilities; import edu.kit.kastel.mcse.ardoco.core.tests.eval.GoldStandardProject; import edu.kit.kastel.mcse.ardoco.core.tests.eval.results.EvaluationResults; -import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelSentenceLink; +import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelElementSentenceLink; /** * This helper-class offer functionality to write out a log of the results for TLR. @@ -35,8 +35,8 @@ private TLLogFile() { * @param projectResults the results to write out * @throws IOException if writing to file system fails */ - public static void append(Path targetFile, List>> projectResults) throws IOException { - List> results = projectResults.stream().map(Pair::getTwo).toList(); + public static void append(Path targetFile, List>> projectResults) throws IOException { + List> results = projectResults.stream().map(Pair::getTwo).toList(); var builder = new StringBuilder(); builder.append("- `").append(CommonUtilities.getCurrentTimeAsString()).append("` "); @@ -50,9 +50,9 @@ public static void append(Path targetFile, List(projectResults); sortedResults.sort(Comparator.comparing(x -> x.getOne().getProjectName())); - for (Pair> projectResult : sortedResults) { + for (Pair> projectResult : sortedResults) { String alias = projectResult.getOne().getAlias(); - EvaluationResults result = projectResult.getTwo(); + EvaluationResults result = projectResult.getTwo(); String precision = NUMBER_FORMAT.format(result.precision()); String recall = NUMBER_FORMAT.format(result.recall()); String F1 = NUMBER_FORMAT.format(result.f1()); diff --git a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLPreviousFile.java b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLPreviousFile.java index 1151c1f..cdc7ad0 100644 --- a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLPreviousFile.java +++ b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLPreviousFile.java @@ -22,7 +22,7 @@ import edu.kit.kastel.mcse.ardoco.core.tests.eval.GoldStandardProject; import edu.kit.kastel.mcse.ardoco.core.tests.eval.Project; import edu.kit.kastel.mcse.ardoco.core.tests.eval.results.EvaluationResults; -import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelSentenceLink; +import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelElementSentenceLink; /** * This is a helper class to load and write out the results of the previous evaluation run for TLR results. @@ -41,11 +41,11 @@ private TLPreviousFile() { * @return the previous results * @throws IOException if file access fails */ - public static Collection>> load(Path sourceFile, + public static Collection>> load(Path sourceFile, final Map DATA_MAP) throws IOException { List lines = Files.readAllLines(sourceFile); - Map> foundLinkMap = new LinkedHashMap<>(); - List>> results = new ArrayList<>(); + Map> foundLinkMap = new LinkedHashMap<>(); + List>> results = new ArrayList<>(); for (String line : lines) { var parts = line.split(",", -1); @@ -53,7 +53,7 @@ public static Collection()); @@ -82,7 +82,7 @@ public static Collection>> projectResults, Logger logger) + public static void save(Path targetFile, Collection>> projectResults, Logger logger) throws IOException { if (Files.exists(targetFile)) { logger.warn("File with the results of the previous evaluation run already exists."); @@ -94,12 +94,12 @@ public static void save(Path targetFile, Collection> projectResult : sortedResults) { - EvaluationResults result = projectResult.getTwo(); - for (ModelSentenceLink foundLink : result.getFound()) { + for (Pair> projectResult : sortedResults) { + EvaluationResults result = projectResult.getTwo(); + for (ModelElementSentenceLink foundLink : result.getFound()) { builder.append(projectResult.getOne().getProjectName()); builder.append(','); - builder.append(foundLink.modelId()); + builder.append(foundLink.modelElementId()); builder.append(','); builder.append(foundLink.sentenceNr()); builder.append(LINE_SEPARATOR); diff --git a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLSummaryFile.java b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLSummaryFile.java index 6ddd9a0..9044eb0 100644 --- a/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLSummaryFile.java +++ b/tests/integration-tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/tlr/tests/integration/tlrhelper/files/TLSummaryFile.java @@ -21,7 +21,7 @@ import edu.kit.kastel.mcse.ardoco.core.tests.eval.GoldStandardProject; import edu.kit.kastel.mcse.ardoco.core.tests.eval.results.EvaluationResults; import edu.kit.kastel.mcse.ardoco.core.tests.eval.results.calculator.ResultCalculatorUtil; -import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelSentenceLink; +import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelElementSentenceLink; /** * This helper class offers functionality to write out a summary of the TLR evaluation runs for all projects. @@ -42,7 +42,7 @@ private TLSummaryFile() { * @param dataMap the outcomes (data) of the runs * @throws IOException if writing to file system fails */ - public static void save(Path targetFile, Collection>> results, + public static void save(Path targetFile, Collection>> results, Map dataMap) throws IOException { var sortedResults = results.stream().sorted().toList(); var builder = new StringBuilder(); @@ -61,7 +61,7 @@ public static void save(Path targetFile, Collection dataMap, StringBuilder builder, - Pair> projectResult) { + Pair> projectResult) { var data = dataMap.get(projectResult.getOne()); var text = data.getText(); @@ -106,11 +106,11 @@ private static void appendOverallResults(List falseLinks, ArDoCoResult data, Text text) { + private static String createFalseLinksOutput(String type, List falseLinks, ArDoCoResult data, Text text) { var builder = new StringBuilder(); builder.append(type).append(":").append(LINE_SEPARATOR); - for (ModelSentenceLink falseLink : falseLinks) { + for (ModelElementSentenceLink falseLink : falseLinks) { builder.append(createFalseLinkOutput(data, text, falseLink)); } @@ -118,7 +118,7 @@ private static String createFalseLinksOutput(String type, List m.getUid().equals(link.modelId())).findAny().orElse(null); + static String format(ModelElementSentenceLink link, Text text, LegacyModelExtractionState modelState) { + var model = modelState.getInstances().stream().filter(m -> m.getUid().equals(link.modelElementId())).findAny().orElse(null); var sentence = text.getSentences().stream().filter(s -> s.getSentenceNumber() == link.sentenceNr()).findAny().orElse(null); if (model == null && sentence == null) { return null; } - var modelStr = model == null ? link.modelId() : "\"" + model.getFullName() + "\""; + var modelStr = model == null ? link.modelElementId() : "\"" + model.getFullName() + "\""; var sentenceStr = sentence == null ? String.valueOf(link.sentenceNr()) : "\"" + sentence.getText() + "\""; - return String.format("%s ⇔ %s [%s,%s]", modelStr, sentenceStr, link.modelId(), link.sentenceNr()); + return String.format("%s ⇔ %s [%s,%s]", modelStr, sentenceStr, link.modelElementId(), link.sentenceNr()); } }