use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.
the class ParserFScoreCalculatorByDistance method onParseEnd.
@Override
public void onParseEnd(ParseConfiguration realConfiguration, List<ParseConfiguration> guessedConfigurations) {
PosTagSequence posTagSequence = realConfiguration.getPosTagSequence();
ParseConfiguration bestGuess = guessedConfigurations.get(0);
for (PosTaggedToken posTaggedToken : posTagSequence) {
if (posTaggedToken.getTag().equals(PosTag.ROOT_POS_TAG))
continue;
DependencyArc realArc = realConfiguration.getGoverningDependency(posTaggedToken);
int depDistance = realArc.getHead().getToken().getIndex() - realArc.getDependent().getToken().getIndex();
if (depDistance < 0)
depDistance = 0 - depDistance;
FScoreCalculator<String> fscoreCalculator = fscoreByDistanceMap.get(depDistance);
if (fscoreCalculator == null) {
fscoreCalculator = new FScoreCalculator<String>(depDistance);
fscoreByDistanceMap.put(depDistance, fscoreCalculator);
}
DependencyArc guessedArc = null;
if (!hasTokeniser && !hasPosTagger) {
guessedArc = bestGuess.getGoverningDependency(posTaggedToken);
} else {
for (PosTaggedToken guessedToken : bestGuess.getPosTagSequence()) {
if (guessedToken.getToken().getStartIndex() == posTaggedToken.getToken().getStartIndex()) {
guessedArc = bestGuess.getGoverningDependency(guessedToken);
break;
}
}
}
String realLabel = realArc == null ? "noHead" : labeledEvaluation ? realArc.getLabel() : "head";
String guessedLabel = guessedArc == null ? "noHead" : labeledEvaluation ? guessedArc.getLabel() : "head";
if (realLabel == null || realLabel.length() == 0)
realLabel = "noLabel";
if (guessedLabel == null || guessedLabel.length() == 0)
guessedLabel = "noLabel";
// should be considered a "no head" rather than "no label"
if (realArc != null && realArc.getHead().getTag().equals(PosTag.ROOT_POS_TAG) && realLabel.equals("noLabel"))
realLabel = "noHead";
if (guessedArc != null && guessedArc.getHead().getTag().equals(PosTag.ROOT_POS_TAG) && guessedLabel.equals("noLabel"))
guessedLabel = "noHead";
if (realLabel.equals(skipLabel))
return;
if (realArc == null || guessedArc == null) {
fscoreCalculator.increment(realLabel, guessedLabel);
} else {
boolean sameHead = false;
if (hasTokeniser || hasPosTagger)
sameHead = realArc.getHead().getToken().getStartIndex() == guessedArc.getHead().getToken().getStartIndex();
else
sameHead = realArc.getHead().equals(guessedArc.getHead());
if (sameHead) {
fscoreCalculator.increment(realLabel, guessedLabel);
} else if (guessedLabel.equals("noHead")) {
fscoreCalculator.increment(realLabel, "noHead");
} else if (realArc.getLabel().equals(guessedArc.getLabel())) {
fscoreCalculator.increment(realLabel, "wrongHead");
} else {
fscoreCalculator.increment(realLabel, "wrongHeadWrongLabel");
}
}
}
}
use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.
the class AddressFunctionBuffer method check.
@Override
public FeatureResult<PosTaggedTokenWrapper> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
ParseConfiguration configuration = wrapper.getParseConfiguration();
PosTaggedToken resultToken = null;
FeatureResult<Integer> indexResult = indexFeature.check(configuration, env);
if (indexResult != null) {
int index = indexResult.getOutcome();
Iterator<PosTaggedToken> bufferIterator = configuration.getBuffer().iterator();
for (int i = 0; i <= index; i++) {
if (!bufferIterator.hasNext()) {
resultToken = null;
break;
}
resultToken = bufferIterator.next();
}
}
FeatureResult<PosTaggedTokenWrapper> featureResult = null;
if (resultToken != null)
featureResult = this.generateResult(resultToken);
return featureResult;
}
use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.
the class AddressFunctionHead method check.
@Override
public FeatureResult<PosTaggedTokenWrapper> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
ParseConfiguration configuration = wrapper.getParseConfiguration();
PosTaggedToken resultToken = null;
FeatureResult<PosTaggedTokenWrapper> addressResult = addressFunction.check(wrapper, env);
if (addressResult != null) {
PosTaggedToken referenceToken = addressResult.getOutcome().getPosTaggedToken();
resultToken = configuration.getHead(referenceToken);
}
FeatureResult<PosTaggedTokenWrapper> featureResult = null;
if (resultToken != null)
featureResult = this.generateResult(resultToken);
return featureResult;
}
use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.
the class AddressFunctionLDep method check.
@Override
public FeatureResult<PosTaggedTokenWrapper> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
ParseConfiguration configuration = wrapper.getParseConfiguration();
PosTaggedToken resultToken = null;
FeatureResult<PosTaggedTokenWrapper> addressResult = addressFunction.check(wrapper, env);
if (addressResult != null) {
PosTaggedToken referenceToken = addressResult.getOutcome().getPosTaggedToken();
List<PosTaggedToken> leftDependents = configuration.getLeftDependents(referenceToken);
if (leftDependents.size() > 0)
resultToken = leftDependents.get(0);
}
FeatureResult<PosTaggedTokenWrapper> featureResult = null;
if (resultToken != null)
featureResult = this.generateResult(resultToken);
return featureResult;
}
use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.
the class AddressFunctionOffset method check.
@Override
public FeatureResult<PosTaggedTokenWrapper> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
ParseConfiguration configuration = wrapper.getParseConfiguration();
PosTaggedToken resultToken = null;
FeatureResult<PosTaggedTokenWrapper> addressResult = addressFunction.check(wrapper, env);
FeatureResult<Integer> offsetResult = offsetFeature.check(configuration, env);
if (addressResult != null && offsetResult != null) {
int offset = offsetResult.getOutcome();
PosTaggedToken referenceToken = addressResult.getOutcome().getPosTaggedToken();
int refIndex = referenceToken.getToken().getIndex();
int index = refIndex + offset;
if (index >= 0 && index < configuration.getPosTagSequence().size()) {
resultToken = configuration.getPosTagSequence().get(index);
}
}
FeatureResult<PosTaggedTokenWrapper> featureResult = null;
if (resultToken != null)
featureResult = this.generateResult(resultToken);
return featureResult;
}
Aggregations