fake_british_toponym 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +8 -8
- data/fake_british_toponym.gemspec +3 -2
- data/lib/fake_british_toponym.rb +45 -71
- data/lib/fake_british_toponym/corpus.rb +229 -0
- data/lib/fake_british_toponym/version.rb +1 -1
- data/spec/fake_british_toponym_spec.rb +45 -18
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4a64ee31075c5aa867e9c17b4f02dc9ac0d5157
|
4
|
+
data.tar.gz: 343d8ba461b7d3ed614e4fe1b76193fb925cb7e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ff7f640f02d13029a6869e78c4157c67bfebd65c189b83e302ad44bdc2ff91dfc5dcff7d385e25b5954d9b611347335df7c4adea0f699e905db35f3d3892383
|
7
|
+
data.tar.gz: 3d0ab9d548613f45499a763b19520f535f1245691e5077e2e21c2967ac2a7f86561e3a3628f3142bcfad1290c4b70bff2b4ab613170bc6c3f5317160d906c297
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -26,14 +26,14 @@ Or install it yourself as:
|
|
26
26
|
$ pry
|
27
27
|
[0] main » require "fake_british_toponym"
|
28
28
|
=> true
|
29
|
-
[0] main » FakeBritishToponym.new
|
30
|
-
=> "
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
[0] main » FakeBritishToponym.new
|
36
|
-
=> "
|
29
|
+
[0] main » Array.new(5) { FakeBritishToponym.new }
|
30
|
+
=> ["Abercastercesholm",
|
31
|
+
"Lymekirktunforth",
|
32
|
+
"South Gloutonbeck",
|
33
|
+
"Intonwich",
|
34
|
+
"Port Shrewsbeckhamp"]
|
35
|
+
[0] main » FakeBritishToponym.new(min_syllables: 5)
|
36
|
+
=> "Lancotherglennock Castle"
|
37
37
|
|
38
38
|
...that's all, folks!
|
39
39
|
|
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.required_ruby_version = "~> 2.0"
|
21
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
24
25
|
end
|
data/lib/fake_british_toponym.rb
CHANGED
@@ -1,92 +1,80 @@
|
|
1
1
|
require "probability"
|
2
2
|
|
3
|
-
|
3
|
+
require "fake_british_toponym/corpus"
|
4
4
|
|
5
|
-
|
6
|
-
PREFIXES = %w( aber avon ash bex birm blen brad bre burn car chef cul dal don dun ex gains glou hex hol in inver ips kil kings knock lan leigh lin lock lon long lough lyme man mannan mid middle mills moss new nor not oak ock old pad pen puds shrews stan stin sud sur swin tarn thorn tilly tre up wake wall well wey which wil win wor worth yar )
|
7
|
-
INFIXES = %w( beck caster ces cester cot er folk ford glen ham hamp her ill ing kirk more ness nock ter tun ton wich )
|
8
|
-
SUFFIXES = %w( bie borough bost born burgh bury bridge by carden cay chester church combe dale deen den don dun ey field firth fork forth frith garth gate head holm hop hurst inge keld lan land law leigh ley low minster moth mouth orth over pool rith rock sbury set shaw shep ship shire stead ster stone ter thorp tham thwait tyne well wich wold wick )
|
9
|
-
POSTFIXES = %w( bight castle crossing downs gate glen grove hall hamlet -in- marsh of -on- -on-the- river 's sands town -under- -upon- village water willow )
|
5
|
+
class FakeBritishToponym < String
|
10
6
|
|
11
7
|
def initialize(**args)
|
12
8
|
args[:modifier] = true unless args.has_key? :modifier
|
13
9
|
args[:min_syllables] ||= 2
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
add_prefix
|
11
|
+
super build_name(args[:min_syllables], args[:modifier])
|
12
|
+
end
|
18
13
|
|
19
|
-
|
20
|
-
add_infix
|
21
|
-
end
|
14
|
+
private
|
22
15
|
|
23
|
-
|
16
|
+
def build_name(min_syllables, use_modifier)
|
17
|
+
pieces = []
|
24
18
|
|
25
|
-
|
19
|
+
pieces.push CORPUS.random_prefix.capitalize
|
26
20
|
|
27
|
-
|
21
|
+
min_syllables.times do
|
22
|
+
pieces.push pick_infix(pieces)
|
23
|
+
end
|
28
24
|
|
29
|
-
|
30
|
-
end
|
25
|
+
add_suffix(pieces) if pieces.length == 1 || 3.in(10)
|
31
26
|
|
32
|
-
|
33
|
-
@name.to_s
|
34
|
-
end
|
27
|
+
add_decoration(pieces) if use_modifier && 1.in(2)
|
35
28
|
|
36
|
-
|
29
|
+
name = pieces.join
|
37
30
|
|
38
|
-
|
39
|
-
@pieces.unshift "#{random_antefix.capitalize} "
|
31
|
+
name
|
40
32
|
end
|
41
33
|
|
42
|
-
def
|
43
|
-
|
34
|
+
def add_antefix(list)
|
35
|
+
list.unshift "#{CORPUS.random_antefix.capitalize} "
|
44
36
|
end
|
45
37
|
|
46
|
-
def
|
47
|
-
|
38
|
+
def add_suffix(list)
|
39
|
+
list.push pick_suffix(list)
|
48
40
|
end
|
49
41
|
|
50
|
-
def
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
def add_postfix
|
55
|
-
pick = random_postfix
|
42
|
+
def add_postfix(list)
|
43
|
+
pick = CORPUS.random_postfix
|
56
44
|
case pick
|
57
45
|
when /^-/ # "-on-the-", "-upon-", etc
|
58
|
-
|
59
|
-
|
46
|
+
list.push pick
|
47
|
+
list.push new_decoration_toponym
|
60
48
|
when "of"
|
61
|
-
|
62
|
-
|
49
|
+
list.push " #{pick} "
|
50
|
+
list.push new_decoration_toponym
|
63
51
|
when "'s"
|
64
|
-
|
65
|
-
|
52
|
+
list.push "#{pick} "
|
53
|
+
list.push new_decoration_toponym
|
66
54
|
else
|
67
|
-
|
55
|
+
list.push " #{pick.capitalize}"
|
68
56
|
end
|
69
57
|
end
|
70
58
|
|
71
|
-
def add_decoration
|
59
|
+
def add_decoration(list)
|
72
60
|
if 1.in(2)
|
73
|
-
add_antefix
|
61
|
+
add_antefix(list)
|
74
62
|
else
|
75
|
-
add_postfix
|
63
|
+
add_postfix(list)
|
76
64
|
end
|
77
65
|
end
|
78
66
|
|
79
|
-
def pick_infix
|
67
|
+
def pick_infix(list)
|
80
68
|
begin
|
81
|
-
pick = random_infix
|
82
|
-
end while pick ==
|
83
|
-
|
69
|
+
pick = CORPUS.random_infix
|
70
|
+
end while pick == list.last # try not to double up syllables
|
71
|
+
double_last_letter(list) if doubled_last_letter_needed?(list, pick)
|
84
72
|
pick
|
85
73
|
end
|
86
74
|
|
87
|
-
def pick_suffix
|
88
|
-
pick = random_suffix
|
89
|
-
|
75
|
+
def pick_suffix(list)
|
76
|
+
pick = CORPUS.random_suffix
|
77
|
+
double_last_letter(list) if doubled_last_letter_needed?(list, pick)
|
90
78
|
pick
|
91
79
|
end
|
92
80
|
|
@@ -94,21 +82,10 @@ class FakeBritishToponym < String
|
|
94
82
|
self.class.new modifier: false
|
95
83
|
end
|
96
84
|
|
97
|
-
|
98
|
-
define_method("random_#{which}fix") do
|
99
|
-
corpus = self.class.const_get("#{which.upcase}FIXES")
|
100
|
-
corpus.sample
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def double_last_letter_if_needed(pick)
|
105
|
-
double_last_letter if doubled_last_letter_needed?(pick)
|
106
|
-
end
|
107
|
-
|
108
|
-
def doubled_last_letter_needed?(pick)
|
85
|
+
def doubled_last_letter_needed?(list, pick)
|
109
86
|
return false unless begins_with_vowel? pick
|
110
|
-
return false if ends_with_vowel?
|
111
|
-
return false if ends_with_doubled_letters?
|
87
|
+
return false if ends_with_vowel? list.last
|
88
|
+
return false if ends_with_doubled_letters? list.last
|
112
89
|
true
|
113
90
|
end
|
114
91
|
|
@@ -124,13 +101,10 @@ class FakeBritishToponym < String
|
|
124
101
|
word[-1] == word[-2]
|
125
102
|
end
|
126
103
|
|
127
|
-
def double_last_letter
|
128
|
-
last_piece =
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
def join_pieces
|
133
|
-
@pieces.join.to_s
|
104
|
+
def double_last_letter(list)
|
105
|
+
last_piece = list.pop
|
106
|
+
last_piece_doubled = last_piece + last_piece[-1]
|
107
|
+
list.push last_piece_doubled
|
134
108
|
end
|
135
109
|
|
136
110
|
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
class FakeBritishToponym < String
|
2
|
+
module CORPUS
|
3
|
+
|
4
|
+
def self.random_antefix
|
5
|
+
ANTEFIXES.sample
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.random_prefix
|
9
|
+
PREFIXES.sample
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.random_infix
|
13
|
+
INFIXES.sample
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.random_suffix
|
17
|
+
SUFFIXES.sample
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.random_postfix
|
21
|
+
POSTFIXES.sample
|
22
|
+
end
|
23
|
+
|
24
|
+
ANTEFIXES = %w(
|
25
|
+
east
|
26
|
+
great
|
27
|
+
little
|
28
|
+
new
|
29
|
+
north
|
30
|
+
old
|
31
|
+
port
|
32
|
+
saint
|
33
|
+
south
|
34
|
+
west
|
35
|
+
)
|
36
|
+
|
37
|
+
PREFIXES = %w(
|
38
|
+
aber
|
39
|
+
avon
|
40
|
+
ash
|
41
|
+
bex
|
42
|
+
birm
|
43
|
+
blen
|
44
|
+
brad
|
45
|
+
bre
|
46
|
+
burn
|
47
|
+
car
|
48
|
+
chef
|
49
|
+
cul
|
50
|
+
dal
|
51
|
+
don
|
52
|
+
dun
|
53
|
+
ex
|
54
|
+
gains
|
55
|
+
glou
|
56
|
+
hex
|
57
|
+
hol
|
58
|
+
in
|
59
|
+
inver
|
60
|
+
ips
|
61
|
+
kil
|
62
|
+
kings
|
63
|
+
knock
|
64
|
+
lan
|
65
|
+
leigh
|
66
|
+
lin
|
67
|
+
lock
|
68
|
+
lon
|
69
|
+
long
|
70
|
+
lough
|
71
|
+
lyme
|
72
|
+
man
|
73
|
+
mannan
|
74
|
+
mid
|
75
|
+
middle
|
76
|
+
mills
|
77
|
+
moss
|
78
|
+
new
|
79
|
+
nor
|
80
|
+
not
|
81
|
+
oak
|
82
|
+
ock
|
83
|
+
old
|
84
|
+
pad
|
85
|
+
pen
|
86
|
+
puds
|
87
|
+
shrews
|
88
|
+
stan
|
89
|
+
stin
|
90
|
+
sud
|
91
|
+
sur
|
92
|
+
swin
|
93
|
+
tarn
|
94
|
+
thorn
|
95
|
+
tilly
|
96
|
+
tre
|
97
|
+
up
|
98
|
+
wake
|
99
|
+
wall
|
100
|
+
well
|
101
|
+
wey
|
102
|
+
which
|
103
|
+
wil
|
104
|
+
win
|
105
|
+
wor
|
106
|
+
worth
|
107
|
+
yar
|
108
|
+
)
|
109
|
+
|
110
|
+
INFIXES = %w(
|
111
|
+
beck
|
112
|
+
caster
|
113
|
+
ces
|
114
|
+
cester
|
115
|
+
cot
|
116
|
+
er
|
117
|
+
folk
|
118
|
+
ford
|
119
|
+
glen
|
120
|
+
ham
|
121
|
+
hamp
|
122
|
+
her
|
123
|
+
ill
|
124
|
+
ing
|
125
|
+
kirk
|
126
|
+
more
|
127
|
+
ness
|
128
|
+
nock
|
129
|
+
ter
|
130
|
+
tun
|
131
|
+
ton
|
132
|
+
wich
|
133
|
+
)
|
134
|
+
|
135
|
+
SUFFIXES = %w(
|
136
|
+
bie
|
137
|
+
borough
|
138
|
+
bost
|
139
|
+
born
|
140
|
+
burgh
|
141
|
+
bury
|
142
|
+
bridge
|
143
|
+
by
|
144
|
+
carden
|
145
|
+
cay
|
146
|
+
chester
|
147
|
+
church
|
148
|
+
combe
|
149
|
+
dale
|
150
|
+
deen
|
151
|
+
den
|
152
|
+
don
|
153
|
+
dun
|
154
|
+
ey
|
155
|
+
field
|
156
|
+
firth
|
157
|
+
fork
|
158
|
+
forth
|
159
|
+
frith
|
160
|
+
garth
|
161
|
+
gate
|
162
|
+
head
|
163
|
+
holm
|
164
|
+
hop
|
165
|
+
hurst
|
166
|
+
inge
|
167
|
+
keld
|
168
|
+
lan
|
169
|
+
land
|
170
|
+
law
|
171
|
+
leigh
|
172
|
+
ley
|
173
|
+
low
|
174
|
+
minster
|
175
|
+
moth
|
176
|
+
mouth
|
177
|
+
orth
|
178
|
+
over
|
179
|
+
pool
|
180
|
+
rith
|
181
|
+
rock
|
182
|
+
sbury
|
183
|
+
set
|
184
|
+
shaw
|
185
|
+
shep
|
186
|
+
ship
|
187
|
+
shire
|
188
|
+
stead
|
189
|
+
ster
|
190
|
+
stone
|
191
|
+
ter
|
192
|
+
thorp
|
193
|
+
tham
|
194
|
+
thwait
|
195
|
+
tyne
|
196
|
+
well
|
197
|
+
wich
|
198
|
+
wold
|
199
|
+
wick
|
200
|
+
)
|
201
|
+
|
202
|
+
POSTFIXES = %w(
|
203
|
+
bight
|
204
|
+
castle
|
205
|
+
crossing
|
206
|
+
downs
|
207
|
+
gate
|
208
|
+
glen
|
209
|
+
grove
|
210
|
+
hall
|
211
|
+
hamlet
|
212
|
+
-in-
|
213
|
+
marsh
|
214
|
+
of
|
215
|
+
-on-
|
216
|
+
-on-the-
|
217
|
+
river
|
218
|
+
's
|
219
|
+
sands
|
220
|
+
town
|
221
|
+
-under-
|
222
|
+
-upon-
|
223
|
+
village
|
224
|
+
water
|
225
|
+
willow
|
226
|
+
)
|
227
|
+
|
228
|
+
end
|
229
|
+
end
|
@@ -4,48 +4,75 @@ describe FakeBritishToponym do
|
|
4
4
|
|
5
5
|
MANY = 10e3.to_i
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
describe "#initialize" do
|
8
|
+
|
9
|
+
subject { FakeBritishToponym.new }
|
10
|
+
|
11
|
+
it { is_expected.to be_a String }
|
12
|
+
|
9
13
|
end
|
10
14
|
|
11
|
-
describe "options" do
|
15
|
+
describe "#initialize options" do
|
12
16
|
|
13
17
|
describe "modifier" do
|
14
|
-
|
18
|
+
|
19
|
+
describe "false" do
|
20
|
+
|
21
|
+
subject { Array.new(MANY) { FakeBritishToponym.new(modifier: false) } }
|
22
|
+
|
15
23
|
it "should never be more than one word or include punctuation" do
|
16
|
-
|
17
|
-
toponym = FakeBritishToponym.new(modifier: false)
|
24
|
+
subject.each do |toponym|
|
18
25
|
expect(toponym).to_not include " "
|
19
26
|
expect(toponym).to_not include "-"
|
20
27
|
expect(toponym).to_not include "'"
|
21
28
|
end
|
22
29
|
end
|
30
|
+
|
23
31
|
end
|
24
32
|
|
25
|
-
|
26
|
-
|
27
|
-
|
33
|
+
describe "true" do
|
34
|
+
|
35
|
+
subject { Array.new(MANY) { FakeBritishToponym.new(modifier: true) } }
|
28
36
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
expect(toponym).not_to match
|
37
|
+
it "should not have double capital letters" do
|
38
|
+
DOUBLE_CAPITAL_REGEX = /{[A-Z]{2}/
|
39
|
+
subject.each do |toponym|
|
40
|
+
expect(toponym).not_to match DOUBLE_CAPITAL_REGEX
|
33
41
|
end
|
34
|
-
|
35
|
-
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not have double punctuation/spaces" do
|
45
|
+
DOUBLE_NONALPHA_REGEX = /[^[:alpha:]]{2}/
|
46
|
+
subject.each do |toponym|
|
47
|
+
expect(toponym).not_to match DOUBLE_NONALPHA_REGEX
|
36
48
|
end
|
37
49
|
end
|
50
|
+
|
51
|
+
it "should not have invalid character sequences" do
|
52
|
+
# little redundant with the nonalpha test
|
53
|
+
subject.each do |toponym|
|
54
|
+
[" -", "- ", " '", "' "].each do |bad_char_sequence|
|
55
|
+
expect(toponym).not_to include bad_char_sequence
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
38
60
|
end
|
61
|
+
|
39
62
|
end
|
40
63
|
|
41
64
|
describe "min_syllables" do
|
65
|
+
|
66
|
+
length = rand(10)
|
67
|
+
|
68
|
+
subject { Array.new(MANY) { FakeBritishToponym.new(min_syllables: length) } }
|
69
|
+
|
42
70
|
it "should return words of roughly appropriate length" do
|
43
|
-
|
44
|
-
length = rand(10)
|
45
|
-
toponym = FakeBritishToponym.new(min_syllables: length)
|
71
|
+
subject.each do |toponym|
|
46
72
|
expect(toponym.length).to be > length * 2
|
47
73
|
end
|
48
74
|
end
|
75
|
+
|
49
76
|
end
|
50
77
|
|
51
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_british_toponym
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.1'
|
55
55
|
description: Generate place names that sound sorta British
|
56
56
|
email:
|
57
57
|
- alxndr+gem@gmail.com
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- Rakefile
|
73
73
|
- fake_british_toponym.gemspec
|
74
74
|
- lib/fake_british_toponym.rb
|
75
|
+
- lib/fake_british_toponym/corpus.rb
|
75
76
|
- lib/fake_british_toponym/version.rb
|
76
77
|
- spec/fake_british_toponym_spec.rb
|
77
78
|
- spec/spec_helper.rb
|
@@ -86,9 +87,9 @@ require_paths:
|
|
86
87
|
- lib
|
87
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
89
|
requirements:
|
89
|
-
- - "
|
90
|
+
- - "~>"
|
90
91
|
- !ruby/object:Gem::Version
|
91
|
-
version: '0'
|
92
|
+
version: '2.0'
|
92
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
94
|
requirements:
|
94
95
|
- - ">="
|