use of com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper 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.features.PosTaggedTokenWrapper in project talismane by joliciel-informatique.
the class ValencyByLabelFeature method check.
@Override
public FeatureResult<Integer> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
ParseConfiguration configuration = wrapper.getParseConfiguration();
FeatureResult<PosTaggedTokenWrapper> tokenResult = addressFunction.check(wrapper, env);
FeatureResult<Integer> featureResult = null;
if (tokenResult != null) {
FeatureResult<String> depLabelResult = dependencyLabelFeature.check(wrapper, env);
if (depLabelResult != null) {
PosTaggedToken posTaggedToken = tokenResult.getOutcome().getPosTaggedToken();
String label = depLabelResult.getOutcome();
int valency = configuration.getDependents(posTaggedToken, label).size();
featureResult = this.generateResult(valency);
}
}
return featureResult;
}
use of com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper in project talismane by joliciel-informatique.
the class ValencyFeature method check.
@Override
public FeatureResult<Integer> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
ParseConfiguration configuration = wrapper.getParseConfiguration();
FeatureResult<PosTaggedTokenWrapper> tokenResult = addressFunction.check(wrapper, env);
FeatureResult<Integer> featureResult = null;
if (tokenResult != null) {
PosTaggedToken posTaggedToken = tokenResult.getOutcome().getPosTaggedToken();
int valency = configuration.getDependents(posTaggedToken).size();
featureResult = this.generateResult(valency);
}
return featureResult;
}
use of com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper in project talismane by joliciel-informatique.
the class DependencyCountIf method check.
@Override
public FeatureResult<Integer> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
ParseConfiguration configuration = wrapper.getParseConfiguration();
FeatureResult<PosTaggedTokenWrapper> tokenResult = addressFunction.check(wrapper, env);
FeatureResult<Integer> featureResult = null;
if (tokenResult != null) {
PosTaggedToken posTaggedToken = tokenResult.getOutcome().getPosTaggedToken();
int countMatching = 0;
for (PosTaggedToken dependent : configuration.getDependents(posTaggedToken)) {
ParseConfigurationAddress parseConfigurationAddress = new ParseConfigurationAddress(env);
parseConfigurationAddress.setParseConfiguration(configuration);
parseConfigurationAddress.setPosTaggedToken(dependent);
FeatureResult<Boolean> criterionResult = criterion.check(parseConfigurationAddress, env);
if (criterionResult != null && criterionResult.getOutcome())
countMatching++;
}
featureResult = this.generateResult(countMatching);
}
return featureResult;
}
use of com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper in project talismane by joliciel-informatique.
the class DependencyLabelFeature method check.
@Override
public FeatureResult<String> check(ParseConfigurationWrapper wrapper, RuntimeEnvironment env) throws TalismaneException {
PosTaggedTokenWrapper innerWrapper = this.getToken(wrapper, env);
if (innerWrapper == null)
return null;
PosTaggedToken posTaggedToken = innerWrapper.getPosTaggedToken();
if (posTaggedToken == null)
return null;
FeatureResult<String> featureResult = null;
ParseConfiguration configuration = wrapper.getParseConfiguration();
DependencyArc arc = configuration.getGoverningDependency(posTaggedToken);
if (arc != null) {
String label = arc.getLabel();
if (label == null)
label = "null";
featureResult = this.generateResult(label);
}
return featureResult;
}
Aggregations