Search in sources :

Example 36 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class StackSearchFeature method check.

@Override
public FeatureResult<PosTaggedTokenWrapper> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
    ParseConfiguration configuration = wrapper.getParseConfiguration();
    int index = 1;
    if (indexFeature != null) {
        FeatureResult<Integer> indexResult = indexFeature.check(wrapper, env);
        if (indexResult == null)
            return null;
        index = indexResult.getOutcome();
    }
    Iterator<PosTaggedToken> stackIterator = configuration.getStack().iterator();
    ParseConfigurationAddress parseConfigurationAddress = new ParseConfigurationAddress(env);
    parseConfigurationAddress.setParseConfiguration(configuration);
    int i = -1;
    PosTaggedToken resultToken = null;
    while (stackIterator.hasNext()) {
        PosTaggedToken token = stackIterator.next();
        i++;
        if (i < index)
            continue;
        parseConfigurationAddress.setPosTaggedToken(token);
        FeatureResult<Boolean> criterionResult = criterionFeature.check(parseConfigurationAddress, env);
        if (criterionResult != null) {
            boolean criterion = criterionResult.getOutcome();
            if (criterion) {
                resultToken = token;
                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 37 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class TokenSearchFeature method check.

@Override
public FeatureResult<PosTaggedTokenWrapper> check(ParseConfigurationWrapper context, RuntimeEnvironment env) throws TalismaneException {
    FeatureResult<PosTaggedTokenWrapper> featureResult = null;
    PosTagSequence posTagSequence = context.getParseConfiguration().getPosTagSequence();
    int startIndex = 0;
    int endIndex = posTagSequence.size() - 1;
    if (startIndexFeature != null) {
        FeatureResult<Integer> startIndexResult = startIndexFeature.check(context, env);
        if (startIndexResult != null) {
            startIndex = startIndexResult.getOutcome();
        } else {
            return featureResult;
        }
    }
    if (endIndexFeature != null) {
        FeatureResult<Integer> endIndexResult = endIndexFeature.check(context, env);
        if (endIndexResult != null) {
            endIndex = endIndexResult.getOutcome();
        } else {
            return featureResult;
        }
    }
    if (startIndex < 0)
        startIndex = 0;
    if (endIndex < 0)
        endIndex = 0;
    if (startIndex >= posTagSequence.size())
        startIndex = posTagSequence.size() - 1;
    if (endIndex >= posTagSequence.size())
        endIndex = posTagSequence.size() - 1;
    int step = -1;
    if (endIndex > startIndex)
        step = 1;
    PosTaggedToken matchingToken = null;
    boolean findFirst = true;
    if (findFirstFeature != null) {
        FeatureResult<Boolean> findFirstResult = this.findFirstFeature.check(context, env);
        if (findFirstResult == null) {
            return null;
        }
        findFirst = findFirstResult.getOutcome();
    }
    ParseConfigurationAddress parseConfigurationAddress = new ParseConfigurationAddress(env);
    parseConfigurationAddress.setParseConfiguration(context.getParseConfiguration());
    int currentSkip = -1;
    for (int i = startIndex; (step < 0 && i >= 0 && i >= endIndex) || (step > 0 && i < posTagSequence.size() && i <= endIndex); i += step) {
        PosTaggedToken oneToken = posTagSequence.get(i);
        parseConfigurationAddress.setPosTaggedToken(oneToken);
        if (currentSkip < 0) {
            FeatureResult<Boolean> criterionResult = this.criterion.check(parseConfigurationAddress, env);
            if (criterionResult != null && criterionResult.getOutcome()) {
                matchingToken = oneToken;
                if (findFirst)
                    break;
            }
        }
        boolean endSkip = false;
        if (skipCriteria != null && skipCriteria.length > 0) {
            if (currentSkip < 0) {
                for (int j = 0; j < skipCriteria.length; j += 2) {
                    BooleanFeature<PosTaggedTokenWrapper> skipCriterion = skipCriteria[j];
                    FeatureResult<Boolean> skipResult = skipCriterion.check(parseConfigurationAddress, env);
                    if (skipResult != null && skipResult.getOutcome()) {
                        currentSkip = j;
                        break;
                    }
                }
            } else {
                int j = currentSkip + 1;
                BooleanFeature<PosTaggedTokenWrapper> endSkipCriterion = skipCriteria[j];
                FeatureResult<Boolean> endSkipResult = endSkipCriterion.check(parseConfigurationAddress, env);
                if (endSkipResult != null && endSkipResult.getOutcome()) {
                    endSkip = true;
                }
            }
        }
        if (currentSkip < 0) {
            if (stopCriterion != null) {
                FeatureResult<Boolean> stopCriterionResult = this.stopCriterion.check(parseConfigurationAddress, env);
                if (stopCriterionResult != null && stopCriterionResult.getOutcome()) {
                    break;
                }
            }
        }
        if (endSkip)
            currentSkip = -1;
    }
    if (matchingToken != null) {
        featureResult = this.generateResult(matchingToken);
    }
    return featureResult;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) PosTaggedTokenWrapper(com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper) PosTagSequence(com.joliciel.talismane.posTagger.PosTagSequence)

Example 38 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class AbstractLexicalAttributesFeature method checkInternal.

@Override
public FeatureResult<String> checkInternal(T context, RuntimeEnvironment env) throws TalismaneException {
    PosTaggedTokenWrapper innerWrapper = this.getToken(context, env);
    if (innerWrapper == null)
        return null;
    PosTaggedToken posTaggedToken = innerWrapper.getPosTaggedToken();
    if (posTaggedToken == null)
        return null;
    FeatureResult<String> featureResult = null;
    List<String> attributes = this.getAttributes(innerWrapper, env);
    Map<String, Set<String>> results = new HashMap<>();
    for (String attribute : attributes) {
        Set<String> values = new TreeSet<>();
        results.put(attribute, values);
        for (LexicalEntry lexicalEntry : posTaggedToken.getLexicalEntries()) {
            values.addAll(lexicalEntry.getAttributeAsList(attribute));
        }
    }
    boolean firstAttribute = true;
    boolean haveAtLeastOne = false;
    StringBuilder sb = new StringBuilder();
    for (String attribute : attributes) {
        if (!firstAttribute)
            sb.append("|");
        Set<String> values = results.get(attribute);
        if (values.size() > 0) {
            haveAtLeastOne = true;
            sb.append(values.stream().collect(Collectors.joining(";")));
        }
        firstAttribute = false;
    }
    if (haveAtLeastOne) {
        String result = sb.toString();
        featureResult = this.generateResult(result);
    }
    return featureResult;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) Set(java.util.Set) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) LexicalEntry(com.joliciel.talismane.lexicon.LexicalEntry)

Example 39 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class AssignedPosTagInFeature method checkInternal.

@Override
public FeatureResult<Boolean> checkInternal(T context, RuntimeEnvironment env) throws TalismaneException {
    PosTaggedTokenWrapper innerWrapper = this.getToken(context, env);
    if (innerWrapper == null)
        return null;
    PosTaggedToken posTaggedToken = innerWrapper.getPosTaggedToken();
    if (posTaggedToken == null)
        return null;
    FeatureResult<Boolean> featureResult = null;
    Set<String> posTagCodes = new HashSet<String>();
    for (StringFeature<PosTaggedTokenWrapper> posTagCodeFeature : posTagCodeFeatures) {
        FeatureResult<String> posTagCodeResult = posTagCodeFeature.check(innerWrapper, env);
        if (posTagCodeResult != null)
            posTagCodes.add(posTagCodeResult.getOutcome());
    }
    boolean result = posTagCodes.contains(posTaggedToken.getTag().getCode());
    featureResult = this.generateResult(result);
    return featureResult;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) HashSet(java.util.HashSet)

Example 40 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class ClosedClassFeature method checkInternal.

@Override
public FeatureResult<Boolean> checkInternal(T context, RuntimeEnvironment env) throws TalismaneException {
    PosTaggedTokenWrapper innerWrapper = this.getToken(context, env);
    if (innerWrapper == null)
        return null;
    PosTaggedToken posTaggedToken = innerWrapper.getPosTaggedToken();
    if (posTaggedToken == null)
        return null;
    FeatureResult<Boolean> featureResult = null;
    boolean isClosedClass = posTaggedToken.getTag().getOpenClassIndicator().isClosed();
    featureResult = this.generateResult(isClosedClass);
    return featureResult;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken)

Aggregations

PosTaggedToken (com.joliciel.talismane.posTagger.PosTaggedToken)77 ParseConfiguration (com.joliciel.talismane.parser.ParseConfiguration)24 PosTaggedTokenWrapper (com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper)20 PosTagSequence (com.joliciel.talismane.posTagger.PosTagSequence)14 Token (com.joliciel.talismane.tokeniser.Token)11 DependencyArc (com.joliciel.talismane.parser.DependencyArc)9 TalismaneException (com.joliciel.talismane.TalismaneException)8 Decision (com.joliciel.talismane.machineLearning.Decision)8 RuntimeEnvironment (com.joliciel.talismane.machineLearning.features.RuntimeEnvironment)8 Sentence (com.joliciel.talismane.rawText.Sentence)8 TokenSequence (com.joliciel.talismane.tokeniser.TokenSequence)8 HashMap (java.util.HashMap)7 List (java.util.List)7 TalismaneTest (com.joliciel.talismane.TalismaneTest)6 PosTaggerContext (com.joliciel.talismane.posTagger.PosTaggerContext)6 PosTaggerContextImpl (com.joliciel.talismane.posTagger.PosTaggerContextImpl)6 Config (com.typesafe.config.Config)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 StringLiteralFeature (com.joliciel.talismane.machineLearning.features.StringLiteralFeature)5