Class: Classyfier::Classifiers::Gender
- Inherits:
-
Object
- Object
- Classyfier::Classifiers::Gender
- Defined in:
- lib/classyfier/gender.rb
Instance Method Summary collapse
- #classify(name) ⇒ Object
-
#initialize(opts = {:dictionary => :popular}) ⇒ Gender
constructor
A new instance of Gender.
Constructor Details
#initialize(opts = {:dictionary => :popular}) ⇒ Gender
Returns a new instance of Gender.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/classyfier/gender.rb', line 6 def initialize(opts = {:dictionary => :popular}) #Load the dictionaries if opts[:dictionary] == :popular @male_dict = load_dictionary("popular_male_names_1960-2010.dat") @female_dict = load_dictionary("popular_female_names_1960-2010.dat") else @male_dict = load_dictionary("census_male_1990.dat") @female_dict = load_dictionary("census_female_1990.dat") end end |
Instance Method Details
#classify(name) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/classyfier/gender.rb', line 17 def classify(name) male_score = @male_dict[name.downcase].to_f || -1 female_score = @female_dict[name.downcase].to_f || -1 return {:male => 0, :female => 1} if male_score < 0 and female_score > 0 return {:male => 1, :female => 0} if male_score > 0 and female_score < 0 return {:male => 0, :female => 0} if male_score == 0 and female_score == 0 return {:male => male_score/(male_score + female_score), :female => female_score/(male_score + female_score)} end |