use of com.joliciel.talismane.machineLearning.features.Feature in project talismane by joliciel-informatique.
the class ParserFeatureParser 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 = this.getFeatureClasses(functionName);
@SuppressWarnings("rawtypes") Class<? extends Feature> featureClass = null;
if (featureClasses != null && featureClasses.size() > 0)
featureClass = featureClasses.get(0);
if (featureClass != null) {
if (featureClass.equals(DependencyCountIf.class)) {
if (functionDescriptor.getArguments().size() == 1) {
String descriptor = this.getFeatureClassDescriptors(ImplicitAddressFeature.class).get(0);
FunctionDescriptor implicitAddressDescriptor = new FunctionDescriptor(descriptor);
functionDescriptor.addArgument(0, implicitAddressDescriptor);
}
} else if (PosTaggedTokenFeature.class.isAssignableFrom(featureClass) || ParseConfigurationAddressFeature.class.isAssignableFrom(featureClass)) {
if (functionDescriptor.getArguments().size() == 0) {
String descriptor = this.getFeatureClassDescriptors(ImplicitAddressFeature.class).get(0);
FunctionDescriptor implicitAddressDescriptor = new FunctionDescriptor(descriptor);
functionDescriptor.addArgument(implicitAddressDescriptor);
}
// has arguments
}
}
if (descriptors.size() == 0) {
descriptors.add(functionDescriptor);
}
return descriptors;
}
use of com.joliciel.talismane.machineLearning.features.Feature 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