use of com.joliciel.talismane.machineLearning.features.FeatureSyntaxException 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;
}
Aggregations