Search in sources :

Example 1 with Dossier

use of info.ephyra.answerselection.definitional.Dossier in project lucida by claritylab.

the class EphyraTREC13To16 method askOther.

/**
	 * Asks Ephyra an 'other' question, making use of the target description and
	 * previous questions and answers.
	 * 
	 * @param target the target the 'other' question is about
	 * @return array of results
	 */
public Result[] askOther(TRECTarget target) {
    //	get target type from interpretations of factoid/list questions
    TRECQuestion[] factoidQuestions = target.getQuestions();
    ArrayList<String> props = new ArrayList<String>();
    ArrayList<String> vals = new ArrayList<String>();
    ArrayList<String> sentences = new ArrayList<String>();
    String[] targetTokens = NETagger.tokenize(target.getTargetDesc());
    for (String tt : targetTokens) sentences.add(tt);
    //	collect properties and answers from FACTOID and LIST questions
    for (TRECQuestion fq : factoidQuestions) {
        QuestionInterpretation qi = fq.getInterpretation();
        if (qi != null) {
            String prop = qi.getProperty();
            TRECAnswer[] answers = fq.getAnswers();
            if (answers.length != 0) {
                //	collect property/value pair
                String val = answers[0].getAnswerString();
                props.add(prop);
                vals.add(val);
                //					MsgPrinter.printStatusMsg("Dossier on '" + target.getTargetDesc() + "' contains: '" + prop + "' is '" + val + "'");
                //	remember answer sentence for previous results
                String[] questionTokens = NETagger.tokenize(fq.getQuestionString());
                for (String qt : questionTokens) sentences.add(qt);
            }
        }
    }
    //	filter out results that bring no new terms but ones contained in the target, a previous question, or an answert to a previous question
    TermFilter.setPreviousResultsTerms(sentences.toArray(new String[sentences.size()]));
    //	initialize Dossier
    //		Dossier dossier = Dossier.getDossier(target.getTargetDesc(), target.getTargetType(), props.toArray(new String[props.size()]), vals.toArray(new String[vals.size()]));
    Dossier dossier = Dossier.getDossier(target.getTargetDesc(), null, props.toArray(new String[props.size()]), vals.toArray(new String[vals.size()]));
    //		MsgPrinter.printStatusMsg("Target type of '" + target.getTargetDesc() + "' is " + dossier.getTargetType());
    ArrayList<Result> rawResults = new ArrayList<Result>();
    //	collect missing properties
    String[] missingProps = dossier.getMissingPropertyNames();
    for (String mp : missingProps) {
        //	generate FACTOID question from template
        String question = QuestionInterpreter.getQuestion(target.getTargetDesc(), mp);
        //	if valid template exists, ask FACTOID question
        if (question != null) {
        //				MsgPrinter.printStatusMsg("Building Dossier on '" + target.getTargetDesc() + "', would ask this question now: '" + question + "'");
        //				Logger.enableLogging(false);
        //				Result res = this.askFactoid(question);
        //				Logger.enableLogging(true);
        //				
        //				//	if question could be answered, add new property and value to dossier
        //				if (res != null) {
        //					dossier.setProperty(mp, res.getAnswer());
        //					MsgPrinter.printStatusMsg("Dossier on '" + target.getTargetDesc() + "' extended: '" + mp + "' set to '" + res.getAnswer() + "'");
        //					rawResults.add(res);
        //					String sentence = res.getSentence();
        //					
        //					//	get supporting sentence of answer and, if existing, remember it as nugget
        //					if (sentence != null) {
        //						Result newRes = new Result(sentence, res.getQuery(), res.getDocID(), res.getHitPos());
        //						newRes.setScore(res.getScore() + 2);
        //						rawResults.add(newRes);
        //					}
        //				}
        }
    }
    NuggetEvaluationFilter.setTargetID(target.getId());
    //	collect BagOfWords results for target
    Result[] nuggets = askOther(target.getTargetDesc());
    for (Result r : nuggets) rawResults.add(r);
    nuggets = rawResults.toArray(new Result[rawResults.size()]);
    NuggetEvaluationFilter.targetFinished();
    //	reset term filter
    TermFilter.setPreviousResultsTerms(null);
    NuggetEvaluationFilter.setTargetID(null);
    return nuggets;
}
Also used : QuestionInterpretation(info.ephyra.questionanalysis.QuestionInterpretation) ArrayList(java.util.ArrayList) Result(info.ephyra.search.Result) Dossier(info.ephyra.answerselection.definitional.Dossier)

Aggregations

Dossier (info.ephyra.answerselection.definitional.Dossier)1 QuestionInterpretation (info.ephyra.questionanalysis.QuestionInterpretation)1 Result (info.ephyra.search.Result)1 ArrayList (java.util.ArrayList)1