genders 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -0
 - data/Rakefile +44 -0
 - data/lib/genders.rb +52 -0
 - data/lib/genders/formal.rb +11 -0
 - data/lib/genders/informal.rb +10 -0
 - metadata +60 -0
 
    
        data/README.md
    ADDED
    
    
    
        data/Rakefile
    ADDED
    
    | 
         @@ -0,0 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rake'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rake/gempackagetask'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            task :default => [:test]
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            task :test do
         
     | 
| 
      
 7 
     | 
    
         
            +
              ruby "spec/genders_spec.rb"
         
     | 
| 
      
 8 
     | 
    
         
            +
            end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            GEM = "genders"
         
     | 
| 
      
 11 
     | 
    
         
            +
            GEM_VERSION = "0.1.0"
         
     | 
| 
      
 12 
     | 
    
         
            +
            SUMMARY = "Provides an easy way to determine the gender of an author from text."
         
     | 
| 
      
 13 
     | 
    
         
            +
            AUTHOR = "Gary Haran"
         
     | 
| 
      
 14 
     | 
    
         
            +
            EMAIL = "gary.haran@gmail.com"
         
     | 
| 
      
 15 
     | 
    
         
            +
            HOMEPAGE = ""
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            spec = Gem::Specification.new do |s|
         
     | 
| 
      
 18 
     | 
    
         
            +
              s.name = GEM
         
     | 
| 
      
 19 
     | 
    
         
            +
              s.version = GEM_VERSION
         
     | 
| 
      
 20 
     | 
    
         
            +
              s.platform = Gem::Platform::RUBY
         
     | 
| 
      
 21 
     | 
    
         
            +
              s.summary = SUMMARY
         
     | 
| 
      
 22 
     | 
    
         
            +
              s.require_paths = ['lib']
         
     | 
| 
      
 23 
     | 
    
         
            +
              s.files = FileList['app_generators/**/*', 'bin/*', 'lib/**/*.rb', '[A-Z]*'].to_a
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              s.author = AUTHOR
         
     | 
| 
      
 26 
     | 
    
         
            +
              s.email = EMAIL
         
     | 
| 
      
 27 
     | 
    
         
            +
              s.homepage = HOMEPAGE
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            Rake::GemPackageTask.new(spec) do |pkg|
         
     | 
| 
      
 31 
     | 
    
         
            +
              pkg.gem_spec = spec
         
     | 
| 
      
 32 
     | 
    
         
            +
            end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            desc "Install the gem locally"
         
     | 
| 
      
 35 
     | 
    
         
            +
            task :install => [:package] do
         
     | 
| 
      
 36 
     | 
    
         
            +
              sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
         
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            desc "Create a gemspec file"
         
     | 
| 
      
 40 
     | 
    
         
            +
            task :make_spec do
         
     | 
| 
      
 41 
     | 
    
         
            +
              File.open("#{GEM}.gemspec", "w") do |file|
         
     | 
| 
      
 42 
     | 
    
         
            +
                file.puts spec.to_ruby
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/genders.rb
    ADDED
    
    | 
         @@ -0,0 +1,52 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'ostruct'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Genders
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Guesser
         
     | 
| 
      
 5 
     | 
    
         
            +
                def self.analyze(text)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  score = OpenStruct.new
         
     | 
| 
      
 7 
     | 
    
         
            +
                  text  = text.downcase
         
     | 
| 
      
 8 
     | 
    
         
            +
                  score.female_score = self.female_score(self.female_determinate_words(text)).abs
         
     | 
| 
      
 9 
     | 
    
         
            +
                  score.male_score   = self.male_score(self.male_determinate_words(text)).abs
         
     | 
| 
      
 10 
     | 
    
         
            +
                  total = (score.female_score + score.male_score).to_f
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  if score.female_score < score.male_score
         
     | 
| 
      
 13 
     | 
    
         
            +
                    score.percentage = (total - score.female_score) / total * 100.0
         
     | 
| 
      
 14 
     | 
    
         
            +
                    score.gender = "male"
         
     | 
| 
      
 15 
     | 
    
         
            +
                  elsif score.female_score > score.male_score
         
     | 
| 
      
 16 
     | 
    
         
            +
                    score.percentage = (total - score.male_score) / total * 100.0
         
     | 
| 
      
 17 
     | 
    
         
            +
                    score.gender = "female"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  else
         
     | 
| 
      
 19 
     | 
    
         
            +
                    score.percentage = 50.0
         
     | 
