-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracting term counting to separate, TextChunk class
- Loading branch information
1 parent
6a3d4ce
commit ba0b2a9
Showing
2 changed files
with
34 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class TextChunk | ||
attr_accessor :body | ||
|
||
BORING_TERMS = [ | ||
'secretary of state', | ||
'secretary of state for the home department' | ||
] | ||
|
||
# Yahoo term extractor likes sending back 'developme'. I have no | ||
# idea why. We replace it with 'development' later on. | ||
BROKEN_TERMS = { | ||
'developme' => 'development' | ||
} | ||
|
||
def initialize(body) | ||
@body = body | ||
end | ||
|
||
def terms | ||
list = TagExtractor.extract(body) - BORING_TERMS | ||
BROKEN_TERMS.each do |term, replacement| | ||
if list.include? term | ||
list.delete term | ||
list << replacement | ||
end | ||
end | ||
list | ||
end | ||
|
||
end |