use of edu.cmu.lti.javelin.qa.Term in project lucida by claritylab.
the class FocusFinder method findFocusWord.
/**
* Given a list of Terms, builds a parse tree using Charniak's parser, and
* then uses the resulting parse tree to find the focus words.
*
* @param terms The list of Terms in the question.
* @return the focus word as a String or null, if one does not exist
*/
public static String findFocusWord(List<Term> terms) {
try {
String question = "";
for (Term term : terms) {
question += term + " ";
}
Tree t = findFocusNode(TreeHelper.buildTree(StanfordParser.parse(question), Tree.ENGLISH));
if (t != null)
return TreeHelper.getLeaves(t);
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of edu.cmu.lti.javelin.qa.Term in project lucida by claritylab.
the class FocusFinder method findFocusTerm.
/**
* Given a sentence, builds a parse tree using Charniak's parser, and
* then uses the resulting parse tree to find the focus words.
*
* @param question the input question
* @return the focus word as a Term or null, if one does not exist
*/
public static Term findFocusTerm(String question) {
try {
Tree t = findFocusNode(TreeHelper.buildTree(StanfordParser.parse(question), Tree.ENGLISH));
if (t != null) {
Term res = new Term(0, 0, TreeHelper.getLeaves(t));
res.setPOS(t.getLabel());
return res;
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of edu.cmu.lti.javelin.qa.Term in project lucida by claritylab.
the class FocusFinder method findFocusTerm.
/**
* Finds the focus word, given a Tree.
*
* @param tree The syntactic parse tree object
* @return the focus word as a Term or null, if one does not exist
*/
public static Term findFocusTerm(Tree tree) {
try {
Tree t = findFocusNode(tree);
if (t != null) {
Term res = new Term(0, 0, TreeHelper.getLeaves(t));
res.setPOS(t.getLabel());
return res;
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of edu.cmu.lti.javelin.qa.Term in project lucida by claritylab.
the class QuestionClassifier method getAnswerTypes.
/**
* Classifies the question represented by the given List of Terms and parse tree
* as having a particular answer type and possibly subtype.
*
* @param terms the Terms that make up the question to classify
* @param parseTreeStr the syntactic parse tree of the question, in String format
*
* @return the candidate answer type / subtypes.
* @throws Exception
*/
public List<AnswerType> getAnswerTypes(List<Term> terms, String parseTreeStr) throws Exception {
if (!isInitialized())
throw new Exception("getAnswerTypes called while not initialized");
String question = "";
for (Term term : terms) question += term.getText() + " ";
// create the instance
Instance instance = new MutableInstance(question);
if (extractor != null)
instance = extractor.createInstance(terms, parseTreeStr);
return classify(instance);
}
use of edu.cmu.lti.javelin.qa.Term in project lucida by claritylab.
the class QuestionClassifier method getAnswerTypes.
/**
* Classifies the question represented by the given String and parse tree
* as having a particular answer type and possibly subtype.
*
* @param question the question to classify
* @param parseTreeStr the syntactic parse tree of the question, in String format
*
* @return the candidate answer type / subtypes.
* @throws Exception
*/
public List<AnswerType> getAnswerTypes(String question, String parseTreeStr) throws Exception {
if (!isInitialized())
throw new Exception("getAnswerTypes called while not initialized");
String[] tokens = question.split("\\s+");
List<Term> terms = new ArrayList<Term>();
for (String token : tokens) {
terms.add(new Term(0, 0, token));
}
return getAnswerTypes(terms, parseTreeStr);
}
Aggregations