Search in sources :

Example 6 with FunctionDescriptor

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

Example 7 with FunctionDescriptor

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

Example 8 with FunctionDescriptor

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

Example 9 with FunctionDescriptor

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;
}
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)

Example 10 with FunctionDescriptor

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

Aggregations

FunctionDescriptor (com.joliciel.talismane.machineLearning.features.FunctionDescriptor)11 FunctionDescriptorParser (com.joliciel.talismane.machineLearning.features.FunctionDescriptorParser)9 TreeSet (java.util.TreeSet)7 ArrayList (java.util.ArrayList)4 BooleanFeature (com.joliciel.talismane.machineLearning.features.BooleanFeature)3 TalismaneException (com.joliciel.talismane.TalismaneException)2 Feature (com.joliciel.talismane.machineLearning.features.Feature)2 AbstractFeature (com.joliciel.talismane.machineLearning.features.AbstractFeature)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 Transition (com.joliciel.talismane.parser.Transition)1 PosTag (com.joliciel.talismane.posTagger.PosTag)1 PosTaggerContext (com.joliciel.talismane.posTagger.PosTaggerContext)1 PosTaggedTokenFeature (com.joliciel.talismane.posTagger.features.PosTaggedTokenFeature)1