Search in sources :

Example 11 with Feature

use of edu.cmu.minorthird.classify.Feature in project lucida by claritylab.

the class ScoreNormalizationFilter method addMinScoreFeature.

/**
	 * Adds the minimum score of all factoid answers from the same extractor as
	 * a feature to the instance.
	 */
private static void addMinScoreFeature(MutableInstance instance, Result result, Result[] results) {
    // calculate minimum score
    double minScore = Double.POSITIVE_INFINITY;
    //		String extractor = result.getExtractionTechniques()[0];
    for (Result r : results) if (r.getScore() > 0 && r.getScore() < Float.POSITIVE_INFINITY)
        //				if (r.extractedWith(extractor))
        minScore = Math.min(r.getScore(), minScore);
    Feature feature = new Feature(MIN_SCORE_F);
    instance.addNumeric(feature, minScore);
}
Also used : Feature(edu.cmu.minorthird.classify.Feature) Result(info.ephyra.search.Result)

Example 12 with Feature

use of edu.cmu.minorthird.classify.Feature in project lucida by claritylab.

the class HierarchicalClassifierTrainer method makeDataset.

private Dataset makeDataset(String fileName) {
    if (trainingLabels == null) {
        loadTraining = true;
        trainingLabels = new HashSet<String>();
    }
    Dataset set = new BasicDataset();
    extractor.setUseClassLevels(useClassLevels);
    extractor.setClassLevels(learnerNames.length);
    Example[] examples = extractor.loadFile(fileName);
    for (int i = 0; i < examples.length; i++) {
        String label = examples[i].getLabel().bestClassName();
        if (classLabels.contains(label)) {
            MutableInstance instance = new MutableInstance(examples[i].getSource(), examples[i].getSubpopulationId());
            Feature.Looper bLooper = examples[i].binaryFeatureIterator();
            while (bLooper.hasNext()) {
                Feature f = bLooper.nextFeature();
                if (featureTypes.contains(f.getPart(0))) {
                    instance.addBinary(f);
                }
            }
            Feature.Looper nLooper = examples[i].numericFeatureIterator();
            while (nLooper.hasNext()) {
                Feature f = nLooper.nextFeature();
                if (featureTypes.contains(f.getPart(0))) {
                    instance.addNumeric(f, examples[i].getWeight(f));
                }
            }
            Example example = new Example(instance, examples[i].getLabel());
            MLToolkit.println(example);
            if (loadTraining) {
                trainingLabels.add(label);
                set.add(example);
            } else {
                if (!trainingLabels.contains(label))
                    MLToolkit.println("Label of test example not found in training set (discarding): " + label);
                else
                    set.add(example);
            }
        } else {
            MLToolkit.println("Discarding example for Class: " + label);
        }
    }
    if (loadTraining)
        loadTraining = false;
    MLToolkit.println("Loaded " + set.size() + " examples for experiment from " + fileName);
    return set;
}
Also used : BasicDataset(edu.cmu.minorthird.classify.BasicDataset) CrossValidatedDataset(edu.cmu.minorthird.classify.experiments.CrossValidatedDataset) Dataset(edu.cmu.minorthird.classify.Dataset) Example(edu.cmu.minorthird.classify.Example) MutableInstance(edu.cmu.minorthird.classify.MutableInstance) BasicDataset(edu.cmu.minorthird.classify.BasicDataset) Feature(edu.cmu.minorthird.classify.Feature)

Example 13 with Feature

use of edu.cmu.minorthird.classify.Feature in project lucida by claritylab.

the class Rule method main.

/**
     * Tests Rule creation, compilation and matching.
     * 
     * @param args
     */
