Search in sources :

Example 6 with Example

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

the class FeatureExtractor method createExample.

/**
     * Creates an edu.cmu.minorthird.classify.Example object from one line
     * of a dataset file using {@link #createInstance(String, String)}.
     * 
     * @param datasetLine the line from the dataset file from which to create
     * the Example 
     * @return the Example created
     * @throws Exception
     */
public Example[] createExample(String datasetLine) throws Exception {
    Matcher m = datasetExamplePattern.matcher(datasetLine);
    if (!m.matches())
        throw new Exception("Malformed dataset line:\n" + datasetLine);
    String[] aTypes = null;
    aTypes = m.group(labelPosition).replaceAll(",$", "").replaceAll(",", ".").split("\\|");
    String question = m.group(questionPosition);
    String sentParse = null;
    if (parsePosition > -1)
        sentParse = m.group(parsePosition);
    Instance instance = createInstance(question, sentParse);
    Example[] result = new Example[aTypes.length];
    //create example(s) and add it to list
    for (int i = 0; i < aTypes.length; i++) {
        String newATypeName = HierarchicalClassifier.getHierarchicalClassName(aTypes[i], classLevels, useClassLevels);
        result[i] = new Example(instance, new ClassLabel(newATypeName));
    }
    return result;
}
Also used : ClassLabel(edu.cmu.minorthird.classify.ClassLabel) Matcher(java.util.regex.Matcher) Instance(edu.cmu.minorthird.classify.Instance) Example(edu.cmu.minorthird.classify.Example)

Example 7 with Example

use of edu.cmu.minorthird.classify.Example 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

Example (edu.cmu.minorthird.classify.Example)7 ClassLabel (edu.cmu.minorthird.classify.ClassLabel)3 BasicDataset (edu.cmu.minorthird.classify.BasicDataset)2 Dataset (edu.cmu.minorthird.classify.Dataset)2 Feature (edu.cmu.minorthird.classify.Feature)2 Instance (edu.cmu.minorthird.classify.Instance)2 MutableInstance (edu.cmu.minorthird.classify.MutableInstance)2 CrossValidatedDataset (edu.cmu.minorthird.classify.experiments.CrossValidatedDataset)2 Matcher (java.util.regex.Matcher)2 ClassifierLearner (edu.cmu.minorthird.classify.ClassifierLearner)1 Result (info.ephyra.search.Result)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1