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);
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations