use of info.ephyra.questionanalysis.atype.AnswerType in project lucida by claritylab.
the class Rule method matches.
/**
* Tells whether a given Instance matches this Rule by returning
* the appropriate answer type if it does match, and <code>null</code>
* if it does not.
*
* @param instance the Instance to consider
* @return the answer type and subtype formed by matching this Rule to the
* given Instance, or <code>null</code> if this Rule does not match the Instance.
* @throws IllegalStateException if this Rule has not been compiled yet
*/
public AnswerType matches(Instance instance) {
if (elements == null)
throw new IllegalStateException("Must compile rule before using it");
String retAtype = atype;
AnswerType res = null;
// All elements of the rule must match in order for the rule to match
for (RuleElement element : elements) {
String result = element.matches(instance);
if (result == null) {
return null;
} else if (element.getFeature().equals("FOCUS_TYPE")) {
result = result.toUpperCase();
if (!result.equals(atype) && result != "")
retAtype = atype + "." + result;
}
}
res = AnswerType.constructFromString(retAtype);
res.setConfidence(confidence);
return res;
}
use of info.ephyra.questionanalysis.atype.AnswerType in project lucida by claritylab.
the class TrainedQuestionClassifier method classify.
public List<AnswerType> classify(Instance instance) {
List<AnswerType> res = new ArrayList<AnswerType>();
ClassLabel label = null;
synchronized (classifier) {
label = classifier.classification(instance);
}
String labelStr = label.bestClassName().replaceAll("-", ".");
AnswerType atype = AnswerType.constructFromString(labelStr);
double weight = label.bestWeight();
if (weight > 1.0)
weight = (1 - (1 / weight));
atype.setConfidence(weight);
res.add(atype);
return res;
}
use of info.ephyra.questionanalysis.atype.AnswerType in project lucida by claritylab.
the class QuestionAnalysis method getAtypes.
private static String[] getAtypes(String question) {
List<AnswerType> atypes = new ArrayList<AnswerType>();
try {
atypes = qc.getAnswerTypes(question);
} catch (Exception e) {
e.printStackTrace();
}
Set<AnswerType> remove = new HashSet<AnswerType>();
for (AnswerType atype : atypes) {
if (atype.getFullType(-1).equals("NONE")) {
remove.add(atype);
}
}
for (AnswerType atype : remove) {
atypes.remove(atype);
}
String[] res = new String[atypes.size()];
for (int i = 0; i < atypes.size(); i++) {
String atype = atypes.get(i).getFullType(-1).toLowerCase().replaceAll("\\.", "->NE").replaceAll("^", "NE");
StringBuilder sb = new StringBuilder(atype);
Matcher m = Pattern.compile("_(\\w)").matcher(atype);
while (m.find()) {
sb.replace(m.start(), m.end(), m.group(1).toUpperCase());
m = Pattern.compile("_(\\w)").matcher(sb.toString());
}
res[i] = sb.toString();
}
return res;
}
use of info.ephyra.questionanalysis.atype.AnswerType 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;
}
Aggregations