Skip to content

Commit

Permalink
Remove global configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Nov 29, 2024
1 parent 06d992b commit 258e8d3
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.MappingKind;
import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.TextState;
import edu.kit.kastel.mcse.ardoco.core.api.text.Word;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils;
import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper;
import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable;
import edu.kit.kastel.mcse.ardoco.core.data.DataRepository;
Expand All @@ -28,21 +29,21 @@ public ExtractionDependentOccurrenceInformant(DataRepository dataRepository) {

@Override
public void process() {
DataRepository dataRepository = getDataRepository();
DataRepository dataRepository = this.getDataRepository();
var text = DataRepositoryHelper.getAnnotatedText(dataRepository);
var textState = DataRepositoryHelper.getTextState(dataRepository);
var modelStates = DataRepositoryHelper.getModelStatesData(dataRepository);
for (var word : text.words()) {
exec(textState, modelStates, word);
this.exec(textState, modelStates, word);
}
}

private void exec(TextState textState, ModelStates modelStates, Word word) {
for (var model : modelStates.modelIds()) {
var modelState = modelStates.getModelExtractionState(model);

searchForName(modelState, textState, word);
searchForType(modelState, textState, word);
this.searchForName(modelState, textState, word);
this.searchForType(modelState, textState, word);
}
}

Expand All @@ -51,12 +52,12 @@ private void exec(TextState textState, ModelStates modelStates, Word word) {
* appears to be a name this is stored in the text extraction state.
*/
private void searchForName(LegacyModelExtractionState modelState, TextState textState, Word word) {
if (posTagIsUndesired(word) && !wordStartsWithCapitalLetter(word)) {
if (this.posTagIsUndesired(word) && !this.wordStartsWithCapitalLetter(word)) {
return;
}
var instanceNameIsSimilar = modelState.getInstances().anySatisfy(i -> getMetaData().getSimilarityUtils().isWordSimilarToModelInstance(word, i));
var instanceNameIsSimilar = modelState.getInstances().anySatisfy(i -> SimilarityUtils.getInstance().isWordSimilarToModelInstance(word, i));
if (instanceNameIsSimilar) {
textState.addNounMapping(word, MappingKind.NAME, this, probability);
textState.addNounMapping(word, MappingKind.NAME, this, this.probability);
}
}

Expand All @@ -74,10 +75,9 @@ private boolean posTagIsUndesired(Word word) {
* value is taken as reference.
*/
private void searchForType(LegacyModelExtractionState modelState, TextState textState, Word word) {
var similarityUtils = getMetaData().getSimilarityUtils();
var instanceTypeIsSimilar = modelState.getInstances().anySatisfy(i -> similarityUtils.isWordSimilarToModelInstanceType(word, i));
var instanceTypeIsSimilar = modelState.getInstances().anySatisfy(i -> SimilarityUtils.getInstance().isWordSimilarToModelInstanceType(word, i));
if (instanceTypeIsSimilar) {
textState.addNounMapping(word, MappingKind.TYPE, this, probability);
textState.addNounMapping(word, MappingKind.TYPE, this, this.probability);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.legacy.ModelInstance;
import edu.kit.kastel.mcse.ardoco.core.api.stage.connectiongenerator.ConnectionState;
import edu.kit.kastel.mcse.ardoco.core.api.stage.recommendationgenerator.RecommendationState;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils;
import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper;
import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable;
import edu.kit.kastel.mcse.ardoco.core.data.DataRepository;
Expand All @@ -25,7 +26,7 @@ public InstantConnectionInformant(DataRepository dataRepository) {

@Override
public void process() {
DataRepository dataRepository = getDataRepository();
DataRepository dataRepository = this.getDataRepository();
var modelStates = DataRepositoryHelper.getModelStatesData(dataRepository);
var recommendationStates = DataRepositoryHelper.getRecommendationStates(dataRepository);
var connectionStates = DataRepositoryHelper.getConnectionStates(dataRepository);
Expand All @@ -35,8 +36,8 @@ public void process() {
var recommendationState = recommendationStates.getRecommendationState(metamodel);
var connectionState = connectionStates.getConnectionState(metamodel);

findNamesOfModelInstancesInSupposedMappings(modelState, recommendationState, connectionState);
createLinksForEqualOrSimilarRecommendedInstances(modelState, recommendationState, connectionState);
this.findNamesOfModelInstancesInSupposedMappings(modelState, recommendationState, connectionState);
this.createLinksForEqualOrSimilarRecommendedInstances(modelState, recommendationState, connectionState);
}
}

Expand All @@ -47,12 +48,11 @@ public void process() {
private void findNamesOfModelInstancesInSupposedMappings(LegacyModelExtractionState modelState, RecommendationState recommendationState,
ConnectionState connectionState) {
var recommendedInstances = recommendationState.getRecommendedInstances();
var similarityUtils = getMetaData().getSimilarityUtils();
for (ModelInstance instance : modelState.getInstances()) {
var mostLikelyRi = similarityUtils.getMostRecommendedInstancesToInstanceByReferences(instance, recommendedInstances);
var mostLikelyRi = SimilarityUtils.getInstance().getMostRecommendedInstancesToInstanceByReferences(instance, recommendedInstances);

for (var recommendedInstance : mostLikelyRi) {
var riProbability = recommendedInstance.getTypeMappings().isEmpty() ? probabilityWithoutType : probability;
var riProbability = recommendedInstance.getTypeMappings().isEmpty() ? this.probabilityWithoutType : this.probability;
connectionState.addToLinks(recommendedInstance, instance, this, riProbability);
}
}
Expand All @@ -62,8 +62,8 @@ private void createLinksForEqualOrSimilarRecommendedInstances(LegacyModelExtract
ConnectionState connectionState) {
for (var recommendedInstance : recommendationState.getRecommendedInstances()) {
var sameInstances = modelState.getInstances()
.select(instance -> getMetaData().getSimilarityUtils().isRecommendedInstanceSimilarToModelInstance(recommendedInstance, instance));
sameInstances.forEach(instance -> connectionState.addToLinks(recommendedInstance, instance, this, probability));
.select(instance -> SimilarityUtils.getInstance().isRecommendedInstanceSimilarToModelInstance(recommendedInstance, instance));
sameInstances.forEach(instance -> connectionState.addToLinks(recommendedInstance, instance, this, this.probability));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.NounMapping;
import edu.kit.kastel.mcse.ardoco.core.api.stage.textextraction.TextState;
import edu.kit.kastel.mcse.ardoco.core.api.text.Word;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.SimilarityUtils;
import edu.kit.kastel.mcse.ardoco.core.common.util.CommonUtilities;
import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper;
import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable;
Expand All @@ -37,24 +38,24 @@ public NameTypeConnectionInformant(DataRepository dataRepository) {

@Override
public void process() {
DataRepository dataRepository = getDataRepository();
DataRepository dataRepository = this.getDataRepository();
var text = DataRepositoryHelper.getAnnotatedText(dataRepository);
var textState = DataRepositoryHelper.getTextState(dataRepository);
var modelStates = DataRepositoryHelper.getModelStatesData(dataRepository);
var recommendationStates = DataRepositoryHelper.getRecommendationStates(dataRepository);
for (var word : text.words()) {
exec(textState, modelStates, recommendationStates, word);
this.exec(textState, modelStates, recommendationStates, word);
}
}

private void exec(TextState textState, ModelStates modelStates, RecommendationStates recommendationStates, Word word) {
for (var model : modelStates.modelIds()) {
var modelState = modelStates.getModelExtractionState(model);
var recommendationState = recommendationStates.getRecommendationState(modelState.getMetamodel());
checkForNameAfterType(textState, word, modelState, recommendationState);
checkForNameBeforeType(textState, word, modelState, recommendationState);
checkForNortBeforeType(textState, word, modelState, recommendationState);
checkForNortAfterType(textState, word, modelState, recommendationState);
this.checkForNameAfterType(textState, word, modelState, recommendationState);
this.checkForNameBeforeType(textState, word, modelState, recommendationState);
this.checkForNortBeforeType(textState, word, modelState, recommendationState);
this.checkForNortAfterType(textState, word, modelState, recommendationState);
}
}

Expand All @@ -70,16 +71,16 @@ private void checkForNameBeforeType(TextState textExtractionState, Word word, Le

var preWord = word.getPreWord();

var similarTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState);
var similarTypes = CommonUtilities.getSimilarTypes(word, modelState);

if (!similarTypes.isEmpty()) {
textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability);
textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability);

var nameMappings = textExtractionState.getMappingsThatCouldBeOfKind(preWord, MappingKind.NAME);
var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE);

var instance = tryToIdentify(textExtractionState, similarTypes, preWord, modelState);
addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nameMappings, typeMappings, recommendationState);
var instance = this.tryToIdentify(textExtractionState, similarTypes, preWord, modelState);
this.addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nameMappings, typeMappings, recommendationState);
}
}

Expand All @@ -100,15 +101,15 @@ private void checkForNameAfterType(TextState textExtractionState, Word word, Leg

var after = word.getNextWord();

var sameLemmaTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState);
var sameLemmaTypes = CommonUtilities.getSimilarTypes(word, modelState);
if (!sameLemmaTypes.isEmpty()) {
textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability);
textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability);

var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE);
var nameMappings = textExtractionState.getMappingsThatCouldBeOfKind(after, MappingKind.NAME);

var instance = tryToIdentify(textExtractionState, sameLemmaTypes, after, modelState);
addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nameMappings, typeMappings, recommendationState);
var instance = this.tryToIdentify(textExtractionState, sameLemmaTypes, after, modelState);
this.addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nameMappings, typeMappings, recommendationState);
}
}

