-
Notifications
You must be signed in to change notification settings - Fork 0
/
shipname.py
288 lines (273 loc) · 3.55 KB
/
shipname.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities for converting between representations of model numbers.
i.e. the number 135 corresponds to the string 000135-some-name and so on.
"""
import random
import re
import petname
import go
MODEL_NUM_REGEX = r"^\d{6}"
MODEL_NAME_REGEX = r"^\d{6}(-\w+)+"
def generate(model_num):
"""Generates a new model name, given the model number."""
if model_num == 0:
new_name = 'bootstrap'
elif go.N == 19:
new_name = random.choice(NAMES)
else:
new_name = petname.generate()
full_name = "%06d-%s" % (model_num, new_name)
return full_name
def detect_model_num(string):
"""Takes a string related to a model name and extract its model number.
For example:
'000000-bootstrap.index' => 0
"""
match = re.match(MODEL_NUM_REGEX, string)
if match:
return int(match.group())
return None
def detect_model_name(string):
"""Takes a string related to a model name and extract its model name.
For example:
'000000-bootstrap.index' => '000000-bootstrap'
"""
match = re.match(MODEL_NAME_REGEX, string)
if match:
return match.group()
return None
NAMES = """
ace
achates
acheron
achilles
aeneas
affray
agamemnon
ajax
alaric
alcide
alderney
alkmaar
alliance
ambush
amphion
anchorite
andrew
antelope
arachne
archer
ariel
artemis
artful
astute
athenienne
atlas
audacious
auriga
aurochs
batavier
belleisle
bellerophon
black-prince
brave
bulldog
bulwark
caesar
canopus
carnatic
cato
centaur
centurion
ceres
clove-tree
colossus
conqueror
constant-warwick
content
cormorant
coronation
courageux
crown
culloden
dauntless
defence
defiance
delfe
devastation
diadem
diligent
diomede
dispatch
dragon
dreadnought
druid
duchess
duke
eagle
elephant
enterprise
europa
exeter
expedition
fame
favorite
formidable
fortitude
foudroyant
fougueux
fury
ganges
gibraltar
glorieux
glory
golden-horse
golden-lion
golden-phoenix
goliath
grief
half-moon
hannibal
hastings
hawk
hawke
hazardous
hecate
hector
hercules
hero
heron
hood
hope
hotspur
hydra
icarus
illustrious
implacable
impregnable
indefatigable
indus
inflexible
intrepid
invincible
irresistible
isis
jupiter
juste
kent
kingfisher
kite
leander
leopard
leviathan
lightning
lincoln
lion
lively
lynx
magnanime
magnificent
majestic
malabar
marigold
mars
medusa
merlin
mermaid
minden
minotaur
moderate
modeste
monarch
mordaunt
namur
nassau
neptune
oberon
ocelot
odin
olympus
onslaught
onyx
opossum
opportune
oracle
orestes
orion
orpheus
osiris
otter
pallas
pandora
parthian
penelope
perseus
phoenix
portia
poseidon
prometheus
prospero
proteus
redoubtable
renown
repulse
research
resistance
revenge
robust
royal-sovereign
san-josef
san-nicolas
sans-pareil
sapphire
seagull
spartiate
sultan
superb
swift
swiftsure
temeraire
theseus
thunderer
tiger
trafalgar
tremendous
trident
triton
triumph
trusty
two-lions
tyger
unity
valiant
vanguard
venerable
vengeance
veteran
victorious
victory
vigilant
vindictive
waakzaamheid
wanderer
warrior
warspite
warwick
wasp
waterloo
wolf
zealous
zephyr
""".strip(' \t\n\r').split('\n')