sexmachine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +14 -0
- data/LICENSE +674 -0
- data/README.rdoc +24 -0
- data/Rakefile +14 -0
- data/docs/README_rdoc.html +123 -0
- data/docs/SexMachine.html +163 -0
- data/docs/SexMachine/Detector.html +376 -0
- data/docs/created.rid +5 -0
- data/docs/index.html +68 -0
- data/docs/lib/sexmachine/detector_rb.html +52 -0
- data/docs/lib/sexmachine/version_rb.html +52 -0
- data/docs/lib/sexmachine_rb.html +56 -0
- data/docs/rdoc.css +706 -0
- data/lib/sexmachine.rb +2 -0
- data/lib/sexmachine/data/nam_dict.txt +48890 -0
- data/lib/sexmachine/detector.rb +51 -0
- data/lib/sexmachine/version.rb +3 -0
- metadata +65 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module SexMachine
|
2
|
+
|
3
|
+
class Detector
|
4
|
+
def initialize(fname=nil)
|
5
|
+
fname ||= File.expand_path('../data/nam_dict.txt', __FILE__)
|
6
|
+
parse fname
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse(fname)
|
10
|
+
@names = {}
|
11
|
+
open(fname, "r:iso8859-1:utf-8") { |f|
|
12
|
+
f.each_line { |line|
|
13
|
+
eatNameLine line
|
14
|
+
}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_gender(name)
|
19
|
+
@names.fetch(name, :andy)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def eatNameLine(line)
|
24
|
+
return if line.start_with?("#") or line.start_with?("=")
|
25
|
+
|
26
|
+
parts = line.split(" ").select { |p| p.strip != "" }
|
27
|
+
|
28
|
+
if parts[0].include? "F"
|
29
|
+
set parts[1], :female
|
30
|
+
elsif parts[0].include? "M"
|
31
|
+
set parts[1], :male
|
32
|
+
else
|
33
|
+
set parts[1], :andy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def set(name, gender)
|
38
|
+
# go w/ first option, don't reset
|
39
|
+
return if @names.has_key? name
|
40
|
+
|
41
|
+
if name.include? "+"
|
42
|
+
[ '', '-', ' ' ].each { |replacement|
|
43
|
+
set name.gsub("+", replacement), gender
|
44
|
+
}
|
45
|
+
else
|
46
|
+
@names[name] = gender
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sexmachine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Muller
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-24 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Get gender from first name.
|
15
|
+
email: brian.muller@livingsocial.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/sexmachine/data/nam_dict.txt
|
21
|
+
- lib/sexmachine/detector.rb
|
22
|
+
- lib/sexmachine/version.rb
|
23
|
+
- lib/sexmachine.rb
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE
|
27
|
+
- Rakefile
|
28
|
+
- README.rdoc
|
29
|
+
- docs/created.rid
|
30
|
+
- docs/index.html
|
31
|
+
- docs/lib/sexmachine/detector_rb.html
|
32
|
+
- docs/lib/sexmachine/version_rb.html
|
33
|
+
- docs/lib/sexmachine_rb.html
|
34
|
+
- docs/rdoc.css
|
35
|
+
- docs/README_rdoc.html
|
36
|
+
- docs/SexMachine/Detector.html
|
37
|
+
- docs/SexMachine.html
|
38
|
+
homepage: https://github.com/bmuller/sexmachine
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.9.2
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
hash: 1950402375859060057
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project: sexmachine
|
61
|
+
rubygems_version: 1.8.17
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Get gender from first name.
|
65
|
+
test_files: []
|