-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dependency processing and recognition (#30)
* Add agent for dependencies * Dependency extraction * Add agent and extractor to get dependencies * Initial stubs only until now * Extend DependencyTags * Changed descriptions, added checks for Word types, DOBJ to OBJ * Started with pipeline for RecommendedRelationExtractor (rename?) * Rename DependencyExtractionAgent to RecommendedRelationAgent * Rename RecommendedRelationAgent to InstanceRelationAgent * Adjust InstanceRelationAgent to InstanceRelation * Interface for InstanceRelation * InstanceRelation used by InstanceRelationAgent * Adjust RecommendationGenerator to use InstanceRelationAgent * Override equals for Word class * Add InstanceRelation to RecommendationState * Lower needed similarity for recommended instances in text extractor * Adjust instance relation to only compare between recommended instances * Remove lemma, only compare considering recommended instances * Only use two instances for identification of a relation (instead of lists) * Add some documentation * Adjust probability calculation (still experimental) * If matching relation between instances is found, add relation between words there * Choose "from" and "to" words according to their position in text * Add simple probability calculation with max 1 * Adjust to merge * Add provisional IWord methods to implementing classes * Adjust usages of ImmutableLists * Adjust DependencyAgent * Fix incorrect link * Adjust similarity to retrieve more RecommendedInstances * Higher probability to generate InstanceRelations * Override recommended hashCode in InstanceRelation * some cleanup * update gitignore * move word check for POS to WordHelper * improve code quality Co-authored-by: Jan Keim <[email protected]>
- Loading branch information
Showing
19 changed files
with
523 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../src/main/java/edu/kit/kastel/mcse/ardoco/core/datastructures/agents/DependencyAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package edu.kit.kastel.mcse.ardoco.core.datastructures.agents; | ||
|
||
import edu.kit.kastel.mcse.ardoco.core.datastructures.definitions.IModelState; | ||
import edu.kit.kastel.mcse.ardoco.core.datastructures.definitions.IRecommendationState; | ||
import edu.kit.kastel.mcse.ardoco.core.datastructures.definitions.IText; | ||
import edu.kit.kastel.mcse.ardoco.core.datastructures.definitions.ITextState; | ||
|
||
import java.util.Objects; | ||
|
||
public abstract class DependencyAgent extends Agent { | ||
|
||
protected IText text; | ||
protected ITextState textState; | ||
protected IModelState modelState; | ||
protected IRecommendationState recommendationState; | ||
|
||
protected DependencyAgent(Class<? extends Configuration> configType) { | ||
super(configType); | ||
} | ||
|
||
protected DependencyAgent(Class<? extends Configuration> configType, IText text, | ||
ITextState textState, IModelState modelState, IRecommendationState recommendationState) { | ||
super(configType); | ||
this.text = text; | ||
this.textState = textState; | ||
this.modelState = modelState; | ||
this.recommendationState = recommendationState; | ||
} | ||
|
||
@Override | ||
protected final DependencyAgent createInternal(AgentDatastructure data, Configuration config) { | ||
Objects.requireNonNull(data.getText()); | ||
Objects.requireNonNull(data.getTextState()); | ||
Objects.requireNonNull(data.getModelState()); | ||
Objects.requireNonNull(data.getRecommendationState()); | ||
|
||
return this.create(data.getText(), data.getTextState(), data.getModelState(), data.getRecommendationState(), config); | ||
} | ||
|
||
public abstract DependencyAgent create(IText text, ITextState textState, IModelState modelState, IRecommendationState recommendationState, | ||
Configuration config); | ||
} |
21 changes: 21 additions & 0 deletions
21
...in/java/edu/kit/kastel/mcse/ardoco/core/datastructures/definitions/IInstanceRelation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package edu.kit.kastel.mcse.ardoco.core.datastructures.definitions; | ||
|
||
import java.util.List; | ||
|
||
public interface IInstanceRelation { | ||
IInstanceRelation createCopy(); | ||
|
||
boolean addLink(IWord relator, List<IWord> from, List<IWord> to); | ||
|
||
boolean matches(IRecommendedInstance fromInstance, IRecommendedInstance toInstance); | ||
|
||
boolean isIn(IWord relator, List<IWord> from, List<IWord> to); | ||
|
||
double getProbability(); | ||
|
||
void setProbability(double newProbability); | ||
|
||
IRecommendedInstance getFromInstance(); | ||
|
||
IRecommendedInstance getToInstance(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
...erator/src/main/java/edu/kit/kastel/mcse/ardoco/core/datastructures/InstanceRelation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package edu.kit.kastel.mcse.ardoco.core.datastructures; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import edu.kit.kastel.mcse.ardoco.core.datastructures.definitions.IInstanceRelation; | ||
import edu.kit.kastel.mcse.ardoco.core.datastructures.definitions.IRecommendedInstance; | ||
import edu.kit.kastel.mcse.ardoco.core.datastructures.definitions.IWord; | ||
|
||
/** | ||
* Relation between RecommendedInstances, store specific occurrences as | ||
* | ||
* @see LocalRelation | ||
* | ||
* TODO fromInstance and toInstance to List to comprise more complex relations?! | ||
*/ | ||
public class InstanceRelation implements IInstanceRelation { | ||
private double probability; | ||
private final IRecommendedInstance fromInstance; | ||
private final IRecommendedInstance toInstance; | ||
private final List<LocalRelation> localRelations; | ||
|
||
@Override | ||
public IInstanceRelation createCopy() { | ||
InstanceRelation relation = new InstanceRelation(fromInstance, toInstance, null, null, null); | ||
for (LocalRelation localRelation : localRelations) { | ||
addLink(localRelation.relator, localRelation.from, localRelation.to); | ||
} | ||
return relation; | ||
} | ||
|
||
public InstanceRelation(IRecommendedInstance fromInstance, IRecommendedInstance toInstance, IWord relator, List<IWord> from, List<IWord> to) { | ||
this.fromInstance = fromInstance; | ||
this.toInstance = toInstance; | ||
localRelations = new ArrayList<>(); | ||
probability = 0; | ||
addLink(relator, from, to); | ||
} | ||
|
||
@Override | ||
public boolean addLink(IWord relator, List<IWord> from, List<IWord> to) { | ||
if (relator == null || from == null || to == null) { | ||
return false; | ||
} | ||
for (LocalRelation relation : localRelations) { | ||
if (relation.from.size() == from.size() && relation.from.containsAll(from) && relation.to.size() == to.size() && relation.to.containsAll(to)) { | ||
return false; | ||
} | ||
} | ||
localRelations.add(new LocalRelation(relator, from, to)); | ||
increaseProbability(); | ||
return true; | ||
} | ||
|
||
private void increaseProbability() { | ||
probability += Math.pow(0.5, localRelations.size()); | ||
} | ||
|
||
@Override | ||
public boolean matches(IRecommendedInstance fromInstance, IRecommendedInstance toInstance) { | ||
return this.fromInstance.equals(fromInstance) && this.toInstance.equals(toInstance); | ||
} | ||
|
||
@Override | ||
public boolean isIn(IWord relator, List<IWord> from, List<IWord> to) { | ||
for (LocalRelation relation : localRelations) { | ||
var sizesAreEqual = relation.from.size() == from.size() && relation.to.size() == to.size(); | ||
var containsEqual = relation.from.containsAll(from) && relation.to.containsAll(to); | ||
if (relation.relator.equals(relator) && containsEqual && sizesAreEqual) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public double getProbability() { | ||
return probability; | ||
} | ||
|
||
@Override | ||
public void setProbability(double newProbability) { | ||
probability = newProbability; | ||
} | ||
|
||
@Override | ||
public IRecommendedInstance getFromInstance() { | ||
return fromInstance; | ||
} | ||
|
||
@Override | ||
public IRecommendedInstance getToInstance() { | ||
return toInstance; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(fromInstance, toInstance); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
InstanceRelation other = (InstanceRelation) obj; | ||
return Objects.equals(fromInstance, other.fromInstance) && Objects.equals(toInstance, other.toInstance); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder str = new StringBuilder(""); | ||
str.append("InstanceRelation{") | ||
.append("probability=") | ||
.append(probability) | ||
.append(", fromInstance=") | ||
.append(fromInstance.toString()) | ||
.append(", ") | ||
.append("toInstance=") | ||
.append(toInstance.toString()) | ||
.append(", ") | ||
.append("localRelations="); | ||
for (LocalRelation relation : localRelations) { | ||
str.append(relation.toString()).append(", "); | ||
} | ||
str.delete(str.length() - 3, str.length() - 1); | ||
str.append('}'); | ||
return str.toString(); | ||
} | ||
|
||
private class LocalRelation { | ||
IWord relator; | ||
List<IWord> from; | ||
List<IWord> to; | ||
|
||
LocalRelation(IWord relator, List<IWord> from, List<IWord> to) { | ||
this.relator = relator; | ||
this.from = from; | ||
this.to = to; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder str = new StringBuilder("Link{from="); | ||
for (IWord fromWord : from) { | ||
str.append(fromWord.getText()).append(", "); | ||
} | ||
str.deleteCharAt(str.length() - 1); | ||
str.append("->to="); | ||
for (IWord toWord : to) { | ||
str.append(toWord.getText()).append(", "); | ||
} | ||
str.deleteCharAt(str.length() - 1); | ||
str.append('}'); | ||
return str.toString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.