Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor model #278

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* Licensed under MIT 2021-2023. */
package edu.kit.kastel.mcse.ardoco.core.api.connectiongenerator;

import edu.kit.kastel.mcse.ardoco.core.api.models.Entity;

import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.set.MutableSet;

import edu.kit.kastel.mcse.ardoco.core.api.models.ModelInstance;
import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.InstanceLink;
import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SadSamTraceLink;
import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance;
Expand Down Expand Up @@ -78,15 +79,15 @@ default ImmutableSet<SadSamTraceLink> getTraceLinks() {
}

/**
* Adds the connection of a recommended instance and a model instance to the state. If the model instance is already
* Adds the connection of a recommended instance and an entity to the state. If the entity is already
* contained by the state it is extended. Elsewhere a new instance link is created
*
* @param recommendedModelInstance the recommended instance
* @param instance the model instance
* @param entity the entity
* @param claimant the claimant
* @param probability the probability of the link
*/
void addToLinks(RecommendedInstance recommendedModelInstance, ModelInstance instance, Claimant claimant, double probability);
void addToLinks(RecommendedInstance recommendedModelInstance, Entity entity, Claimant claimant, double probability);

/**
* Checks if an instance link is already contained by the state.
Expand All @@ -108,7 +109,7 @@ default ImmutableSet<SadSamTraceLink> getTraceLinks() {
*
* @param instance the given instance
*/
void removeAllInstanceLinksWith(ModelInstance instance);
void removeAllInstanceLinksWith(Entity instance);

/**
* Removes all instance links containing the given recommended instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ public interface ModelInconsistency extends Inconsistency {
*
* @return the name of the inconsistent model instance.
*/
String getModelInstanceName();
String getEntityName();

/**
* Return the type of the inconsistent model instance.
*
* @return the type of the inconsistent model instance.
*/
String getModelInstanceType();
String getEntityType();

/**
* Return the UID of the inconsistent model instance.
*
* @return the UID of the inconsistent model instance.
*/
String getModelInstanceUid();
String getInstanceId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;

import java.util.Arrays;

/**
* An entity with a name. Is a model element.
*/
Expand Down Expand Up @@ -38,6 +43,10 @@ public String getName() {
return name;
}

public ImmutableList<String> getNameParts() {
return Lists.immutable.ofAll(Arrays.stream(getName().split(" ")).toList());
}

