use of info.ephyra.querygeneration.Query in project lucida by claritylab.
the class AnswerPatternFilter method apply.
/**
* Applies the answer patterns to the answer strings of the
* <code>Result</code> objects and creates a new <code>Result</code> for
* each extracted unique answer.
*
* @param results array of <code>Result</code> objects
* @return extended array of <code>Result</code> objects
*/
public Result[] apply(Result[] results) {
// extracted factoid answers and corresponding results
Hashtable<String, Result> factoids = new Hashtable<String, Result>();
for (Result result : results) {
// only apply this filter to results for the pattern matching
// approach
Query query = result.getQuery();
QuestionInterpretation qi = query.getInterpretation();
if (!query.extractWith(ID) || qi == null || result.getScore() > Float.NEGATIVE_INFINITY)
continue;
// extract PROPERTY objects
extractPos(result);
// create new result for each unique normalized PROPERTY object
for (int i = 0; i < extr.size(); i++) {
String po = extr.get(i);
String[] neTypes = types.get(i);
String norm = StringUtils.normalize(po);
String sentence = sents.get(i);
float conf = aps.get(i).getConfidence();
Result factoid = factoids.get(norm);
if (factoid == null) {
// new answer
// query, doc ID and sentence can be ambiguous
factoid = new Result(po, result.getQuery(), result.getDocID());
factoid.setSentence(sentence);
factoid.addExtractionTechnique(ID);
factoids.put(norm, factoid);
}
if (neTypes != null)
for (String neType : neTypes) factoid.addNeType(neType);
factoid.incScore(conf);
}
}
// keep old results
Result[] newResults = factoids.values().toArray(new Result[factoids.size()]);
Result[] allResults = new Result[results.length + newResults.length];
for (int i = 0; i < results.length; i++) allResults[i] = results[i];
for (int i = 0; i < newResults.length; i++) allResults[results.length + i] = newResults[i];
return allResults;
}
use of info.ephyra.querygeneration.Query in project lucida by claritylab.
the class PredicateG method generateQueries.
/**
* Generates queries from predicate-argument structures extracted from the
* question string.
*
* @param aq analyzed question
* @return <code>Query</code> objects
*/
public Query[] generateQueries(AnalyzedQuestion aq) {
// only generate a query if predicates could be extracted
Predicate[] ps = aq.getPredicates();
if (ps.length == 0)
return new Query[0];
// create query string
Term[] terms = aq.getTerms();
String[] kws = aq.getKeywords();
String queryString = getQueryString(ps, terms, kws);
// create query, set answer types and predicates
Query[] queries = new Query[1];
queries[0] = new Query(queryString, aq, SCORE);
queries[0].setExtractionTechniques(EXTRACTION_TECHNIQUES);
return queries;
}
use of info.ephyra.querygeneration.Query in project lucida by claritylab.
the class QuestionInterpretationG method generateQueries.
/**
* Creates queries from question interpretations. The query string is the
* concatenation of the target object, any context objects and the keywords
* in the question.
*
* @param aq analyzed question
* @return <code>Query</code> objects
*/
public Query[] generateQueries(AnalyzedQuestion aq) {
ArrayList<Query> queries = new ArrayList<Query>();
QuestionInterpretation[] qis = aq.getInterpretations();
String[] kws = aq.getKeywords();
for (QuestionInterpretation qi : qis) {
// create query string
String queryString = queryString(qi.getTarget(), qi.getContext(), kws);
// create query, set answer types and question interpretation
Query query = new Query(queryString, aq, SCORE);
query.setExtractionTechniques(EXTRACTION_TECHNIQUES);
query.setInterpretation(qi);
queries.add(query);
}
return queries.toArray(new Query[queries.size()]);
}
use of info.ephyra.querygeneration.Query in project lucida by claritylab.
the class QuestionReformulationG method generateQueries.
/**
* Generates queries that are reformulations of the question string.
*
* @param aq analyzed question
* @return <code>Query</code> objects
*/
public Query[] generateQueries(AnalyzedQuestion aq) {
// only generate queries if the answer type is known or the question is
// not a factoid question
String[] ats = aq.getAnswerTypes();
if (ats.length == 0 && aq.isFactoid())
return new Query[0];
ArrayList<Query> results = new ArrayList<Query>();
// create question reformulations
String verbMod = aq.getVerbMod();
String[] kws = aq.getKeywords();
if (reformulators != null) {
// reformulators loaded
Query[] queries;
for (QuestionReformulator reformulator : reformulators) {
queries = reformulator.apply(verbMod);
if (queries != null)
for (Query query : queries) {
// include context keywords in the query string
String queryString = query.getQueryString();
for (String kw : kws) if (!StringUtils.equalsCommonNorm(queryString, kw))
queryString += " " + kw;
query.setQueryString(queryString);
query.setAnalyzedQuestion(aq);
query.setExtractionTechniques(EXTRACTION_TECHNIQUES);
results.add(query);
}
}
}
return results.toArray(new Query[results.size()]);
}
use of info.ephyra.querygeneration.Query in project lucida by claritylab.
the class BagOfTermsG method generateQueries.
/**
* Generates a "bag of terms" query from the terms in the question string.
*
* @param aq analyzed question
* @return <code>Query</code> objects
*/
public Query[] generateQueries(AnalyzedQuestion aq) {
// only generate a query if the answer type is known, predicates could
// be extracted or the question is not a factoid question
String[] ats = aq.getAnswerTypes();
Predicate[] ps = aq.getPredicates();
if (ats.length == 0 && ps.length == 0 && aq.isFactoid())
return new Query[0];
// create query string
Term[] terms = aq.getTerms();
String[] kws = aq.getKeywords();
String queryString = getQueryString(terms, kws);
// create query, set answer types
Query[] queries = new Query[1];
queries[0] = new Query(queryString, aq, SCORE);
queries[0].setExtractionTechniques(EXTRACTION_TECHNIQUES);
return queries;
}
Aggregations