Search in sources :

Example 6 with Term

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;
    }
}
Also used : Tree(edu.cmu.lti.chineseNLP.util.Tree) Term(edu.cmu.lti.javelin.qa.Term)

Example 7 with Term

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;
    }
}
Also used : Tree(edu.cmu.lti.chineseNLP.util.Tree) Term(edu.cmu.lti.javelin.qa.Term)

Example 8 with Term

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;
    }
}
Also used : Tree(edu.cmu.lti.chineseNLP.util.Tree) Term(edu.cmu.lti.javelin.qa.Term)

Example 9 with Term

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);
}
Also used : Instance(edu.cmu.minorthird.classify.Instance) MutableInstance(edu.cmu.minorthird.classify.MutableInstance) MutableInstance(edu.cmu.minorthird.classify.MutableInstance) Term(edu.cmu.lti.javelin.qa.Term) IOException(java.io.IOException)

Example 10 with Term

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);
}
Also used : ArrayList(java.util.ArrayList) Term(edu.cmu.lti.javelin.qa.Term) IOException(java.io.IOException)

Aggregations

Term (edu.cmu.lti.javelin.qa.Term)11 Tree (edu.cmu.lti.chineseNLP.util.Tree)6 MutableInstance (edu.cmu.minorthird.classify.MutableInstance)3 ArrayList (java.util.ArrayList)3 Feature (edu.cmu.minorthird.classify.Feature)2 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 Instance (edu.cmu.minorthird.classify.Instance)1 List (java.util.List)1 IndexWord (net.didion.jwnl.data.IndexWord)1