demografix 0.1.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/README.md +66 -30
- data/lib/demografix/client.rb +1 -1
- data/lib/demografix/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e32fcb1768c53fe52e90ada47fe4d769670981532f6aea61084c5db7ec5fd636
|
|
4
|
+
data.tar.gz: 305dbff3f2b864435f09c6ade2bdf89f48e9140b5954aad39f6af4c9fe4293ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d9adc3c9710b7c42c12c235048b8c10cf6ff1c3e073beee61019d251f415f9e68ef7c95b2f9c467c5956a083fe99eb0a49dd06e05997d3d23b0c633bedf59446
|
|
7
|
+
data.tar.gz: 6d2f866f2052e62e96d6e58e7bf58856a879159a8539c85181d8660ffab749805a12f8dc7e176a9d75c220cda9d2f86184a6ba7a54efcd7ef95c2ed5c08f7837
|
data/README.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
# demografix (Ruby)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Predict gender, age, and nationality from names. One Ruby client covers all three Demografix
|
|
4
|
+
APIs — [genderize.io](https://genderize.io) (gender), [agify.io](https://agify.io) (age), and
|
|
5
|
+
[nationalize.io](https://nationalize.io) (nationality) — with single-name lookups and batches of up
|
|
6
|
+
to 100 names per request.
|
|
7
|
+
|
|
8
|
+
[](https://rubygems.org/gems/demografix)
|
|
9
|
+
[](https://github.com/DemografixGenderize/demografix-ruby/actions/workflows/ci.yml)
|
|
10
|
+
[](LICENSE)
|
|
5
11
|
|
|
6
12
|
## Install
|
|
7
13
|
|
|
@@ -17,12 +23,8 @@ Then run `bundle install`. To install directly:
|
|
|
17
23
|
gem install demografix
|
|
18
24
|
```
|
|
19
25
|
|
|
20
|
-
The client uses the Ruby standard library (`net/http` and `json`) and has no runtime dependencies. It
|
|
21
|
-
|
|
22
|
-
## Authentication
|
|
23
|
-
|
|
24
|
-
An API key is required. Creating one is free and includes 2,500 requests per month. Generate a key in your
|
|
25
|
-
dashboard at genderize.io, agify.io, or nationalize.io. One key works across all three services.
|
|
26
|
+
The client uses the Ruby standard library (`net/http` and `json`) and has no runtime dependencies. It
|
|
27
|
+
requires Ruby 3.2 or later.
|
|
26
28
|
|
|
27
29
|
## Quickstart
|
|
28
30
|
|
|
@@ -44,12 +46,13 @@ average_age = known.sum.to_f / known.length
|
|
|
44
46
|
ages.quota.remaining # => 24987
|
|
45
47
|
```
|
|
46
48
|
|
|
47
|
-
Each call returns prediction fields plus a `quota`. Batch calls return `results` (one prediction per
|
|
48
|
-
name, in input order) plus one `quota` for the response. Aggregate the results into a
|
|
49
|
+
Each call returns prediction fields plus a `quota`. Batch calls return `results` (one prediction per
|
|
50
|
+
input name, in input order) plus one `quota` for the response. Aggregate the results into a
|
|
51
|
+
distribution.
|
|
49
52
|
|
|
50
53
|
## genderize
|
|
51
54
|
|
|
52
|
-
Predict gender from
|
|
55
|
+
Predict gender from names.
|
|
53
56
|
|
|
54
57
|
```ruby
|
|
55
58
|
result = client.genderize("peter")
|
|
@@ -68,12 +71,12 @@ end
|
|
|
68
71
|
# => { "male" => 2, "female" => 2 }
|
|
69
72
|
```
|
|
70
73
|
|
|
71
|
-
`gender` is `"male"`, `"female"`, or `nil`. A name with no match returns `nil` gender, `0.0`
|
|
72
|
-
and `0` count. That is a successful response, not an error.
|
|
74
|
+
`gender` is `"male"`, `"female"`, or `nil`. A name with no match returns `nil` gender, `0.0`
|
|
75
|
+
probability, and `0` count. That is a successful response, not an error.
|
|
73
76
|
|
|
74
77
|
## agify
|
|
75
78
|
|
|
76
|
-
Predict age from
|
|
79
|
+
Predict age from names.
|
|
77
80
|
|
|
78
81
|
```ruby
|
|
79
82
|
result = client.agify("michael")
|
|
@@ -94,7 +97,7 @@ buckets = ages.group_by { |age| (age / 10) * 10 }
|
|
|
94
97
|
|
|
95
98
|
## nationalize
|
|
96
99
|
|
|
97
|
-
Predict nationality from
|
|
100
|
+
Predict nationality from names.
|
|
98
101
|
|
|
99
102
|
```ruby
|
|
100
103
|
result = client.nationalize("nguyen")
|
|
@@ -113,24 +116,45 @@ end
|
|
|
113
116
|
# => { "VN" => 1, "DE" => 1, "IT" => 1 }
|
|
114
117
|
```
|
|
115
118
|
|
|
116
|
-
`country` holds up to five candidates in descending probability order. A name with no match returns
|
|
117
|
-
`country` array.
|
|
119
|
+
`country` holds up to five candidates in descending probability order. A name with no match returns
|
|
120
|
+
an empty `country` array.
|
|
121
|
+
|
|
122
|
+
## Batch limit
|
|
123
|
+
|
|
124
|
+
Each batch accepts at most 100 names. A batch of more than 100 raises `ValidationError` before any
|
|
125
|
+
HTTP call is made. Chunk a longer list and aggregate across the chunks.
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
split = roster.each_slice(100).each_with_object(Hash.new(0)) do |chunk, counts|
|
|
129
|
+
client.genderize_batch(chunk).results.each do |pred|
|
|
130
|
+
counts[pred.gender || "unknown"] += 1
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
```
|
|
118
134
|
|
|
119
135
|
## country_id
|
|
120
136
|
|
|
121
|
-
`genderize` and `agify` accept an optional `country_id` (ISO 3166-1 alpha-2) to scope the prediction
|
|
122
|
-
country. `nationalize` does not accept it.
|
|
137
|
+
`genderize` and `agify` accept an optional `country_id` (ISO 3166-1 alpha-2) to scope the prediction
|
|
138
|
+
to a country. `nationalize` does not accept it. The value is echoed back uppercase in `country_id` on
|
|
139
|
+
every prediction.
|
|
123
140
|
|
|
124
141
|
```ruby
|
|
125
142
|
result = client.genderize("kim", country_id: "US")
|
|
126
143
|
result.country_id # => "US"
|
|
127
144
|
result.gender # => "female"
|
|
128
145
|
|
|
129
|
-
client.agify_batch(%w[andrea
|
|
146
|
+
client.agify_batch(%w[andrea giulia], country_id: "IT")
|
|
130
147
|
```
|
|
131
148
|
|
|
132
|
-
|
|
133
|
-
|
|
149
|
+
Scoping changes the prediction: `andrea` reads female with probability 0.99 in the United States and
|
|
150
|
+
male with probability 0.79 in Italy.
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
client.genderize("andrea", country_id: "US").gender # => "female"
|
|
154
|
+
client.genderize("andrea", country_id: "IT").gender # => "male"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
When the request sends no `country_id`, the field is `nil`.
|
|
134
158
|
|
|
135
159
|
## Quota
|
|
136
160
|
|
|
@@ -153,20 +177,18 @@ Read quota off the returned value or a raised error. The client does not cache i
|
|
|
153
177
|
|
|
154
178
|
## Errors
|
|
155
179
|
|
|
156
|
-
Every error subclasses `Demografix::Error` and carries `status`, `message`, and `quota` (when the
|
|
157
|
-
included rate-limit headers).
|
|
180
|
+
Every error subclasses `Demografix::Error` and carries `status`, `message`, and `quota` (when the
|
|
181
|
+
response included rate-limit headers).
|
|
158
182
|
|
|
159
183
|
| Error | Raised on |
|
|
160
184
|
|---|---|
|
|
161
185
|
| `Demografix::AuthError` | 401, invalid or missing API key |
|
|
162
186
|
| `Demografix::SubscriptionError` | 402, subscription not active |
|
|
163
|
-
| `Demografix::ValidationError` | 422, invalid parameters; also client-side for a batch over
|
|
187
|
+
| `Demografix::ValidationError` | 422, invalid parameters; also client-side for a batch over 100 names |
|
|
164
188
|
| `Demografix::RateLimitError` | 429, request limit reached (quota always populated) |
|
|
165
189
|
| `Demografix::TransportError` | network failure, timeout, or non-JSON body |
|
|
166
190
|
| `Demografix::Error` | any other non-2xx status |
|
|
167
191
|
|
|
168
|
-
A batch of more than 10 names raises `ValidationError` before any HTTP call is made.
|
|
169
|
-
|
|
170
192
|
On a `RateLimitError`, read `quota.reset` for the seconds to wait before retrying:
|
|
171
193
|
|
|
172
194
|
```ruby
|
|
@@ -189,7 +211,21 @@ end
|
|
|
189
211
|
| `nationalize(name)` | `NationalizeResult` | no |
|
|
190
212
|
| `nationalize_batch(names)` | `Batch` of `NationalizePrediction` | no |
|
|
191
213
|
|
|
192
|
-
`Demografix::Client.new` requires `api_key:` and accepts `timeout:` (optional, default 10 seconds).
|
|
193
|
-
host URLs and the User-Agent are fixed constants, not options.
|
|
214
|
+
`Demografix::Client.new` requires `api_key:` and accepts `timeout:` (optional, default 10 seconds).
|
|
215
|
+
The host URLs and the User-Agent are fixed constants, not options.
|
|
216
|
+
|
|
217
|
+
## API keys
|
|
218
|
+
|
|
219
|
+
An API key is required. Creating one is free and includes 2,500 names per month.
|
|
220
|
+
|
|
221
|
+
Quota counts **names, not requests**. A single-name call costs 1. A batch of 100 names costs 100. The
|
|
222
|
+
free tier therefore covers 2,500 names in a month however they are split across calls.
|
|
223
|
+
|
|
224
|
+
Generate a key in your dashboard at [genderize.io](https://genderize.io),
|
|
225
|
+
[agify.io](https://agify.io), or [nationalize.io](https://nationalize.io). One key works across all
|
|
226
|
+
three services. Full reference:
|
|
227
|
+
[genderize.io/documentation/api](https://genderize.io/documentation/api).
|
|
228
|
+
|
|
229
|
+
## License
|
|
194
230
|
|
|
195
|
-
|
|
231
|
+
MIT. See [LICENSE](LICENSE).
|
data/lib/demografix/client.rb
CHANGED
data/lib/demografix/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: demografix
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Demografix
|
|
@@ -51,8 +51,10 @@ dependencies:
|
|
|
51
51
|
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '3.18'
|
|
54
|
-
description: One client for the three Demografix APIs
|
|
55
|
-
prediction from
|
|
54
|
+
description: 'One client for the three Demografix APIs: gender, age, and nationality
|
|
55
|
+
prediction from a name. Look up a single name or send a batch of up to 100 names
|
|
56
|
+
in one request for bulk demographic analysis, optionally scoped to a country, and
|
|
57
|
+
read the remaining quota carried on every response.'
|
|
56
58
|
email:
|
|
57
59
|
- info@genderize.io
|
|
58
60
|
executables: []
|
|
@@ -90,5 +92,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
90
92
|
requirements: []
|
|
91
93
|
rubygems_version: 3.6.9
|
|
92
94
|
specification_version: 4
|
|
93
|
-
summary:
|
|
95
|
+
summary: Predict gender, age, and nationality from names — the official Ruby client
|
|
96
|
+
for genderize.io, agify.io, and nationalize.io.
|
|
94
97
|
test_files: []
|