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;
}
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()]);
}
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()]);
}
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();
}
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;
}
Aggregations