Search in sources :

Example 11 with Token

use of com.joliciel.talismane.tokeniser.Token in project talismane by joliciel-informatique.

the class NLetterPrefixFeature method checkInternal.

@Override
public FeatureResult<String> checkInternal(TokenWrapper tokenWrapper, RuntimeEnvironment env) throws TalismaneException {
    TokenWrapper innerWrapper = this.getToken(tokenWrapper, env);
    if (innerWrapper == null)
        return null;
    Token token = innerWrapper.getToken();
    FeatureResult<String> result = null;
    FeatureResult<Integer> nResult = nFeature.check(innerWrapper, env);
    if (nResult != null) {
        int n = nResult.getOutcome();
        String firstWord = token.getAnalyisText().trim();
        if (firstWord.indexOf(' ') >= 0) {
            firstWord = firstWord.substring(0, firstWord.indexOf(' '));
        }
        if (firstWord.length() > n) {
            String prefix = firstWord.substring(0, n);
            result = this.generateResult(prefix);
        }
    }
    return result;
}
Also used : Token(com.joliciel.talismane.tokeniser.Token)

Example 12 with Token

use of com.joliciel.talismane.tokeniser.Token in project talismane by joliciel-informatique.

the class NLetterSuffixFeature method checkInternal.

@Override
public FeatureResult<String> checkInternal(TokenWrapper tokenWrapper, RuntimeEnvironment env) throws TalismaneException {
    TokenWrapper innerWrapper = this.getToken(tokenWrapper, env);
    if (innerWrapper == null)
        return null;
    Token token = innerWrapper.getToken();
    FeatureResult<String> result = null;
    String lastWord = token.getAnalyisText().trim();
    if (lastWord.indexOf(' ') >= 0) {
        int lastSpace = lastWord.lastIndexOf(' ');
        lastWord = lastWord.substring(lastSpace + 1);
    }
    FeatureResult<Integer> nResult = nFeature.check(innerWrapper, env);
    if (nResult != null) {
        int n = nResult.getOutcome();
        if (lastWord.length() > n) {
            String suffix = lastWord.substring(lastWord.length() - n);
            result = this.generateResult(suffix);
        }
    }
    return result;
}
Also used : Token(com.joliciel.talismane.tokeniser.Token)

Example 13 with Token

use of com.joliciel.talismane.tokeniser.Token in project talismane by joliciel-informatique.

the class OrRangeFeature method checkInternal.

@Override
public FeatureResult<Boolean> checkInternal(TokenWrapper tokenWrapper, RuntimeEnvironment env) throws TalismaneException {
    TokenWrapper innerWrapper = this.getToken(tokenWrapper, env);
    if (innerWrapper == null)
        return null;
    Token token = innerWrapper.getToken();
    FeatureResult<Boolean> featureResult = null;
    FeatureResult<Integer> startResult = startFeature.check(innerWrapper, env);
    FeatureResult<Integer> endResult = endFeature.check(innerWrapper, env);
    if (startResult != null && endResult != null) {
        int start = startResult.getOutcome();
        int end = endResult.getOutcome();
        if (start < 0)
            start = 0;
        if (end > token.getTokenSequence().size() - 1)
            end = token.getTokenSequence().size() - 1;
        if (start <= end) {
            Boolean result = Boolean.FALSE;
            for (int i = start; i <= end; i++) {
                Token oneToken = token.getTokenSequence().get(i);
                FeatureResult<Boolean> criterionResult = this.criterion.check(oneToken, env);
                if (criterionResult == null) {
                    result = null;
                    break;
                }
                result = result || criterionResult.getOutcome();
            }
            if (result != null) {
                featureResult = this.generateResult(result);
            }
        }
    }
    return featureResult;
}
Also used : Token(com.joliciel.talismane.tokeniser.Token)

Example 14 with Token

use of com.joliciel.talismane.tokeniser.Token in project talismane by joliciel-informatique.

the class TokenAtAddressFunction method checkInternal.

@Override
public FeatureResult<TokenWrapper> checkInternal(TokenWrapper tokenWrapper, RuntimeEnvironment env) throws TalismaneException {
    TokenWrapper innerWrapper = this.getToken(tokenWrapper, env);
    if (innerWrapper == null)
        return null;
    Token token = innerWrapper.getToken();
    FeatureResult<TokenWrapper> result = null;
    FeatureResult<Integer> indexResult = indexFeature.check(innerWrapper, env);
    if (indexResult != null) {
        int i = indexResult.getOutcome();
        if (i >= 0 && i < token.getTokenSequence().size()) {
            Token indexedToken = token.getTokenSequence().get(i);
            result = this.generateResult(indexedToken);
        }
    }
    return result;
}
Also used : Token(com.joliciel.talismane.tokeniser.Token)

Example 15 with Token

use of com.joliciel.talismane.tokeniser.Token in project talismane by joliciel-informatique.

the class TokenIndexFeature method checkInternal.

@Override
public FeatureResult<Integer> checkInternal(TokenWrapper tokenWrapper, RuntimeEnvironment env) throws TalismaneException {
    TokenWrapper innerWrapper = this.getToken(tokenWrapper, env);
    if (innerWrapper == null)
        return null;
    Token token = innerWrapper.getToken();
    FeatureResult<Integer> result = null;
    int index = token.getIndex();
    result = this.generateResult(index);
    return result;
}
Also used : Token(com.joliciel.talismane.tokeniser.Token)

Aggregations

Token (com.joliciel.talismane.tokeniser.Token)69 TokenSequence (com.joliciel.talismane.tokeniser.TokenSequence)16 ArrayList (java.util.ArrayList)15 Sentence (com.joliciel.talismane.rawText.Sentence)14 Decision (com.joliciel.talismane.machineLearning.Decision)12 Config (com.typesafe.config.Config)12 TalismaneTest (com.joliciel.talismane.TalismaneTest)11 PosTaggedToken (com.joliciel.talismane.posTagger.PosTaggedToken)11 Test (org.junit.Test)11 TalismaneException (com.joliciel.talismane.TalismaneException)7 RuntimeEnvironment (com.joliciel.talismane.machineLearning.features.RuntimeEnvironment)7 PosTagSequence (com.joliciel.talismane.posTagger.PosTagSequence)7 TokeniserOutcome (com.joliciel.talismane.tokeniser.TokeniserOutcome)7 List (java.util.List)7 WeightedOutcome (com.joliciel.talismane.utils.WeightedOutcome)6 HashMap (java.util.HashMap)6 StringLiteralFeature (com.joliciel.talismane.machineLearning.features.StringLiteralFeature)5 PosTag (com.joliciel.talismane.posTagger.PosTag)5 PosTaggerContext (com.joliciel.talismane.posTagger.PosTaggerContext)5 PosTaggerContextImpl (com.joliciel.talismane.posTagger.PosTaggerContextImpl)5