| 
      
 20 
     | 
    
         
            +
                    score.gender = "indeterminate"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  score
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                def self.determinate_words(text)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  text.split.select{ |word| @female_words.merge(@male_words).keys.include?(word.downcase) }
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                def self.male_determinate_words(text)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  text.split.select{ |word| @male_words.keys.include? word.downcase }
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                def self.female_determinate_words(text)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  text.split.select{ |word| @female_words.keys.include? word.downcase }
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                def self.male_score(words)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  words.inject(0) do |total, word|
         
     | 
| 
      
 39 
     | 
    
         
            +
                    total + @male_words[word]
         
     | 
| 
      
 40 
     | 
    
         
            +
                  end
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                def self.female_score(words)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  words.inject(0) do |total, word|
         
     | 
| 
      
 45 
     | 
    
         
            +
                    total + @female_words[word]
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            require_relative 'genders/formal'
         
     | 
| 
      
 52 
     | 
    
         
            +
            require_relative 'genders/informal'
         
     | 
| 
         @@ -0,0 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Genders::Formal < Genders::Guesser
         
     | 
| 
      
 2 
     | 
    
         
            +
              @male_words = {
         
     | 
| 
      
 3 
     | 
    
         
            +
                "a"=>6, "above"=>4, "are"=>28, "around"=>42, "as"=>23, "at"=>6, "below"=>8, "is"=>8, "it"=>6, 
         
     | 
| 
      
 4 
     | 
    
         
            +
                "many"=>6, "more"=>34, "said"=>5, "the"=>7, "these"=>8, "to"=>2, "what"=>35, "who"=>19
         
     | 
| 
      
 5 
     | 
    
         
            +
              }
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              @female_words = {
         
     | 
| 
      
 8 
     | 
    
         
            +
                "and"=>-4, "be"=>-17, "her"=>-9, "hers"=>-3, "if"=>-47, "me"=>-4, "myself"=>-4, "not"=>-27, 
         
     | 
| 
      
 9 
     | 
    
         
            +
                "she"=>-6, "should"=>-7, "was"=>-1, "we"=>-8, "when"=>-17, "where"=>-18, "with"=>-52, "your"=>-17
         
     | 
| 
      
 10 
     | 
    
         
            +
              }
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Genders::Informal < Genders::Guesser
         
     | 
| 
      
 2 
     | 
    
         
            +
              @male_words = {
         
     | 
| 
      
 3 
     | 
    
         
            +
                "as"=>37, "ever"=>21, "good"=>31, "if"=>25, "in"=>10, "is"=>19, "now"=>33, "some"=>58, 
         
     | 
| 
      
 4 
     | 
    
         
            +
                "something"=>26, "the"=>17, "this"=>44, "well"=>15
         
     | 
| 
      
 5 
     | 
    
         
            +
              }
         
     | 
| 
      
 6 
     | 
    
         
            +
              @female_words ={
         
     | 
| 
      
 7 
     | 
    
         
            +
                "actually"=>-49, "am"=>-42, "because"=>-55, "but"=>-43, "everything"=>-44, "has"=>-33, 
         
     | 
| 
      
 8 
     | 
    
         
            +
                "him"=>-73, "like"=>-43, "more"=>-41, "out"=>-39, "since"=>-25, "so"=>-64, "too"=>-38
         
     | 
| 
      
 9 
     | 
    
         
            +
              }
         
     | 
| 
      
 10 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,60 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification 
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: genders
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version 
         
     | 
| 
      
 4 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors: 
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Gary Haran
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 10 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 11 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2011-04-08 00:00:00 -04:00
         
     | 
| 
      
 14 
     | 
    
         
            +
            default_executable: 
         
     | 
| 
      
 15 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            description: 
         
     | 
| 
      
 18 
     | 
    
         
            +
            email: gary.haran@gmail.com
         
     | 
| 
      
 19 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            files: 
         
     | 
| 
      
 26 
     | 
    
         
            +
            - lib/genders/formal.rb
         
     | 
| 
      
 27 
     | 
    
         
            +
            - lib/genders/informal.rb
         
     | 
| 
      
 28 
     | 
    
         
            +
            - lib/genders.rb
         
     | 
| 
      
 29 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 30 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 31 
     | 
    
         
            +
            has_rdoc: true
         
     | 
| 
      
 32 
     | 
    
         
            +
            homepage: ""
         
     | 
| 
      
 33 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 36 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            require_paths: 
         
     | 
| 
      
 39 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 40 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 41 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 42 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 43 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 44 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 45 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 46 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 47 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 48 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 49 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 50 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 51 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 52 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 55 
     | 
    
         
            +
            rubygems_version: 1.5.1
         
     | 
| 
      
 56 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 57 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 58 
     | 
    
         
            +
            summary: Provides an easy way to determine the gender of an author from text.
         
     | 
| 
      
 59 
     | 
    
         
            +
            test_files: []
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     |