@Override
public String toString() {
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public interface ModelExtractionState extends IConfigurable {
Metamodel getMetamodel();

/**
* Returns the instances of a specific type.
* Returns the entities of a specific type.
*
* @param type the type to search for
* @return all instances that are from that type
*/
ImmutableList<ModelInstance> getInstancesOfType(String type);
ImmutableList<Entity> getEntitiesOfType(String type);

/**
* Returns all types that are contained by instances of this state.
*
* @return all instance types of this state
*/
ImmutableSet<String> getInstanceTypes();
ImmutableSet<String> getEntityTypes();

/**
* Returns all names that are contained by this state.
Expand All @@ -49,11 +49,11 @@ public interface ModelExtractionState extends IConfigurable {
Set<String> getNames();

/**
* Returns all instances that are contained by this state.
* Returns all entities that are contained by this state.
*
* @return all instances of this state
* @return all entities of this state
*/
ImmutableList<ModelInstance> getInstances();
ImmutableList<Entity> getEntities();

void addAllOf(ModelExtractionState other);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl;

import edu.kit.kastel.mcse.ardoco.core.api.models.Entity;

import java.util.List;
import java.util.Objects;

public class HoldBackModel extends Model {

private final List<? extends Entity> content;
private final List<? extends Entity> endpoints;

public HoldBackModel(List<? extends Entity> content, List<? extends Entity> endpoints) {
this.content = content;
this.endpoints = endpoints;
}

@Override
public List<? extends Entity> getContent() {
return this.content;
}

@Override
public List<? extends Entity> getEndpoints() {
return this.endpoints;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
if (!super.equals(o))
return false;
HoldBackModel that = (HoldBackModel) o;
return Objects.equals(content, that.content) && Objects.equals(endpoints, that.endpoints);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), content, endpoints);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,49 @@
import java.util.Objects;
import java.util.Set;

import edu.kit.kastel.mcse.ardoco.core.api.models.Entity;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.MutableList;

import edu.kit.kastel.mcse.ardoco.core.api.models.ModelInstance;
import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance;
import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping;
import edu.kit.kastel.mcse.ardoco.core.common.AggregationFunctions;
import edu.kit.kastel.mcse.ardoco.core.data.Confidence;
import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant;

/**
* An InstanceLink defines a link between an {@link RecommendedInstance} and an {@link ModelInstance}.
* An InstanceLink defines a link between an {@link RecommendedInstance} and an {@link Entity}.
*/
public class InstanceLink extends EndpointTuple {

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

/**
* Create a new instance link
*
* @param textualInstance the recommended instance
* @param modelInstance the model instance
* @param entity the model instance
*/
public InstanceLink(RecommendedInstance textualInstance, ModelInstance modelInstance) {
super(textualInstance, modelInstance);
public InstanceLink(RecommendedInstance textualInstance, Entity entity) {
super(textualInstance, entity);
this.textualInstance = textualInstance;
this.modelInstance = modelInstance;
this.entity = entity;
this.confidence = new Confidence(AggregationFunctions.AVERAGE);
}

/**
* Creates a new instance link.
*
* @param textualInstance the recommended instance
* @param modelInstance the model instance
* @param entity the model instance
* @param claimant the claimant
* @param probability the probability of this link
*/
public InstanceLink(RecommendedInstance textualInstance, ModelInstance modelInstance, Claimant claimant, double probability) {
this(textualInstance, modelInstance);
public InstanceLink(RecommendedInstance textualInstance, Entity entity, Claimant claimant, double probability) {
this(textualInstance, entity);
this.confidence.addAgentConfidence(claimant, probability);
}

Expand All @@ -74,13 +75,13 @@ public final RecommendedInstance getTextualInstance() {
*
* @return the extracted instance
*/
public final ModelInstance getModelInstance() {
return modelInstance;
public final Entity getEntity() {
return entity;
}

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

@Override
Expand All @@ -91,7 +92,7 @@ public boolean equals(Object obj) {
if (!(obj instanceof InstanceLink other)) {
return false;
}
return Objects.equals(getModelInstance(), other.getModelInstance()) && Objects.equals(getTextualInstance(), other.getTextualInstance());
return Objects.equals(getEntity(), other.getEntity()) && Objects.equals(getTextualInstance(), other.getTextualInstance());
}

@Override
Expand All @@ -109,8 +110,8 @@ public String toString() {
types.addAll(typeMapping.getSurfaceForms().castToCollection());
typePositions.addAll(typeMapping.getMappingSentenceNo().castToCollection());
}
return "InstanceMapping [ uid=" + modelInstance.getUid() + ", name=" + modelInstance.getFullName() + //
", as=" + String.join(", ", modelInstance.getFullType()) + ", probability=" + getConfidence() + ", FOUND: " + //
return "InstanceMapping [ uid=" + entity.getId() + ", name=" + entity.getName() + //
", as=" + String.join(", ", entity.getClass().getSimpleName()) + ", probability=" + getConfidence() + ", FOUND: " + //
textualInstance.getName() + " : " + textualInstance.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 @@ -3,27 +3,28 @@

import java.util.Objects;

import edu.kit.kastel.mcse.ardoco.core.api.models.ModelInstance;
import edu.kit.kastel.mcse.ardoco.core.api.models.Entity;

import edu.kit.kastel.mcse.ardoco.core.api.text.Sentence;
import edu.kit.kastel.mcse.ardoco.core.api.text.Word;

/**
* Represents a trace link. This is a convenience data class that takes the necessary info from {@link InstanceLink} and
* the specific {@link ModelInstance} and {@link Word} that are used in this trace link.
* the specific {@link Entity} and {@link Word} that are used in this trace link.
*/
public class SadSamTraceLink extends TraceLink implements Comparable<SadSamTraceLink> {
private final InstanceLink instanceLink;
private final Word word;

/**
* Create a trace link based on a {@link InstanceLink} and a concrete {@link ModelInstance} along with a concrete
* Create a trace link based on a {@link InstanceLink} and a concrete {@link Entity} along with a concrete
* {@link Word}.
*
* @param instanceLink InstanceLink of this trace link
* @param word word that the trace link points to
*/
public SadSamTraceLink(InstanceLink instanceLink, Word word) {
super(new EndpointTuple(instanceLink.getTextualInstance(), instanceLink.getModelInstance()));
super(new EndpointTuple(instanceLink.getTextualInstance(), instanceLink.getEntity()));
this.instanceLink = instanceLink;
this.word = word;
}
Expand Down Expand Up @@ -52,7 +53,7 @@ public Sentence getSentence() {
* @return Uid of the model element that the trace link is based on.
*/
public String getModelElementUid() {
return instanceLink.getModelInstance().getUid();
return instanceLink.getEntity().getId();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ public static ImmutableList<String> getSimilarTypes(Word word, ModelExtractionSt
* @return Set of identifiers for existing types
*/
public static Set<String> getTypeIdentifiers(ModelExtractionState modelState) {
Set<String> identifiers = modelState.getInstanceTypes()
Set<String> identifiers = modelState.getEntityTypes()
.stream()
.map(CommonUtilities::splitSnakeAndKebabCase)
.map(CommonUtilities::splitCamelCase)
.map(type -> type.split(" "))
.flatMap(Arrays::stream)
.collect(Collectors.toSet());
identifiers.addAll(modelState.getInstanceTypes().toSet());
identifiers.addAll(modelState.getEntityTypes().toSet());
return identifiers;
}

Expand Down
Loading
Loading