Skip to content

Commit

Permalink
copy editing
Browse files Browse the repository at this point in the history
  • Loading branch information
gsingers committed Aug 5, 2012
1 parent 66e1dcd commit 693ea37
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/tamingtext/qa/AnswerTypeClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public static void main(String[] args) throws IOException {
Parser parser = new ChunkParser(chunker, tagger);
AnswerTypeContextGenerator actg = new AnswerTypeContextGenerator(new File(wordnetDir));
//<start id="atc.train"/>
AnswerTypeEventStream es = new AnswerTypeEventStream(trainFile, actg, parser);
AnswerTypeEventStream es = new AnswerTypeEventStream(trainFile,
actg, parser);
GISModel model = GIS.trainModel(100, new TwoPassDataIndexer(es, 3));//<co id="atc.train.do"/>
new DoccatModel("en", model).serialize(new FileOutputStream(outFile));
/*
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/tamingtext/qa/PassageRankingComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ protected float scoreBigrams(SortedSet<WindowTerm> bigrams, Map<String, Float> b
//<start id="qa.scorePassage"/>
protected float scorePassage(Passage p, Map<String, Float> termWeights,
Map<String, Float> bigramWeights,
float adjWeight, float secondAdjWeight, float biWeight) {
float adjWeight, float secondAdjWeight,
float biWeight) {
Set<String> covered = new HashSet<String>();
float termScore = scoreTerms(p.terms, termWeights, covered);//<co id="prc.main"/>
float adjScore = scoreTerms(p.prevTerms, termWeights, covered) +
Expand All @@ -257,7 +258,8 @@ protected float scorePassage(Passage p, Map<String, Float> termWeights,
+ scoreTerms(p.secFollowTerms, termWeights, covered);//<co id="prc.sec"/>
//Give a bonus for bigram matches in the main window, could also
float bigramScore = scoreBigrams(p.bigrams, bigramWeights, covered);//<co id="prc.bigrams"/>
float score = termScore + (adjWeight * adjScore) + (secondAdjWeight * secondScore)
float score = termScore + (adjWeight * adjScore) +
(secondAdjWeight * secondScore)
+ (biWeight * bigramScore);//<co id="prc.score"/>
return (score);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/tamingtext/qa/QuestionQParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ public Query parse() throws ParseException {
}
try {
Analyzer analyzer = sp.getType().getQueryAnalyzer();
TokenStream ts = analyzer.tokenStream(field, new StringReader(qstr));
TokenStream ts = analyzer.tokenStream(field,
new StringReader(qstr));
while (ts.incrementToken()) {//<co id="qqp.addTerms"/>
String term = ((CharTermAttribute) ts.getAttribute(CharTermAttribute.class)).toString();
String term = ((CharTermAttribute)
ts.getAttribute(CharTermAttribute.class)).toString();
sql.add(new SpanTermQuery(new Term(field, term)));
}
} catch (IOException e) {
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/tamingtext/qa/QuestionQParserPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public QParser createParser(String qStr, SolrParams localParams, SolrParams para
QParser qParser;
if (params.getBool(QAParams.COMPONENT_NAME, false) == true //<co id="qqpp.explainif"/>
&& qStr.equals("*:*") == false) {
AnswerTypeClassifier atc = new AnswerTypeClassifier(model, probs, atcg);//<co id="qqpp.atc"/>
AnswerTypeClassifier atc =
new AnswerTypeClassifier(model, probs, atcg);//<co id="qqpp.atc"/>
Parser parser = new ChunkParser(chunker, tagger);//<co id="qqpp.parser"/>
qParser = new QuestionQParser(qStr, localParams, //<co id="qqpp.construct"/>
params, req, parser, atc, answerTypeMap);
Expand All @@ -92,8 +93,10 @@ public QParser createParser(String qStr, SolrParams localParams, SolrParams para
//<start id="qqpp.init"/>
public void init(NamedList initArgs) {
SolrParams params = SolrParams.toSolrParams(initArgs);
String modelDirectory = params.get("modelDirectory", System.getProperty("model.dir"));//<co id="qqpp.model"/>
String wordnetDirectory = params.get("wordnetDirectory", System.getProperty("wordnet.dir"));//<co id="qqpp.wordnet"/>
String modelDirectory = params.get("modelDirectory",
System.getProperty("model.dir"));//<co id="qqpp.model"/>
String wordnetDirectory = params.get("wordnetDirectory",
System.getProperty("wordnet.dir"));//<co id="qqpp.wordnet"/>
if (modelDirectory != null) {
File modelsDir = new File(modelDirectory);
try {
Expand All @@ -109,7 +112,8 @@ public void init(NamedList initArgs) {
new File(modelDirectory,"en-answer.bin")))
.getChunkerModel();
probs = new double[model.getNumOutcomes()];
atcg = new AnswerTypeContextGenerator(new File(wordnetDirectory, "dict"));//<co id="qqpp.context"/>
atcg = new AnswerTypeContextGenerator(
new File(wordnetDirectory, "dict"));//<co id="qqpp.context"/>
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/com/tamingtext/opennlp/AnswerTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ public void demonstrateATCG() throws Exception {
POSTaggerME tagger = new POSTaggerME(posModel);
Parser parser = new ChunkParser(chunker, tagger);
//<start id="att.answerTypeDemo"/>
AnswerTypeContextGenerator atcg = new AnswerTypeContextGenerator(new File(getWordNetDictionary().getAbsolutePath()));
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("atcg-questions.txt");
AnswerTypeContextGenerator atcg =
new AnswerTypeContextGenerator(
new File(getWordNetDictionary().getAbsolutePath()));
InputStream is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("atcg-questions.txt");
assertNotNull("input stream", is);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
Expand Down

0 comments on commit 693ea37

Please sign in to comment.