Search in sources :

Example 6 with ParseConfiguration

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");
            }
        }
    }
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) PosTagSequence(com.joliciel.talismane.posTagger.PosTagSequence) DependencyArc(com.joliciel.talismane.parser.DependencyArc) ParseConfiguration(com.joliciel.talismane.parser.ParseConfiguration)

Example 7 with ParseConfiguration

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;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) PosTaggedTokenWrapper(com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper) ParseConfiguration(com.joliciel.talismane.parser.ParseConfiguration)

Example 8 with ParseConfiguration

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;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) PosTaggedTokenWrapper(com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper) ParseConfiguration(com.joliciel.talismane.parser.ParseConfiguration)

Example 9 with ParseConfiguration

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;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) PosTaggedTokenWrapper(com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper) ParseConfiguration(com.joliciel.talismane.parser.ParseConfiguration)

Example 10 with ParseConfiguration

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;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) PosTaggedTokenWrapper(com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper) ParseConfiguration(com.joliciel.talismane.parser.ParseConfiguration)

Aggregations

ParseConfiguration (com.joliciel.talismane.parser.ParseConfiguration)31 PosTaggedToken (com.joliciel.talismane.posTagger.PosTaggedToken)24 PosTaggedTokenWrapper (com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper)18 DependencyArc (com.joliciel.talismane.parser.DependencyArc)7 PosTagSequence (com.joliciel.talismane.posTagger.PosTagSequence)7 TalismaneException (com.joliciel.talismane.TalismaneException)4 Sentence (com.joliciel.talismane.rawText.Sentence)4 Transition (com.joliciel.talismane.parser.Transition)3 SentenceAnnotator (com.joliciel.talismane.sentenceAnnotators.SentenceAnnotator)3 TokenSequence (com.joliciel.talismane.tokeniser.TokenSequence)3 NonDeterministicParser (com.joliciel.talismane.parser.NonDeterministicParser)2 ParseConfigurationProcessor (com.joliciel.talismane.parser.output.ParseConfigurationProcessor)2 NonDeterministicPosTagger (com.joliciel.talismane.posTagger.NonDeterministicPosTagger)2 PosTagAnnotatedCorpusReader (com.joliciel.talismane.posTagger.PosTagAnnotatedCorpusReader)2 PosTagSequenceProcessor (com.joliciel.talismane.posTagger.output.PosTagSequenceProcessor)2 SentenceProcessor (com.joliciel.talismane.sentenceDetector.SentenceProcessor)2 Token (com.joliciel.talismane.tokeniser.Token)2 TokeniserAnnotatedCorpusReader (com.joliciel.talismane.tokeniser.TokeniserAnnotatedCorpusReader)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2