use of com.joliciel.talismane.machineLearning.features.FunctionDescriptor in project talismane by joliciel-informatique.
the class ParserFeatureParser method getFeatures.
public Set<ParseConfigurationFeature<?>> getFeatures(List<String> featureDescriptors) {
Set<ParseConfigurationFeature<?>> parseFeatures = new TreeSet<ParseConfigurationFeature<?>>();
FunctionDescriptorParser descriptorParser = new FunctionDescriptorParser();
for (String featureDescriptor : featureDescriptors) {
if (featureDescriptor.trim().length() > 0 && !featureDescriptor.startsWith("#")) {
FunctionDescriptor functionDescriptor = descriptorParser.parseDescriptor(featureDescriptor);
List<ParseConfigurationFeature<?>> myFeatures = this.parseDescriptor(functionDescriptor);
parseFeatures.addAll(myFeatures);
}
}
return parseFeatures;
}
use of com.joliciel.talismane.machineLearning.features.FunctionDescriptor in project talismane by joliciel-informatique.
the class TokenPatternMatchFeatureParser method getTokenPatternMatchFeatureSet.
public Set<TokenPatternMatchFeature<?>> getTokenPatternMatchFeatureSet(List<String> featureDescriptors) {
Set<TokenPatternMatchFeature<?>> features = new TreeSet<TokenPatternMatchFeature<?>>();
FunctionDescriptorParser descriptorParser = new FunctionDescriptorParser();
for (String featureDescriptor : featureDescriptors) {
if (featureDescriptor.length() > 0 && !featureDescriptor.startsWith("#")) {
FunctionDescriptor functionDescriptor = descriptorParser.parseDescriptor(featureDescriptor);
List<TokenPatternMatchFeature<?>> myFeatures = this.parseDescriptor(functionDescriptor);
features.addAll(myFeatures);
}
}
return features;
}
use of com.joliciel.talismane.machineLearning.features.FunctionDescriptor in project talismane by joliciel-informatique.
the class SentenceDetectorFeatureParser method getFeatureSet.
public Set<SentenceDetectorFeature<?>> getFeatureSet(List<String> featureDescriptors) {
Set<SentenceDetectorFeature<?>> features = new TreeSet<SentenceDetectorFeature<?>>();
FunctionDescriptorParser descriptorParser = new FunctionDescriptorParser();
for (String featureDescriptor : featureDescriptors) {
if (featureDescriptor.length() > 0 && !featureDescriptor.startsWith("#")) {
FunctionDescriptor functionDescriptor = descriptorParser.parseDescriptor(featureDescriptor);
List<SentenceDetectorFeature<?>> myFeatures = this.parseDescriptor(functionDescriptor);
features.addAll(myFeatures);
}
}
return features;
}
use of com.joliciel.talismane.machineLearning.features.FunctionDescriptor in project jochre by urieli.
the class ShapeFeatureParser method getModifiedDescriptors.
@Override
public List<FunctionDescriptor> getModifiedDescriptors(FunctionDescriptor functionDescriptor) {
List<FunctionDescriptor> descriptors = new ArrayList<FunctionDescriptor>();
String functionName = functionDescriptor.getFunctionName();
@SuppressWarnings("rawtypes") List<Class<? extends Feature>> featureClasses = container.getFeatureClasses(functionName);
@SuppressWarnings("rawtypes") Class<? extends Feature> featureClass = null;
if (featureClasses != null && featureClasses.size() > 0)
featureClass = featureClasses.get(0);
if (functionName.equalsIgnoreCase("SectionRelativeBrightnessGrid")) {
if (!(functionDescriptor.getArguments().get(0).getObject() instanceof Integer))
throw new FeatureSyntaxException(functionName + " argument 1 must be a whole number", functionDescriptor, functionDescriptor);
if (!(functionDescriptor.getArguments().get(1).getObject() instanceof Integer))
throw new FeatureSyntaxException(functionName + " argument 2 must be a whole number", functionDescriptor, functionDescriptor);
if (!(functionDescriptor.getArguments().get(2).getObject() instanceof Double))
throw new FeatureSyntaxException(functionName + " argument 3 must be a decimal number", functionDescriptor, functionDescriptor);
if (!(functionDescriptor.getArguments().get(3).getObject() instanceof Double))
throw new FeatureSyntaxException(functionName + " argument 4 must be a decimal number", functionDescriptor, functionDescriptor);
int verticalSections = ((Integer) functionDescriptor.getArguments().get(0).getObject()).intValue();
int horizontalSections = ((Integer) functionDescriptor.getArguments().get(1).getObject()).intValue();
String newFunctionName = "SectionRelativeBrightness";
for (int x = 0; x < verticalSections; x++) {
for (int y = 0; y < horizontalSections; y++) {
FunctionDescriptor descriptor = new FunctionDescriptor(newFunctionName);
descriptor.addArgument(x);
descriptor.addArgument(y);
descriptor.addArgument(verticalSections);
descriptor.addArgument(horizontalSections);
descriptor.addArgument(functionDescriptor.getArguments().get(2));
descriptor.addArgument(functionDescriptor.getArguments().get(3));
descriptors.add(descriptor);
}
}
} else if (functionName.equalsIgnoreCase("SectionRelativeBrightnessNoMarginsGrid")) {
if (!(functionDescriptor.getArguments().get(0).getObject() instanceof Integer))
throw new FeatureSyntaxException(functionName + " argument 1 must be a whole number", functionDescriptor, functionDescriptor);
if (!(functionDescriptor.getArguments().get(1).getObject() instanceof Integer))
throw new FeatureSyntaxException(functionName + " argument 2 must be a whole number", functionDescriptor, functionDescriptor);
int verticalSections = ((Integer) functionDescriptor.getArguments().get(0).getObject()).intValue();
int horizontalSections = ((Integer) functionDescriptor.getArguments().get(1).getObject()).intValue();
String newFunctionName = "SectionRelativeBrightnessNoMargins";
for (int x = 0; x < verticalSections; x++) {
for (int y = 0; y < horizontalSections; y++) {
FunctionDescriptor descriptor = new FunctionDescriptor(newFunctionName);
descriptor.addArgument(x);
descriptor.addArgument(y);
descriptor.addArgument(verticalSections);
descriptor.addArgument(horizontalSections);
descriptors.add(descriptor);
}
}
} else if (featureClass == null) {
// do nothing
}
return descriptors;
}
use of com.joliciel.talismane.machineLearning.features.FunctionDescriptor in project jochre by urieli.
the class MergeFeatureParser method getMergeFeatureSet.
public Set<MergeFeature<?>> getMergeFeatureSet(List<String> featureDescriptors) {
Set<MergeFeature<?>> features = new TreeSet<MergeFeature<?>>();
FunctionDescriptorParser descriptorParser = new FunctionDescriptorParser();
for (String featureDescriptor : featureDescriptors) {
LOG.trace(featureDescriptor);
if (featureDescriptor.length() > 0 && !featureDescriptor.startsWith("#")) {
FunctionDescriptor functionDescriptor = descriptorParser.parseDescriptor(featureDescriptor);
List<MergeFeature<?>> myFeatures = this.parseDescriptor(functionDescriptor);
features.addAll(myFeatures);
}
}
return features;
}
Aggregations