Expand All @@ -124,16 +125,16 @@ private void checkForNortBeforeType(TextState textExtractionState, Word word, Le

var preWord = word.getPreWord();

var sameLemmaTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState);
var sameLemmaTypes = CommonUtilities.getSimilarTypes(word, modelState);

if (!sameLemmaTypes.isEmpty()) {
textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability);
textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability);

var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE);
var nortMappings = textExtractionState.getMappingsThatCouldBeMultipleKinds(preWord, MappingKind.NAME, MappingKind.TYPE);

var instance = tryToIdentify(textExtractionState, sameLemmaTypes, preWord, modelState);
addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nortMappings, typeMappings, recommendationState);
var instance = this.tryToIdentify(textExtractionState, sameLemmaTypes, preWord, modelState);
this.addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nortMappings, typeMappings, recommendationState);
}
}

Expand All @@ -149,15 +150,15 @@ private void checkForNortAfterType(TextState textExtractionState, Word word, Leg

var after = word.getNextWord();

var sameLemmaTypes = CommonUtilities.getSimilarTypes(getMetaData().getSimilarityUtils(), word, modelState);
var sameLemmaTypes = CommonUtilities.getSimilarTypes(word, modelState);
if (!sameLemmaTypes.isEmpty()) {
textExtractionState.addNounMapping(word, MappingKind.TYPE, this, probability);
textExtractionState.addNounMapping(word, MappingKind.TYPE, this, this.probability);

var typeMappings = textExtractionState.getMappingsThatCouldBeOfKind(word, MappingKind.TYPE);
var nortMappings = textExtractionState.getMappingsThatCouldBeMultipleKinds(after, MappingKind.NAME, MappingKind.TYPE);

var instance = tryToIdentify(textExtractionState, sameLemmaTypes, after, modelState);
addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nortMappings, typeMappings, recommendationState);
var instance = this.tryToIdentify(textExtractionState, sameLemmaTypes, after, modelState);
this.addRecommendedInstanceIfNodeNotNull(word, textExtractionState, instance, nortMappings, typeMappings, recommendationState);
}
}

Expand All @@ -179,7 +180,7 @@ private void addRecommendedInstanceIfNodeNotNull(//
for (NounMapping nmapping : nounMappingsByCurrentWord) {
var name = instance.getFullName();
var type = nmapping.getReference();
recommendationState.addRecommendedInstance(name, type, this, probability, nameMappings, typeMappings);
recommendationState.addRecommendedInstance(name, type, this, this.probability, nameMappings, typeMappings);
}
}
}
Expand All @@ -204,8 +205,7 @@ private ModelInstance tryToIdentify(TextState textExtractionState, ImmutableList
}

var text = word.getText();
matchingInstances = matchingInstances.select(i -> getMetaData().getSimilarityUtils()
.areWordsOfListsSimilar(i.getNameParts(), Lists.immutable.with(text)));
matchingInstances = matchingInstances.select(i -> SimilarityUtils.getInstance().areWordsOfListsSimilar(i.getNameParts(), Lists.immutable.with(text)));

if (!matchingInstances.isEmpty()) {
return matchingInstances.get(0);
Expand Down
Loading

0 comments on commit 258e8d3

Please sign in to comment.