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