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