public static void main(String[] args) {
    String test = "<RULE atype=\"TEST_TYPE\">" + "<RULE_ELEMENT feature_name=\"TEST_FEATURE1\">" + "<FEATURE_VALUE>value1</FEATURE_VALUE>" + "<FEATURE_VALUE>value2</FEATURE_VALUE>" + "<FEATURE_VALUE>value3</FEATURE_VALUE>" + "</RULE_ELEMENT>" + "<RULE_ELEMENT feature_name=\"FOCUS_TYPE\">" + "<FEATURE_VALUE>value3=</FEATURE_VALUE>" + "<FEATURE_VALUE>value4=new</FEATURE_VALUE>" + "</RULE_ELEMENT>" + "</RULE>";
    Document ruleDocument;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(false);
        factory.setIgnoringComments(true);
        factory.setIgnoringElementContentWhitespace(true);
        factory.setNamespaceAware(true);
        DocumentBuilder db = factory.newDocumentBuilder();
        ruleDocument = db.parse(new InputSource(new StringReader(test)));
        Rule r = new Rule(ruleDocument.getDocumentElement());
        System.out.println("Test input: " + test);
        System.out.println(r.toString());
        MutableInstance testInstance = new MutableInstance(test);
        testInstance.addBinary(new Feature("TEST_FEATURE1.value1"));
        testInstance.addBinary(new Feature("FOCUS_TYPE.value4"));
        System.out.println("Test instance: " + testInstance);
        System.out.println("matches test rule?: " + r.matches(testInstance));
        testInstance = new MutableInstance(test);
        testInstance.addBinary(new Feature("TEST_FEATURE1.value1"));
        testInstance.addBinary(new Feature("FOCUS_TYPE.value3"));
        System.out.println("Test instance: " + testInstance);
        System.out.println("matches test rule?: " + r.matches(testInstance));
    } catch (Exception e) {
        throw new RuntimeException("Failed to parse XML string", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) MutableInstance(edu.cmu.minorthird.classify.MutableInstance) Document(org.w3c.dom.Document) Feature(edu.cmu.minorthird.classify.Feature)

Example 14 with Feature

use of edu.cmu.minorthird.classify.Feature in project lucida by claritylab.

the class RuleBasedQuestionClassifier method getFeatureValue.

/**
     * Retrieves the value of the given feature from the given Instance.
     * 
     * @param instance the Instance to consider
     * @param featName the name of the feature
     */
public static String getFeatureValue(Instance instance, String featName) {
    for (Iterator it = instance.binaryFeatureIterator(); it.hasNext(); ) {
        Feature f = (Feature) it.next();
        if (f.getPart(0).equals(featName)) {
            String val = f.getPart(1).trim();
            val = val.equals("-") ? null : val;
            return val;
        }
    }
    return null;
}
Also used : Iterator(java.util.Iterator) Feature(edu.cmu.minorthird.classify.Feature)

Example 15 with Feature

use of edu.cmu.minorthird.classify.Feature in project lucida by claritylab.

the class FeatureExtractor method printFeatures.

/**
     * Prints the features generated for each example in an input file.  If feature
     * types are included as command-line arguments, only those types are printed. 
     * Otherwise, all features are printed.
     * 
     * @param dataSetFileName the name of the file containing the dataset to load
     * @param features a List of the features to print
     */
public void printFeatures(String dataSetFileName, List<String> features) {
    Example[] examples = loadFile(dataSetFileName);
    for (int i = 0; i < examples.length; i++) {
        String src = (String) examples[i].getSource();
        StringBuilder sb = new StringBuilder();
        if (features.size() > 0) {
            for (Iterator it = examples[i].binaryFeatureIterator(); it.hasNext(); ) {
                Feature feat = (Feature) it.next();
                String name = "";
                for (String s : feat.getName()) name += "." + s;
                name = name.replaceFirst(".", "");
                if (features.contains(feat.getName()[0]))
                    sb.append(name + "  ");
            }
            System.out.println(sb.toString() + " " + src);
        } else
            System.out.println(examples[i] + " " + src);
    }
    System.out.println("Loaded: " + getNumLoaded());
}
Also used : Example(edu.cmu.minorthird.classify.Example) Iterator(java.util.Iterator) Feature(edu.cmu.minorthird.classify.Feature)

Aggregations

Feature (edu.cmu.minorthird.classify.Feature)15 Result (info.ephyra.search.Result)4 Iterator (java.util.Iterator)3 Term (edu.cmu.lti.javelin.qa.Term)2 Example (edu.cmu.minorthird.classify.Example)2 MutableInstance (edu.cmu.minorthird.classify.MutableInstance)2 Matcher (java.util.regex.Matcher)2 Tree (edu.cmu.lti.chineseNLP.util.Tree)1 BasicDataset (edu.cmu.minorthird.classify.BasicDataset)1 Dataset (edu.cmu.minorthird.classify.Dataset)1 Instance (edu.cmu.minorthird.classify.Instance)1 CrossValidatedDataset (edu.cmu.minorthird.classify.experiments.CrossValidatedDataset)1 StringReader (java.io.StringReader)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 IndexWord (net.didion.jwnl.data.IndexWord)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1