Search in sources :

Example 1 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class OpenEphyra method askFactoid.

/**
	 * Asks Ephyra a factoid question and returns up to <code>maxAnswers</code>
	 * results that have a score of at least <code>absThresh</code>.
	 * 
	 * @param question factoid question
	 * @param maxAnswers maximum number of answers
	 * @param absThresh absolute threshold for scores
	 * @return array of results
	 */
public Result[] askFactoid(String question, int maxAnswers, float absThresh) {
    // initialize pipeline
    initFactoid();
    // analyze question
    MsgPrinter.printAnalyzingQuestion();
    AnalyzedQuestion aq = QuestionAnalysis.analyze(question);
    // get answers
    Result[] results = runPipeline(aq, maxAnswers, absThresh);
    return results;
}
Also used : AnalyzedQuestion(info.ephyra.questionanalysis.AnalyzedQuestion) Result(info.ephyra.search.Result)

Example 2 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class OpenEphyra method askList.

/**
	 * Asks Ephyra a list question and returns results that have a score of at
	 * least <code>relThresh * top score</code>.
	 * 
	 * @param question list question
	 * @param relThresh relative threshold for scores
	 * @return array of results
	 */
public Result[] askList(String question, float relThresh) {
    question = QuestionNormalizer.transformList(question);
    Result[] results = askFactoid(question, Integer.MAX_VALUE, 0);
    // get results with a score of at least relThresh * top score
    ArrayList<Result> confident = new ArrayList<Result>();
    if (results.length > 0) {
        float topScore = results[0].getScore();
        for (Result result : results) if (result.getScore() >= relThresh * topScore)
            confident.add(result);
    }
    return confident.toArray(new Result[confident.size()]);
}
Also used : ArrayList(java.util.ArrayList) Result(info.ephyra.search.Result)

Example 3 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class OpenEphyraServer method askList.

/**
	 * Asks Ephyra a list question and returns results that have a score of at
	 * least <code>relThresh * top score</code>.
	 * 
	 * @param question list question
	 * @param relThresh relative threshold for scores
	 * @return array of results
	 */
public Result[] askList(String question, float relThresh) {
    question = QuestionNormalizer.transformList(question);
    Result[] results = askFactoid(question, Integer.MAX_VALUE, 0);
    // get results with a score of at least relThresh * top score
    ArrayList<Result> confident = new ArrayList<Result>();
    if (results.length > 0) {
        float topScore = results[0].getScore();
        for (Result result : results) if (result.getScore() >= relThresh * topScore)
            confident.add(result);
    }
    return confident.toArray(new Result[confident.size()]);
}
Also used : ArrayList(java.util.ArrayList) Result(info.ephyra.search.Result)

Example 4 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class OpenEphyraServer method handle.

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    String query_str = request.getQueryString();
    System.out.println("Query str: " + query_str);
    if (query_str == null) {
        response.setContentType("text/html;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_OK);
        baseRequest.setHandled(true);
        return;
    }
    String[] tokens = query_str.split("=");
    String question = URLDecoder.decode(tokens[1], "UTF-8");
    // response
    response.setContentType("text/html;charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);
    baseRequest.setHandled(true);
    PrintWriter out = response.getWriter();
    out.flush();
    // determine question type and extract question string
    String type;
    if (question.matches("(?i)" + FACTOID + ":.*+")) {
        // factoid question
        type = FACTOID;
        question = question.split(":", 2)[1].trim();
    } else if (question.matches("(?i)" + LIST + ":.*+")) {
        // list question
        type = LIST;
        question = question.split(":", 2)[1].trim();
    } else {
        // question type unspecified
        // default type
        type = FACTOID;
    }
    // ask question
    Result[] results = new Result[0];
    if (type.equals(FACTOID)) {
        Logger.logFactoidStart(question);
        results = askFactoid(question, FACTOID_MAX_ANSWERS, FACTOID_ABS_THRESH);
        Logger.logResults(results);
        Logger.logFactoidEnd();
    } else if (type.equals(LIST)) {
        Logger.logListStart(question);
        results = askList(question, LIST_REL_THRESH);
        Logger.logResults(results);
        Logger.logListEnd();
    }
    String answer = results[0].getAnswer();
    if (answer != null)
        out.println(answer);
    else
        out.println("Sorry, I cannot answer your question.");
    out.close();
}
Also used : PrintWriter(java.io.PrintWriter) Result(info.ephyra.search.Result)

Example 5 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class OpenEphyraServer method askFactoid.

/**
	 * Asks Ephyra a factoid question and returns up to <code>maxAnswers</code>
	 * results that have a score of at least <code>absThresh</code>.
	 * 
	 * @param question factoid question
	 * @param maxAnswers maximum number of answers
	 * @param absThresh absolute threshold for scores
	 * @return array of results
	 */
public Result[] askFactoid(String question, int maxAnswers, float absThresh) {
    // initialize pipeline
    initFactoid();
    // analyze question
    MsgPrinter.printAnalyzingQuestion();
    AnalyzedQuestion aq = QuestionAnalysis.analyze(question);
    // get answers
    Result[] results = runPipeline(aq, maxAnswers, absThresh);
    return results;
}
Also used : AnalyzedQuestion(info.ephyra.questionanalysis.AnalyzedQuestion) Result(info.ephyra.search.Result)

Aggregations

Result (info.ephyra.search.Result)68 ArrayList (java.util.ArrayList)36 Query (info.ephyra.querygeneration.Query)11 HashSet (java.util.HashSet)9 Hashtable (java.util.Hashtable)9 AnalyzedQuestion (info.ephyra.questionanalysis.AnalyzedQuestion)8 IOException (java.io.IOException)7 QuestionInterpretation (info.ephyra.questionanalysis.QuestionInterpretation)5 Feature (edu.cmu.minorthird.classify.Feature)4 HashMap (java.util.HashMap)4 Predicate (info.ephyra.nlp.semantics.Predicate)3 BagOfWordsG (info.ephyra.querygeneration.generators.BagOfWordsG)3 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 URL (java.net.URL)3 TRECTarget (info.ephyra.trec.TRECTarget)2 EOFException (java.io.EOFException)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStreamReader (java.io.InputStreamReader)2