Class: CorrectHorseBatteryStaple::Word
- Inherits:
-
Object
- Object
- CorrectHorseBatteryStaple::Word
- Includes:
- Comparable
- Defined in:
- lib/correct_horse_battery_staple/word.rb
Instance Attribute Summary collapse
-
#dispersion ⇒ Object
dispersion is Juilland dispersion, the % of texts containing the word.
-
#distance ⇒ Object
this word’s frequency’s distance from mean frequency in stddevs; signed.
-
#distance_probability ⇒ Object
distance_probability is the distance of this word’s probability from the mean in stddev.
-
#frequency ⇒ Object
frequency is the total count of the word in corpus.
-
#index ⇒ Object
rank is the word position when sorted by frequency in entire corpus index is the index of the word in this (sub)corpus.
-
#percentile ⇒ Object
in which percentile does the word appear.
-
#probability ⇒ Object
probability is the chance of any given word in a text composed of the sum of (word*frequency) in the corpus being this word.
-
#rank ⇒ Object
rank is the word position when sorted by frequency in entire corpus index is the index of the word in this (sub)corpus.
-
#texts ⇒ Object
texts is the # of texts containing the word.
-
#word ⇒ Object
text of word.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #[](attr) ⇒ Object
- #[]=(attr, value) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(value_map = {}) ⇒ Word
constructor
A new instance of Word.
- #inspect ⇒ Object
- #to_hash ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
- #update_from_hash(hash) ⇒ Object
Constructor Details
#initialize(value_map = {}) ⇒ Word
Returns a new instance of Word.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/correct_horse_battery_staple/word.rb', line 40 def initialize(value_map = {}) raise ArgumentError, "Must supply at least :word" unless value_map[:word] || value_map["word"] # phasing this out self.index = -1 case value_map when Hash then update_from_hash(value_map) when CorrectHorseBatteryStaple::Word then update_from_hash(value_map.to_hash) else raise "Can't initialize Word from #{value_map.inspect}" end end |
Instance Attribute Details
#dispersion ⇒ Object
dispersion is Juilland dispersion, the % of texts containing the word. texts is the # of texts containing the word.
14 15 16 |
# File 'lib/correct_horse_battery_staple/word.rb', line 14 def dispersion @dispersion end |
#distance ⇒ Object
this word’s frequency’s distance from mean frequency in stddevs; signed.
28 29 30 |
# File 'lib/correct_horse_battery_staple/word.rb', line 28 def distance @distance end |
#distance_probability ⇒ Object
distance_probability is the distance of this word’s probability from the mean in stddev
36 37 38 |
# File 'lib/correct_horse_battery_staple/word.rb', line 36 def distance_probability @distance_probability end |
#frequency ⇒ Object
frequency is the total count of the word in corpus
6 7 8 |
# File 'lib/correct_horse_battery_staple/word.rb', line 6 def frequency @frequency end |
#index ⇒ Object
rank is the word position when sorted by frequency in entire corpus index is the index of the word in this (sub)corpus
10 11 12 |
# File 'lib/correct_horse_battery_staple/word.rb', line 10 def index @index end |
#percentile ⇒ Object
in which percentile does the word appear. this can be calculated from the array of words so is somewhat redundant here
24 25 26 |
# File 'lib/correct_horse_battery_staple/word.rb', line 24 def percentile @percentile end |
#probability ⇒ Object
probability is the chance of any given word in a text composed of the sum of (word*frequency) in the corpus being this word.
32 33 34 |
# File 'lib/correct_horse_battery_staple/word.rb', line 32 def probability @probability end |
#rank ⇒ Object
rank is the word position when sorted by frequency in entire corpus index is the index of the word in this (sub)corpus
10 11 12 |
# File 'lib/correct_horse_battery_staple/word.rb', line 10 def rank @rank end |
#texts ⇒ Object
texts is the # of texts containing the word. this is not available for many frequency lists.
18 19 20 |
# File 'lib/correct_horse_battery_staple/word.rb', line 18 def texts @texts end |
#word ⇒ Object
text of word
3 4 5 |
# File 'lib/correct_horse_battery_staple/word.rb', line 3 def word @word end |
Instance Method Details
#<=>(other) ⇒ Object
53 54 55 |
# File 'lib/correct_horse_battery_staple/word.rb', line 53 def <=>(other) self.frequency <=> other.frequency end |
#==(other) ⇒ Object
99 100 101 |
# File 'lib/correct_horse_battery_staple/word.rb', line 99 def ==(other) self.word == other.word end |
#[](attr) ⇒ Object
85 86 87 |
# File 'lib/correct_horse_battery_staple/word.rb', line 85 def [](attr) send(attr.to_s) end |
#[]=(attr, value) ⇒ Object
89 90 91 |
# File 'lib/correct_horse_battery_staple/word.rb', line 89 def []=(attr, value) send("#{attr}=", value) end |
#eql?(other) ⇒ Boolean
95 96 97 |
# File 'lib/correct_horse_battery_staple/word.rb', line 95 def eql?(other) self.word == other.word end |
#inspect ⇒ Object
65 66 67 |
# File 'lib/correct_horse_battery_staple/word.rb', line 65 def inspect "CHBS::Word(#{self.to_hash.inspect})" end |
#to_hash ⇒ Object
69 70 71 72 73 74 |
# File 'lib/correct_horse_battery_staple/word.rb', line 69 def to_hash instance_variables.reduce({}) do |hash, key| hash[key.to_s[1..-1]] = instance_variable_get(key) hash end end |
#to_json(*args) ⇒ Object
57 58 59 |
# File 'lib/correct_horse_battery_staple/word.rb', line 57 def to_json(*args) to_hash.to_json(*args) end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/correct_horse_battery_staple/word.rb', line 61 def to_s self.word end |
#update_from_hash(hash) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/correct_horse_battery_staple/word.rb', line 76 def update_from_hash(hash) hash.each do |key, val| self[key] = val unless key.to_s == "wstruct" end self end |