Search in sources :

Example 1 with QuestionClassifier

use of info.ephyra.questionanalysis.atype.QuestionClassifier in project lucida by claritylab.

the class HybridQuestionClassifier method initialize.

public void initialize() throws Exception {
    // return if already initialized
    if (isInitialized())
        return;
    if (languagePair == null)
        throw new Exception("languagePair must be set before calling initialize");
    super.initialize();
    Properties properties = Properties.loadFromClassName(this.getClass().getName());
    properties = properties.mapProperties().get(languagePair.getFirst() + "_" + languagePair.getSecond());
    String classifierClassNames = properties.get("classifierTypes").trim();
    if (classifierClassNames == null)
        throw new RuntimeException("Required property classifierTypes is undefined");
    String[] classNames = classifierClassNames.split(",");
    classifiers = new ArrayList<QuestionClassifier>();
    for (String className : classNames) {
        QuestionClassifier classifier = (QuestionClassifier) Class.forName(className).newInstance();
        classifier.setLanguagePair(languagePair);
        classifier.initialize();
        classifiers.add(classifier);
    }
    String mergeResultsStr = properties.get("mergeResults").trim();
    if (mergeResultsStr == null)
        throw new RuntimeException("Required property mergeResults is undefined");
    mergeResults = Boolean.parseBoolean(mergeResultsStr);
    String confidenceThresholdStr = properties.get("confidenceThreshold").trim();
    if (mergeResultsStr == null)
        throw new RuntimeException("Required property confidenceThreshold is undefined");
    confidenceThreshold = Double.parseDouble(confidenceThresholdStr);
    setInitialized(true);
}
Also used : Properties(info.ephyra.util.Properties) QuestionClassifier(info.ephyra.questionanalysis.atype.QuestionClassifier)

Example 2 with QuestionClassifier

use of info.ephyra.questionanalysis.atype.QuestionClassifier in project lucida by claritylab.

the class HybridQuestionClassifier method classify.

public List<AnswerType> classify(Instance instance) {
    List<AnswerType> res = new ArrayList<AnswerType>();
    for (QuestionClassifier classifier : classifiers) {
        List<AnswerType> classifierResult = classifier.classify(instance);
        if (classifierResult != null && classifierResult.size() > 0 && !classifierResult.get(0).getType().equals("NOANS")) {
            if (!mergeResults)
                return classifierResult;
            for (AnswerType atype : classifierResult) if (!res.contains(atype))
                res.add(atype);
        }
    }
    Collections.sort(res, atypeComparator);
    for (int i = 0; i < res.size(); i++) {
        if (res.get(i).getConfidence() < confidenceThreshold) {
            res.remove(i);
            i--;
        }
    }
    if (res.size() == 0)
        res.add(AnswerType.constructFromString("NONE"));
    return res;
}
Also used : ArrayList(java.util.ArrayList) AnswerType(info.ephyra.questionanalysis.atype.AnswerType) QuestionClassifier(info.ephyra.questionanalysis.atype.QuestionClassifier)

Aggregations

QuestionClassifier (info.ephyra.questionanalysis.atype.QuestionClassifier)2 AnswerType (info.ephyra.questionanalysis.atype.AnswerType)1 Properties (info.ephyra.util.Properties)1 ArrayList (java.util.ArrayList)1