Search in sources :

Example 1 with IntegerLiteralFeature

use of com.joliciel.talismane.machineLearning.features.IntegerLiteralFeature 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

IntegerLiteralFeature (com.joliciel.talismane.machineLearning.features.IntegerLiteralFeature)1 ParseConfiguration (com.joliciel.talismane.parser.ParseConfiguration)1 PosTaggedToken (com.joliciel.talismane.posTagger.PosTaggedToken)1 PosTaggedTokenWrapper (com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper)1