Skip to content

Commit

Permalink
InstanceLinks are TraceLinks
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Dec 9, 2024
1 parent c76c861 commit 1ade956
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected Entity(String name) {

protected Entity(String name, String id) {
this.id = Objects.requireNonNull(id);
this.name = name;
this.name = Objects.requireNonNull(name);
}

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ public interface ConnectionState extends IConfigurable {
*
* @return all instance links
*/
ImmutableList<InstanceLink> getInstanceLinks();
ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinks();

/**
* Returns all instance links with a model instance containing the given name.
*
* @param name the name of a model instance
* @return all instance links with a model instance containing the given name as list
*/
ImmutableList<InstanceLink> getInstanceLinksByName(String name);
ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinksByName(String name);

/**
* Returns all instance links with a model instance containing the given type.
*
* @param type the type of a model instance
* @return all instance links with a model instance containing the given type as list
*/
ImmutableList<InstanceLink> getInstanceLinksByType(String type);
ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinksByType(String type);

/**
* Returns all instance links with a model instance containing the given recommended instance.
*
* @param recommendedInstance the recommended instance to consider
* @return all instance links found
*/
ImmutableList<InstanceLink> getInstanceLinksByRecommendedInstance(RecommendedInstance recommendedInstance);
ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinksByRecommendedInstance(RecommendedInstance recommendedInstance);

/**
* Returns all instance links with a model instance containing the given name and type.
Expand All @@ -60,7 +60,7 @@ public interface ConnectionState extends IConfigurable {
* @param type the type of a model instance
* @return all instance links with a model instance containing the given name and type as list
*/
ImmutableList<InstanceLink> getInstanceLinks(String name, String type);
ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinks(String name, String type);

/**
* Returns a list of tracelinks that are contained within this connection state.
Expand All @@ -69,11 +69,11 @@ public interface ConnectionState extends IConfigurable {
*/
default ImmutableSet<TraceLink<SentenceEntity, ArchitectureEntity>> getTraceLinks() {
MutableSet<TraceLink<SentenceEntity, ArchitectureEntity>> traceLinks = Sets.mutable.empty();
for (var instanceLink : getInstanceLinks()) {
var textualInstance = instanceLink.getTextualInstance();
for (var instanceLink : this.getInstanceLinks()) {
var textualInstance = instanceLink.getFirstEndpoint();
for (var nm : textualInstance.getNameMappings()) {
for (var word : nm.getWords()) {
var traceLink = new SadSamTraceLink(word.getSentence(), instanceLink.getModelInstance());
var traceLink = new SadSamTraceLink(word.getSentence(), instanceLink.getSecondEndpoint());
traceLinks.add(traceLink);
}
}
Expand All @@ -98,14 +98,14 @@ default ImmutableSet<TraceLink<SentenceEntity, ArchitectureEntity>> getTraceLink
* @param instanceLink the given instance link
* @return true if it is already contained
*/
boolean isContainedByInstanceLinks(InstanceLink instanceLink);
boolean isContainedByInstanceLinks(TraceLink<RecommendedInstance, ModelInstance> instanceLink);

/**
* Removes an instance link from the state.
*
* @param instanceMapping the instance link to remove
*/
void removeFromMappings(InstanceLink instanceMapping);
void removeFromMappings(TraceLink<RecommendedInstance, ModelInstance> instanceMapping);

/**
* Removes all instance links containing the given instance.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* Licensed under MIT 2021-2024. */
package edu.kit.kastel.mcse.ardoco.core.api.stage.connectiongenerator;

import java.io.Serializable;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

import org.eclipse.collections.api.factory.Lists;
Expand All @@ -13,6 +11,7 @@
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.legacy.ModelInstance;
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.api.tracelink.TraceLink;
import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic;
import edu.kit.kastel.mcse.ardoco.core.common.AggregationFunctions;
import edu.kit.kastel.mcse.ardoco.core.data.Confidence;
Expand All @@ -22,12 +21,9 @@
* An InstanceLink defines a link between an {@link RecommendedInstance} and an {@link ModelInstance}.
*/
@Deterministic
public class InstanceLink implements Serializable {
public class InstanceLink extends TraceLink<RecommendedInstance, ModelInstance> {

private static final long serialVersionUID = -8630933950725516269L;

private final RecommendedInstance textualInstance;
private final ModelInstance modelInstance;
private final Confidence confidence;

/**
Expand All @@ -37,8 +33,7 @@ public class InstanceLink implements Serializable {
* @param modelInstance the model instance
*/
public InstanceLink(RecommendedInstance textualInstance, ModelInstance modelInstance) {
this.textualInstance = textualInstance;
this.modelInstance = modelInstance;
super(textualInstance, modelInstance);
this.confidence = new Confidence(AggregationFunctions.AVERAGE);
}

Expand Down Expand Up @@ -74,58 +69,24 @@ public final double getConfidence() {
return this.confidence.getConfidence();
}

/**
* Returns the recommended instance.
*
* @return the textual instance
*/
public final RecommendedInstance getTextualInstance() {
return this.textualInstance;
}

/**
* Returns the model instance.
*
* @return the extracted instance
*/
public final ModelInstance getModelInstance() {
return this.modelInstance;
}

@Override
public int hashCode() {
return Objects.hash(this.modelInstance, this.textualInstance);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof InstanceLink other)) {
return false;
}
return Objects.equals(this.getModelInstance(), other.getModelInstance()) && Objects.equals(this.getTextualInstance(), other.getTextualInstance());
}

@Override
public String toString() {
Set<String> names = new LinkedHashSet<>();
MutableList<Integer> namePositions = Lists.mutable.empty();
Set<String> types = new LinkedHashSet<>();
MutableList<Integer> typePositions = Lists.mutable.empty();

for (NounMapping nameMapping : this.textualInstance.getNameMappings()) {
for (NounMapping nameMapping : this.getFirstEndpoint().getNameMappings()) {
names.addAll(nameMapping.getSurfaceForms().castToCollection());
namePositions.addAll(nameMapping.getMappingSentenceNo().castToCollection());
}
for (NounMapping typeMapping : this.textualInstance.getTypeMappings()) {
for (NounMapping typeMapping : this.getFirstEndpoint().getTypeMappings()) {
types.addAll(typeMapping.getSurfaceForms().castToCollection());
typePositions.addAll(typeMapping.getMappingSentenceNo().castToCollection());
}
return "InstanceMapping [ uid=" + this.modelInstance.getUid() + ", name=" + this.modelInstance.getFullName() + //
", as=" + String.join(", ", this.modelInstance.getFullType()) + ", probability=" + this.getConfidence() + ", FOUND: " + //
this.textualInstance.getName() + " : " + this.textualInstance.getType() + ", occurrences= " + //
return "InstanceMapping [ uid=" + this.getSecondEndpoint().getUid() + ", name=" + this.getSecondEndpoint().getFullName() + //
", as=" + String.join(", ", this.getSecondEndpoint().getFullType()) + ", probability=" + this.getConfidence() + ", FOUND: " + //
this.getFirstEndpoint().getName() + " : " + this.getFirstEndpoint().getType() + ", occurrences= " + //
"NameVariants: " + names.size() + ": " + names + " sentences{" + Arrays.toString(namePositions.toArray()) + "}" + //
", TypeVariants: " + types.size() + ": " + types + "sentences{" + Arrays.toString(typePositions.toArray()) + "}" + "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ImmutableList<TraceLink<SentenceEntity, ArchitectureEntity>> getAllTraceL
MutableSet<TraceLink<SentenceEntity, ArchitectureEntity>> traceLinks = Sets.mutable.empty();

for (var modelId : this.getModelIds()) {
if (this.getModelState(modelId).getMetamodel() == Metamodel.ARCHITECTURE) {
if (modelId == Metamodel.ARCHITECTURE) {
traceLinks.addAll(this.getTraceLinksForModel(modelId).castToCollection());
}
}
Expand Down Expand Up @@ -255,8 +255,7 @@ public Sentence getSentence(int sentenceNo) {
public ConnectionState getConnectionState(Metamodel modelId) {
if (DataRepositoryHelper.hasConnectionStates(this.dataRepository)) {
var connectionStates = DataRepositoryHelper.getConnectionStates(this.dataRepository);
var modelState = this.getModelState(modelId);
return connectionStates.getConnectionState(modelState.getMetamodel());
return connectionStates.getConnectionState(modelId);
}
ArDoCoResult.logger.warn("No ConnectionState found.");
return null;
Expand All @@ -271,8 +270,7 @@ public ConnectionState getConnectionState(Metamodel modelId) {
public InconsistencyState getInconsistencyState(Metamodel modelId) {
if (DataRepositoryHelper.hasInconsistencyStates(this.dataRepository)) {
var inconsistencyStates = DataRepositoryHelper.getInconsistencyStates(this.dataRepository);
var modelState = this.getModelState(modelId);
return inconsistencyStates.getInconsistencyState(modelState.getMetamodel());
return inconsistencyStates.getInconsistencyState(modelId);
}
ArDoCoResult.logger.warn("No InconsistencyState found.");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
public class ProjectPipelineDataImpl implements ProjectPipelineData {

private static final long serialVersionUID = -993634357212795104L;
private final String projectName;

/**
Expand All @@ -22,6 +23,6 @@ public class ProjectPipelineDataImpl implements ProjectPipelineData {

@Override
public String getProjectName() {
return projectName;
return this.projectName;
}
}

0 comments on commit 1ade956

Please sign in to comment.