Browse files

Made the capitalization factor into a constant, and updated the value…

… (from 3.0 to 2.1)
  • Loading branch information...
1 parent d3c0027 commit 51f24b7c9f6ffb47a3e2bc9cfd4ddc958e676b0f @mnielsen committed Jun 27, 2012
Showing with 7 additions and 4 deletions.
  1. +7 −4 mini_qa.py
View
11 mini_qa.py
@@ -34,6 +34,9 @@
wolfram_server = 'http://api.wolframalpha.com/v1/query.jsp'
+#### Parameters
+CAPITALIZATION_FACTOR = 2.1
+
#### Create or retrieve an S3 bucket for the cache of Google search
#### results
s3conn = S3Connection(config.AWS_ACCESS_KEY_ID, config.AWS_SECRET_ACCESS_KEY)
@@ -223,13 +226,13 @@ def ngrams(words, n=1):
def ngram_score(ngram, score):
"""
Return the score associated to `ngram`. The base score is
- `score`, but it's modified by a factor which is 3 to the power of
- the number of capitalized words. This biases answers toward
- proper nouns.
+ `score`, but it's modified by a factor which is
+ `CAPITALIZATION_FACTOR` to the power of the number of capitalized
+ words. This biases answers toward proper nouns.
"""
num_capitalized_words = sum(
1 for word in ngram if is_capitalized(word))
- return score * (3**num_capitalized_words)
+ return score * (CAPITALIZATION_FACTOR**num_capitalized_words)
def is_capitalized(word):
"""

0 comments on commit 51f24b7

Please sign in to comment.