Search in sources :

Example 1 with Feature

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;
}
Also used : ArrayList(java.util.ArrayList) FunctionDescriptor(com.joliciel.talismane.machineLearning.features.FunctionDescriptor) AbstractFeature(com.joliciel.talismane.machineLearning.features.AbstractFeature) DoubleFeature(com.joliciel.talismane.machineLearning.features.DoubleFeature) IntegerFeature(com.joliciel.talismane.machineLearning.features.IntegerFeature) Feature(com.joliciel.talismane.machineLearning.features.Feature) StringFeature(com.joliciel.talismane.machineLearning.features.StringFeature) PosTaggedTokenFeature(com.joliciel.talismane.posTagger.features.PosTaggedTokenFeature) BooleanFeature(com.joliciel.talismane.machineLearning.features.BooleanFeature)

Example 2 with Feature

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;
}
Also used : ArrayList(java.util.ArrayList) FunctionDescriptor(com.joliciel.talismane.machineLearning.features.FunctionDescriptor) Feature(com.joliciel.talismane.machineLearning.features.Feature) FeatureSyntaxException(com.joliciel.talismane.machineLearning.features.FeatureSyntaxException)

Aggregations

Feature (com.joliciel.talismane.machineLearning.features.Feature)2 FunctionDescriptor (com.joliciel.talismane.machineLearning.features.FunctionDescriptor)2 ArrayList (java.util.ArrayList)2 AbstractFeature (com.joliciel.talismane.machineLearning.features.AbstractFeature)1 BooleanFeature (com.joliciel.talismane.machineLearning.features.BooleanFeature)1 DoubleFeature (com.joliciel.talismane.machineLearning.features.DoubleFeature)1 FeatureSyntaxException (com.joliciel.talismane.machineLearning.features.FeatureSyntaxException)1 IntegerFeature (com.joliciel.talismane.machineLearning.features.IntegerFeature)1 StringFeature (com.joliciel.talismane.machineLearning.features.StringFeature)1 PosTaggedTokenFeature (com.joliciel.talismane.posTagger.features.PosTaggedTokenFeature)1