Search in sources :

Example 11 with ParseConfiguration

use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.

the class AddressFunctionSequence 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();
        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)

Example 12 with ParseConfiguration

use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.

the class AddressFunctionStack 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(wrapper, env);
    if (indexResult != null) {
        int index = indexResult.getOutcome();
        Iterator<PosTaggedToken> stackIterator = configuration.getStack().iterator();
        for (int i = 0; i <= index; i++) {
            if (!stackIterator.hasNext()) {
                resultToken = null;
                break;
            }
            resultToken = stackIterator.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 13 with ParseConfiguration

use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.

the class AncestorSearchFeature method check.

@Override
public FeatureResult<PosTaggedTokenWrapper> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
    ParseConfiguration configuration = wrapper.getParseConfiguration();
    PosTaggedToken resultToken = null;
    FeatureResult<PosTaggedTokenWrapper> referenceTokenResult = referenceTokenFeature.check(wrapper, env);
    if (referenceTokenResult != null) {
        PosTaggedToken referenceToken = referenceTokenResult.getOutcome().getPosTaggedToken();
        boolean includeMe = false;
        if (includeMeFeature != null) {
            FeatureResult<Boolean> includeMeResult = includeMeFeature.check(wrapper, env);
            if (includeMeResult == null)
                return null;
            includeMe = includeMeResult.getOutcome();
        }
        PosTaggedToken ancestor = null;
        if (includeMe)
            ancestor = referenceToken;
        else
            ancestor = configuration.getHead(referenceToken);
        ParseConfigurationAddress parseConfigurationAddress = new ParseConfigurationAddress(env);
        parseConfigurationAddress.setParseConfiguration(configuration);
        while (ancestor != null) {
            parseConfigurationAddress.setPosTaggedToken(ancestor);
            FeatureResult<Boolean> criterionResult = criterionFeature.check(parseConfigurationAddress, env);
            if (criterionResult != null) {
                boolean criterion = criterionResult.getOutcome();
                if (criterion) {
                    resultToken = ancestor;
                    break;
                }
            }
            ancestor = configuration.getHead(ancestor);
        }
    }
    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 14 with ParseConfiguration

use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.

the class BackwardSearchFeature method check.

@Override
public FeatureResult<PosTaggedTokenWrapper> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
    ParseConfiguration configuration = wrapper.getParseConfiguration();
    PosTaggedToken resultToken = null;
    FeatureResult<PosTaggedTokenWrapper> referenceTokenResult = referenceTokenFeature.check(wrapper, env);
    if (referenceTokenResult != null) {
        PosTaggedToken referenceToken = referenceTokenResult.getOutcome().getPosTaggedToken();
        ParseConfigurationAddress parseConfigurationAddress = new ParseConfigurationAddress(env);
        parseConfigurationAddress.setParseConfiguration(configuration);
        for (int i = referenceToken.getToken().getIndex() - 1; i >= 0; i--) {
            PosTaggedToken nextToken = configuration.getPosTagSequence().get(i);
            parseConfigurationAddress.setPosTaggedToken(nextToken);
            FeatureResult<Boolean> criterionResult = criterionFeature.check(parseConfigurationAddress, env);
            if (criterionResult != null) {
                boolean criterion = criterionResult.getOutcome();
                if (criterion) {
                    resultToken = nextToken;
                    break;
                }
            }
        }
    }
    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 15 with ParseConfiguration

use of com.joliciel.talismane.parser.ParseConfiguration in project talismane by joliciel-informatique.

the class BetweenCountIf method check.

@Override
public FeatureResult<Integer> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
    ParseConfiguration configuration = wrapper.getParseConfiguration();
    FeatureResult<PosTaggedTokenWrapper> tokenResult1 = addressFunction1.check(wrapper, env);
    FeatureResult<PosTaggedTokenWrapper> tokenResult2 = addressFunction2.check(wrapper, env);
    FeatureResult<Integer> featureResult = null;
    if (tokenResult1 != null && tokenResult2 != null) {
        PosTaggedToken posTaggedToken1 = tokenResult1.getOutcome().getPosTaggedToken();
        PosTaggedToken posTaggedToken2 = tokenResult2.getOutcome().getPosTaggedToken();
        int index1 = posTaggedToken1.getToken().getIndex();
        int index2 = posTaggedToken2.getToken().getIndex();
        int minIndex = index1 < index2 ? index1 : index2;
        int maxIndex = index1 >= index2 ? index1 : index2;
        int countMatching = 0;
        for (int i = minIndex + 1; i < maxIndex; i++) {
            IntegerFeature<ParseConfigurationWrapper> indexFeature = new IntegerLiteralFeature<ParseConfigurationWrapper>(i);
            PosTaggedTokenAddressFunction<ParseConfigurationWrapper> indexFunction = new AddressFunctionSequence(indexFeature);
            ParseConfigurationAddress parseConfigurationAddress = new ParseConfigurationAddress(configuration, indexFunction, env);
            FeatureResult<Boolean> criterionResult = criterion.check(parseConfigurationAddress, env);
            if (criterionResult != null && criterionResult.getOutcome())
                countMatching++;
        }
        featureResult = this.generateResult(countMatching);
    }
    return featureResult;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) PosTaggedTokenWrapper(com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper) ParseConfiguration(com.joliciel.talismane.parser.ParseConfiguration) IntegerLiteralFeature(com.joliciel.talismane.machineLearning.features.IntegerLiteralFeature)

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