Search in sources :

Example 11 with PosTaggedToken

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

the class RightArcTransition method applyInternal.

@Override
protected void applyInternal(ParseConfiguration configuration) throws CircularDependencyException {
    PosTaggedToken head = configuration.getStack().pop();
    PosTaggedToken dependent = configuration.getBuffer().pollFirst();
    configuration.getBuffer().addFirst(head);
    configuration.addDependency(head, dependent, label, this);
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken)

Example 12 with PosTaggedToken

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

the class LeftArcEagerTransition method applyInternal.

@Override
protected void applyInternal(ParseConfiguration configuration) throws CircularDependencyException {
    PosTaggedToken head = configuration.getBuffer().getFirst();
    PosTaggedToken dependent = configuration.getStack().pop();
    configuration.addDependency(head, dependent, label, this);
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken)

Example 13 with PosTaggedToken

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

the class PosTaggerHistoryAddressFunction method checkInternal.

@Override
protected FeatureResult<PosTaggedTokenWrapper> checkInternal(PosTaggerContext context, RuntimeEnvironment env) throws TalismaneException {
    FeatureResult<PosTaggedTokenWrapper> result = null;
    FeatureResult<Integer> offsetResult = offsetFeature.check(context, env);
    if (offsetResult != null) {
        int n = offsetResult.getOutcome();
        if (n >= 0) {
            throw new TalismaneException("Cannot call PosTaggerHistoryFeature with an offset >= 0");
        }
        n = 0 - n;
        int i = context.getToken().getIndex();
        if (i >= n) {
            PosTaggedToken prevToken = context.getHistory().get(i - n);
            if (prevToken != null)
                result = this.generateResult(prevToken);
        }
    }
    // have n
    return result;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) TalismaneException(com.joliciel.talismane.TalismaneException)

Example 14 with PosTaggedToken

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

the class PosTagFeatureTester method onNextPosTagSequence.

@Override
public void onNextPosTagSequence(PosTagSequence posTagSequence) throws TalismaneException {
    PosTagSequence currentHistory = new PosTagSequence(posTagSequence.getTokenSequence());
    for (PosTaggedToken posTaggedToken : posTagSequence) {
        if (testWords.contains(posTaggedToken.getToken().getAnalyisText().toLowerCase())) {
            StringBuilder sb = new StringBuilder();
            boolean foundToken = false;
            for (PosTaggedToken taggedToken : posTagSequence) {
                if (taggedToken.equals(posTaggedToken)) {
                    sb.append(" [" + taggedToken.getToken().getOriginalText().replace(' ', '_') + "/" + taggedToken.getTag().toString() + "]");
                    foundToken = true;
                } else if (foundToken) {
                    sb.append(" " + taggedToken.getToken().getOriginalText().replace(' ', '_'));
                } else {
                    sb.append(" " + taggedToken.getToken().getOriginalText().replace(' ', '_') + "/" + taggedToken.getTag().toString());
                }
            }
            LOG.debug(sb.toString());
            String classification = posTaggedToken.getTag().getCode();
            PosTaggerContext context = new PosTaggerContextImpl(posTaggedToken.getToken(), currentHistory);
            List<FeatureResult<?>> posTagFeatureResults = new ArrayList<FeatureResult<?>>();
            for (PosTaggerFeature<?> posTaggerFeature : posTaggerFeatures) {
                RuntimeEnvironment env = new RuntimeEnvironment();
                FeatureResult<?> featureResult = posTaggerFeature.check(context, env);
                if (featureResult != null)
                    posTagFeatureResults.add(featureResult);
            }
            if (LOG.isTraceEnabled()) {
                LOG.trace("Token: " + posTaggedToken.getToken().getAnalyisText());
                for (FeatureResult<?> result : posTagFeatureResults) {
                    LOG.trace(result.toString());
                }
            }
            for (FeatureResult<?> featureResult : posTagFeatureResults) {
                Map<String, List<String>> classificationMap = featureResultMap.get(featureResult.toString());
                if (classificationMap == null) {
                    classificationMap = new TreeMap<String, List<String>>();
                    featureResultMap.put(featureResult.toString(), classificationMap);
                }
                List<String> sentences = classificationMap.get(classification);
                if (sentences == null) {
                    sentences = new ArrayList<String>();
                    classificationMap.put(classification, sentences);
                }
                sentences.add(sb.toString());
            }
        }
        currentHistory.addPosTaggedToken(posTaggedToken);
    }
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) RuntimeEnvironment(com.joliciel.talismane.machineLearning.features.RuntimeEnvironment) ArrayList(java.util.ArrayList) PosTaggerContext(com.joliciel.talismane.posTagger.PosTaggerContext) PosTaggerContextImpl(com.joliciel.talismane.posTagger.PosTaggerContextImpl) PosTagSequence(com.joliciel.talismane.posTagger.PosTagSequence) ArrayList(java.util.ArrayList) List(java.util.List) FeatureResult(com.joliciel.talismane.machineLearning.features.FeatureResult)

Example 15 with PosTaggedToken

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

the class HistoryHasFeature 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;
    FeatureResult<Boolean> criterionResult = criterion.check(innerWrapper, env);
    if (criterionResult != null) {
        featureResult = this.generateResult(criterionResult.getOutcome());
    }
    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