回答編集履歴
11
修正
test
CHANGED
File without changes
|
10
修正
test
CHANGED
@@ -128,7 +128,7 @@
|
|
128
128
|
|
129
129
|
'opuses' => 'opus',
|
130
130
|
|
131
|
-
'penises'
|
131
|
+
'penises' => 'penis',
|
132
132
|
|
133
133
|
'equipment' => 'equipment',
|
134
134
|
|
9
修正
test
CHANGED
@@ -198,7 +198,7 @@
|
|
198
198
|
|
199
199
|
'(^analy)ses$' => '\1sis',
|
200
200
|
|
201
|
-
'(analy|ba|diagno|parenthe|progno|synop|the)ses$'
|
201
|
+
'(analy|ba|diagno|parenthe|progno|synop|the)ses$' => '\1sis',
|
202
202
|
|
203
203
|
'([ti])a$' => '\1um',
|
204
204
|
|
8
修正
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
def singularize
|
62
62
|
|
63
|
-
P2S.
|
63
|
+
P2S.singular_by_plural(self)
|
64
64
|
|
65
65
|
end
|
66
66
|
|
@@ -74,7 +74,7 @@
|
|
74
74
|
|
75
75
|
|
76
76
|
|
77
|
-
@
|
77
|
+
@irregular_rules = {
|
78
78
|
|
79
79
|
'men' => 'man',
|
80
80
|
|
@@ -156,7 +156,7 @@
|
|
156
156
|
|
157
157
|
|
158
158
|
|
159
|
-
@
|
159
|
+
@singular_rules = {
|
160
160
|
|
161
161
|
'(quiz)zes$' => '\1',
|
162
162
|
|
@@ -210,19 +210,15 @@
|
|
210
210
|
|
211
211
|
|
212
212
|
|
213
|
-
def singular
|
213
|
+
def self.singular_by_plural(prural)
|
214
|
-
|
214
|
+
|
215
|
-
return @
|
215
|
+
return @irregular_rules[prural] if @irregular_rules.key?(prural)
|
216
|
-
|
217
|
-
|
218
|
-
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
-
@
|
219
|
+
@singular_rules.each do |key, value|
|
220
|
-
|
221
|
-
|
220
|
+
|
222
|
-
|
223
|
-
|
221
|
+
return prural.sub(/#{key}/, value) if prural =~ /#{key}/
|
224
|
-
|
225
|
-
end
|
226
222
|
|
227
223
|
end
|
228
224
|
|
7
修正
test
CHANGED
@@ -228,7 +228,7 @@
|
|
228
228
|
|
229
229
|
|
230
230
|
|
231
|
-
|
231
|
+
nil
|
232
232
|
|
233
233
|
end
|
234
234
|
|
6
修正
test
CHANGED
@@ -236,7 +236,7 @@
|
|
236
236
|
|
237
237
|
|
238
238
|
|
239
|
-
puts 'computer'.singularize # => computer
|
239
|
+
puts 'computers'.singularize # => computer
|
240
240
|
|
241
241
|
|
242
242
|
|
5
修正
test
CHANGED
@@ -236,7 +236,7 @@
|
|
236
236
|
|
237
237
|
|
238
238
|
|
239
|
-
puts 'pr
|
239
|
+
puts 'computer'.singularize # => computer
|
240
240
|
|
241
241
|
|
242
242
|
|
4
修正
test
CHANGED
@@ -78,75 +78,75 @@
|
|
78
78
|
|
79
79
|
'men' => 'man',
|
80
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
|
-
|
81
|
+
'seamen' => 'seaman',
|
82
|
+
|
83
|
+
'snowmen' => 'snowman',
|
84
|
+
|
85
|
+
'women' => 'woman',
|
86
|
+
|
87
|
+
'people' => 'person',
|
88
|
+
|
89
|
+
'children' => 'child',
|
90
|
+
|
91
|
+
'sexes' => 'sex',
|
92
|
+
|
93
|
+
'moves' => 'move',
|
94
|
+
|
95
|
+
'databases' => 'database',
|
96
|
+
|
97
|
+
'feet' => 'foot',
|
98
|
+
|
99
|
+
'cruces' => 'crux',
|
100
|
+
|
101
|
+
'oases' => 'oasis',
|
102
|
+
|
103
|
+
'phenomena' => 'phenomenon',
|
104
|
+
|
105
|
+
'teeth' => 'tooth',
|
106
|
+
|
107
|
+
'geese' => 'goose',
|
108
|
+
|
109
|
+
'atlases' => 'atlas',
|
110
|
+
|
111
|
+
'corpuses' => 'corpus',
|
112
|
+
|
113
|
+
'genies' => 'genie',
|
114
|
+
|
115
|
+
'genera' => 'genus',
|
116
|
+
|
117
|
+
'graffiti' => 'graffito',
|
118
|
+
|
119
|
+
'loaves' => 'loaf',
|
120
|
+
|
121
|
+
'mythoi' => 'mythos',
|
122
|
+
|
123
|
+
'niches' => 'niche',
|
124
|
+
|
125
|
+
'numina' => 'numen',
|
126
|
+
|
127
|
+
'octopuses' => 'octopus',
|
128
|
+
|
129
|
+
'opuses' => 'opus',
|
130
|
+
|
131
|
+
'penises' => 'penis',
|
132
|
+
|
133
|
+
'equipment' => 'equipment',
|
134
|
+
|
135
|
+
'information' => 'information',
|
136
|
+
|
137
|
+
'rice' => 'rice',
|
138
|
+
|
139
|
+
'money' => 'money',
|
140
|
+
|
141
|
+
'species' => 'species',
|
142
|
+
|
143
|
+
'series' => 'series',
|
144
|
+
|
145
|
+
'fish' => 'fish',
|
146
|
+
|
147
|
+
'sheep' => 'sheep',
|
148
|
+
|
149
|
+
'swiss' => 'swiss',
|
150
150
|
|
151
151
|
'progress' => 'progress',
|
152
152
|
|
@@ -158,53 +158,53 @@
|
|
158
158
|
|
159
159
|
@@singular_rules = {
|
160
160
|
|
161
|
-
|
161
|
+
'(quiz)zes$' => '\1',
|
162
|
-
|
162
|
+
|
163
|
-
|
163
|
+
'(matr)ices$' => '\1ix',
|
164
|
-
|
164
|
+
|
165
|
-
|
165
|
+
'(vert|ind)ices$' => '\1ex',
|
166
|
-
|
166
|
+
|
167
|
-
|
167
|
+
'^(ox)en' => '\1',
|
168
|
-
|
168
|
+
|
169
|
-
|
169
|
+
'(alias|status)es$' => '\1',
|
170
|
-
|
170
|
+
|
171
|
-
|
171
|
+
'(octop|vir)i$' => '\1us',
|
172
|
-
|
172
|
+
|
173
|
-
|
173
|
+
'(cris|ax|test)es$' => '\1is',
|
174
|
-
|
174
|
+
|
175
|
-
|
175
|
+
'(shoe)s$' => '\1',
|
176
|
-
|
176
|
+
|
177
|
-
|
177
|
+
'(o)es$' => '\1',
|
178
|
-
|
178
|
+
|
179
|
-
|
179
|
+
'(bus)es$' => '\1',
|
180
|
-
|
180
|
+
|
181
|
-
|
181
|
+
'([m|l])ice$' => '\1ouse',
|
182
|
-
|
182
|
+
|
183
|
-
|
183
|
+
'(x|ch|ss|sh)es$' => '\1',
|
184
|
-
|
184
|
+
|
185
|
-
|
185
|
+
'movies$' => 'movie',
|
186
|
-
|
186
|
+
|
187
|
-
|
187
|
+
'series$' => 'series',
|
188
|
-
|
188
|
+
|
189
|
-
|
189
|
+
'([^aeiouy]|qu)ies$' => '\1y',
|
190
|
-
|
190
|
+
|
191
|
-
|
191
|
+
'([lr])ves$' => '\1f',
|
192
|
-
|
192
|
+
|
193
|
-
|
193
|
+
'(tive)s$' => '\1',
|
194
|
-
|
194
|
+
|
195
|
-
|
195
|
+
'(hive)s$' => '\1',
|
196
|
-
|
196
|
+
|
197
|
-
|
197
|
+
'([^f])ves$' => '\1fe',
|
198
|
-
|
198
|
+
|
199
|
-
|
199
|
+
'(^analy)ses$' => '\1sis',
|
200
|
-
|
200
|
+
|
201
|
-
|
201
|
+
'(analy|ba|diagno|parenthe|progno|synop|the)ses$' => '\1sis',
|
202
|
-
|
202
|
+
|
203
|
-
|
203
|
+
'([ti])a$' => '\1um',
|
204
|
-
|
204
|
+
|
205
|
-
|
205
|
+
'(n)ews$' => '\1ews',
|
206
|
-
|
206
|
+
|
207
|
-
|
207
|
+
'(.)s$' => '\1'
|
208
208
|
|
209
209
|
}.freeze
|
210
210
|
|
@@ -236,7 +236,9 @@
|
|
236
236
|
|
237
237
|
|
238
238
|
|
239
|
-
puts '
|
239
|
+
puts 'progress'.singularize # => computer
|
240
|
+
|
241
|
+
|
240
242
|
|
241
243
|
```
|
242
244
|
|
3
修正
test
CHANGED
@@ -146,7 +146,11 @@
|
|
146
146
|
|
147
147
|
'sheep' => 'sheep',
|
148
148
|
|
149
|
-
'swiss' => 'swiss'
|
149
|
+
'swiss' => 'swiss',
|
150
|
+
|
151
|
+
'progress' => 'progress',
|
152
|
+
|
153
|
+
'nonsense' => 'nonsense'
|
150
154
|
|
151
155
|
}.freeze
|
152
156
|
|
@@ -232,7 +236,7 @@
|
|
232
236
|
|
233
237
|
|
234
238
|
|
235
|
-
p 'computers'.singularize # =>
|
239
|
+
puts 'computers'.singularize # => computer
|
236
240
|
|
237
241
|
```
|
238
242
|
|
@@ -241,3 +245,7 @@
|
|
241
245
|
[【まとめ】インスタンス変数、クラス変数、クラスインスタンス変数](http://qiita.com/mogulla3/items/cd4d6e188c34c6819709)
|
242
246
|
|
243
247
|
[Rubyで逆ポーランド記法の計算機と変換器を作った](http://qiita.com/siman/items/d72854c4c4aaaf452868)
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
progressとnonsenseは追加しました。
|
2
修正
test
CHANGED
@@ -46,4 +46,198 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
|
49
|
+
[PHP 複数形を単数形に変換 - サンプルコード](http://pb-times.jp/P_527b395742f17)
|
50
|
+
|
51
|
+
こちらのページに書いてあるコードをRubyに書き換えてみました。
|
52
|
+
|
53
|
+
```Ruby
|
54
|
+
|
55
|
+
# encoding: utf-8
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
class String
|
60
|
+
|
61
|
+
def singularize
|
62
|
+
|
63
|
+
P2S.new.singularByPlural(self)
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
class P2S
|
72
|
+
|
73
|
+
attr_reader :word
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
@@irregular_rules = {
|
78
|
+
|
79
|
+
'men' => 'man',
|
80
|
+
|
81
|
+
'seamen' => 'seaman',
|
82
|
+
|
83
|
+
'snowmen' => 'snowman',
|
84
|
+
|
85
|
+
'women' => 'woman',
|
86
|
+
|
87
|
+
'people' => 'person',
|
88
|
+
|
89
|
+
'children' => 'child',
|
90
|
+
|
91
|
+
'sexes' => 'sex',
|
92
|
+
|
93
|
+
'moves' => 'move',
|
94
|
+
|
95
|
+
'databases' => 'database',
|
96
|
+
|
97
|
+
'feet' => 'foot',
|
98
|
+
|
99
|
+
'cruces' => 'crux',
|
100
|
+
|
101
|
+
'oases' => 'oasis',
|
102
|
+
|
103
|
+
'phenomena' => 'phenomenon',
|
104
|
+
|
105
|
+
'teeth' => 'tooth',
|
106
|
+
|
107
|
+
'geese' => 'goose',
|
108
|
+
|
109
|
+
'atlases' => 'atlas',
|
110
|
+
|
111
|
+
'corpuses' => 'corpus',
|
112
|
+
|
113
|
+
'genies' => 'genie',
|
114
|
+
|
115
|
+
'genera' => 'genus',
|
116
|
+
|
117
|
+
'graffiti' => 'graffito',
|
118
|
+
|
119
|
+
'loaves' => 'loaf',
|
120
|
+
|
121
|
+
'mythoi' => 'mythos',
|
122
|
+
|
123
|
+
'niches' => 'niche',
|
124
|
+
|
125
|
+
'numina' => 'numen',
|
126
|
+
|
127
|
+
'octopuses' => 'octopus',
|
128
|
+
|
129
|
+
'opuses' => 'opus',
|
130
|
+
|
131
|
+
'penises' => 'penis',
|
132
|
+
|
133
|
+
'equipment' => 'equipment',
|
134
|
+
|
135
|
+
'information' => 'information',
|
136
|
+
|
137
|
+
'rice' => 'rice',
|
138
|
+
|
139
|
+
'money' => 'money',
|
140
|
+
|
141
|
+
'species' => 'species',
|
142
|
+
|
143
|
+
'series' => 'series',
|
144
|
+
|
145
|
+
'fish' => 'fish',
|
146
|
+
|
147
|
+
'sheep' => 'sheep',
|
148
|
+
|
149
|
+
'swiss' => 'swiss'
|
150
|
+
|
151
|
+
}.freeze
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
@@singular_rules = {
|
156
|
+
|
157
|
+
'(quiz)zes$' => '\1',
|
158
|
+
|
159
|
+
'(matr)ices$' => '\1ix',
|
160
|
+
|
161
|
+
'(vert|ind)ices$' => '\1ex',
|
162
|
+
|
163
|
+
'^(ox)en' => '\1',
|
164
|
+
|
165
|
+
'(alias|status)es$' => '\1',
|
166
|
+
|
167
|
+
'(octop|vir)i$' => '\1us',
|
168
|
+
|
169
|
+
'(cris|ax|test)es$' => '\1is',
|
170
|
+
|
171
|
+
'(shoe)s$' => '\1',
|
172
|
+
|
173
|
+
'(o)es$' => '\1',
|
174
|
+
|
175
|
+
'(bus)es$' => '\1',
|
176
|
+
|
177
|
+
'([m|l])ice$' => '\1ouse',
|
178
|
+
|
179
|
+
'(x|ch|ss|sh)es$' => '\1',
|
180
|
+
|
181
|
+
'movies$' => 'movie',
|
182
|
+
|
183
|
+
'series$' => 'series',
|
184
|
+
|
185
|
+
'([^aeiouy]|qu)ies$' => '\1y',
|
186
|
+
|
187
|
+
'([lr])ves$' => '\1f',
|
188
|
+
|
189
|
+
'(tive)s$' => '\1',
|
190
|
+
|
191
|
+
'(hive)s$' => '\1',
|
192
|
+
|
193
|
+
'([^f])ves$' => '\1fe',
|
194
|
+
|
195
|
+
'(^analy)ses$' => '\1sis',
|
196
|
+
|
197
|
+
'(analy|ba|diagno|parenthe|progno|synop|the)ses$' => '\1sis',
|
198
|
+
|
199
|
+
'([ti])a$' => '\1um',
|
200
|
+
|
201
|
+
'(n)ews$' => '\1ews',
|
202
|
+
|
203
|
+
'(.)s$' => '\1'
|
204
|
+
|
205
|
+
}.freeze
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
def singularByPlural(prural)
|
210
|
+
|
211
|
+
return @@irregular_rules[prural] if @@irregular_rules.key?(prural)
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
@@singular_rules.each do |key, value|
|
216
|
+
|
217
|
+
if prural =~ /#{key}/
|
218
|
+
|
219
|
+
return prural.sub(/#{key}/, value)
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
'Not found'
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
p 'computers'.singularize # => "computer"
|
236
|
+
|
237
|
+
```
|
238
|
+
|
239
|
+
参考にしたページ
|
240
|
+
|
241
|
+
[【まとめ】インスタンス変数、クラス変数、クラスインスタンス変数](http://qiita.com/mogulla3/items/cd4d6e188c34c6819709)
|
242
|
+
|
243
|
+
[Rubyで逆ポーランド記法の計算機と変換器を作った](http://qiita.com/siman/items/d72854c4c4aaaf452868)
|
1
修正
test
CHANGED
@@ -37,3 +37,13 @@
|
|
37
37
|
どうかわかりませんがRuby単体には存在しない
|
38
38
|
|
39
39
|
機能なのではないかなぁと私は予想しています。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
私のRubyのバージョンなど
|
44
|
+
|
45
|
+
Ruby 2.2.6 Windows32bit版
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|