Skip to content

Commit

Permalink
Fix Name of Link
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Aug 21, 2024
1 parent a874407 commit 33de997
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,7 +52,7 @@ class TraceLinkEvaluationIT<T extends GoldStandardProject> {
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<Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>>> RESULTS = new ArrayList<>();
protected static final List<Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>>> RESULTS = new ArrayList<>();
protected static final Map<GoldStandardProject, ArDoCoResult> DATA_MAP = new LinkedHashMap<>();

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>>> RESULTS = new ArrayList<>();
protected static final List<Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>>> RESULTS = new ArrayList<>();
protected static final Map<GoldStandardProject, ArDoCoResult> DATA_MAP = new LinkedHashMap<>();

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModelSentenceLink> {
public record ModelElementSentenceLink(String modelElementId, int sentenceNr) implements Comparable<ModelElementSentenceLink> {

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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ private TLRUtil() {
* @param data the {@link EvaluationResults}
* @return the trace links
*/
public static ImmutableList<ModelSentenceLink> getTraceLinks(DataRepository data) {
var traceLinks = Lists.mutable.<ModelSentenceLink>empty();
public static ImmutableList<ModelElementSentenceLink> getTraceLinks(DataRepository data) {
var traceLinks = Lists.mutable.<ModelElementSentenceLink>empty();
var connectionStates = data.getData(ConnectionStates.ID, ConnectionStates.class).orElseThrow();
var modelStates = data.getData(ModelStates.ID, ModelStates.class).orElseThrow();

Expand All @@ -40,7 +40,7 @@ public static ImmutableList<ModelSentenceLink> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>>> newProjectResults,
Collection<Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>>> oldProjectResults, Map<GoldStandardProject, ArDoCoResult> dataMap)
throws IOException {
public static void save(Path targetFile, Collection<Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>>> newProjectResults,
Collection<Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>>> oldProjectResults,
Map<GoldStandardProject, ArDoCoResult> dataMap) throws IOException {
// Assumption: Both collections contain the same projects

newProjectResults = newProjectResults.stream().sorted(Comparator.comparing(x -> x.getOne().getProjectName())).toList();
Expand Down Expand Up @@ -71,7 +71,7 @@ public static void save(Path targetFile, Collection<Pair<GoldStandardProject, Ev
builder.append(LINE_SEPARATOR).append(LINE_SEPARATOR);

// Append project specific details
for (Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>> oldProjectResult : oldProjectResults) {
for (Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>> oldProjectResult : oldProjectResults) {
var project = oldProjectResult.getOne();
var newResultOptional = newProjectResults.stream().filter(r -> r.getOne().equals(project)).findAny();
if (newResultOptional.isEmpty()) {
Expand Down Expand Up @@ -107,15 +107,15 @@ public static void save(Path targetFile, Collection<Pair<GoldStandardProject, Ev
Files.writeString(targetFile, builder.toString(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}

private static List<ModelSentenceLink> findNewLinks(List<ModelSentenceLink> oldLinks, List<ModelSentenceLink> newLinks) {
private static List<ModelElementSentenceLink> findNewLinks(List<ModelElementSentenceLink> oldLinks, List<ModelElementSentenceLink> newLinks) {
return newLinks.stream().filter(link -> !oldLinks.contains(link)).toList();
}

private static List<ModelSentenceLink> findMissingLinks(List<ModelSentenceLink> oldLinks, List<ModelSentenceLink> newLinks) {
private static List<ModelElementSentenceLink> findMissingLinks(List<ModelElementSentenceLink> oldLinks, List<ModelElementSentenceLink> newLinks) {
return oldLinks.stream().filter(link -> !newLinks.contains(link)).toList();
}

private static void appendList(StringBuilder builder, String description, List<ModelSentenceLink> links, ArDoCoResult arDoCoResult) {
private static void appendList(StringBuilder builder, String description, List<ModelElementSentenceLink> links, ArDoCoResult arDoCoResult) {
var text = arDoCoResult.getText();
if (links.isEmpty()) {
return;
Expand All @@ -124,7 +124,7 @@ private static void appendList(StringBuilder builder, String description, List<M
builder.append(description).append(":");
builder.append(LINE_SEPARATOR);

for (ModelSentenceLink link : links) {
for (ModelElementSentenceLink link : links) {
for (var modelId : arDoCoResult.getModelIds()) {
var dataModel = arDoCoResult.getModelState(modelId);
var line = TLSummaryFile.format(link, text, dataModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.eclipse.collections.api.list.MutableList;

import edu.kit.kastel.mcse.ardoco.core.tests.eval.GoldStandardProject;
import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelSentenceLink;
import edu.kit.kastel.mcse.ardoco.tlr.tests.integration.tlrhelper.ModelElementSentenceLink;

public class TLGoldStandardFile {

Expand All @@ -19,15 +19,15 @@ private TLGoldStandardFile() {
throw new IllegalAccessError("No instantiation allowed");
}

public static MutableList<ModelSentenceLink> loadLinks(GoldStandardProject goldStandardProject) throws IOException {
public static MutableList<ModelElementSentenceLink> loadLinks(GoldStandardProject goldStandardProject) throws IOException {
Path path = goldStandardProject.getTlrGoldStandardFile().toPath();
List<String> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>>> projectResults) throws IOException {
List<EvaluationResults<ModelSentenceLink>> results = projectResults.stream().map(Pair::getTwo).toList();
public static void append(Path targetFile, List<Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>>> projectResults) throws IOException {
List<EvaluationResults<ModelElementSentenceLink>> results = projectResults.stream().map(Pair::getTwo).toList();
var builder = new StringBuilder();

builder.append("- `").append(CommonUtilities.getCurrentTimeAsString()).append("` ");
Expand All @@ -50,9 +50,9 @@ public static void append(Path targetFile, List<Pair<GoldStandardProject, Evalua

var sortedResults = new ArrayList<>(projectResults);
sortedResults.sort(Comparator.comparing(x -> x.getOne().getProjectName()));
for (Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>> projectResult : sortedResults) {
for (Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>> projectResult : sortedResults) {
String alias = projectResult.getOne().getAlias();
EvaluationResults<ModelSentenceLink> result = projectResult.getTwo();
EvaluationResults<ModelElementSentenceLink> result = projectResult.getTwo();
String precision = NUMBER_FORMAT.format(result.precision());
String recall = NUMBER_FORMAT.format(result.recall());
String F1 = NUMBER_FORMAT.format(result.f1());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -41,19 +41,19 @@ private TLPreviousFile() {
* @return the previous results
* @throws IOException if file access fails
*/
public static Collection<Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>>> load(Path sourceFile,
public static Collection<Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>>> load(Path sourceFile,
final Map<GoldStandardProject, ArDoCoResult> DATA_MAP) throws IOException {
List<String> lines = Files.readAllLines(sourceFile);
Map<Project, List<ModelSentenceLink>> foundLinkMap = new LinkedHashMap<>();
List<Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>>> results = new ArrayList<>();
Map<Project, List<ModelElementSentenceLink>> foundLinkMap = new LinkedHashMap<>();
List<Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>>> results = new ArrayList<>();

for (String line : lines) {
var parts = line.split(",", -1);
Project project = Project.valueOf(parts[0]);
String modelId = parts[1];
int sentenceNr = Integer.parseInt(parts[2]);

var testLink = new ModelSentenceLink(modelId, sentenceNr);
var testLink = new ModelElementSentenceLink(modelId, sentenceNr);

if (!foundLinkMap.containsKey(project)) {
foundLinkMap.put(project, new ArrayList<>());
Expand Down Expand Up @@ -82,7 +82,7 @@ public static Collection<Pair<GoldStandardProject, EvaluationResults<ModelSenten
* @param projectResults results to save
* @throws IOException if writing to file system fails
*/
public static void save(Path targetFile, Collection<Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>>> projectResults, Logger logger)
public static void save(Path targetFile, Collection<Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>>> projectResults, Logger logger)
throws IOException {
if (Files.exists(targetFile)) {
logger.warn("File with the results of the previous evaluation run already exists.");
Expand All @@ -94,12 +94,12 @@ public static void save(Path targetFile, Collection<Pair<GoldStandardProject, Ev

var builder = new StringBuilder();

for (Pair<GoldStandardProject, EvaluationResults<ModelSentenceLink>> projectResult : sortedResults) {
EvaluationResults<ModelSentenceLink> result = projectResult.getTwo();
for (ModelSentenceLink foundLink : result.getFound()) {
for (Pair<GoldStandardProject, EvaluationResults<ModelElementSentenceLink>> projectResult : sortedResults) {
EvaluationResults<ModelElementSentenceLink> 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);
Expand Down
Loading

0 comments on commit 33de997

Please sign in to comment.