llt-form_builder 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/lib/llt/form/adjective.rb +19 -0
- data/lib/llt/form/adverb.rb +13 -0
- data/lib/llt/form/cardinal.rb +31 -0
- data/lib/llt/form/conjunction.rb +7 -0
- data/lib/llt/form/declinable.rb +23 -0
- data/lib/llt/form/demonstrative_pronoun.rb +7 -0
- data/lib/llt/form/ethnic.rb +6 -0
- data/lib/llt/form/fp.rb +6 -0
- data/lib/llt/form/gerund.rb +9 -0
- data/lib/llt/form/gerundive.rb +12 -0
- data/lib/llt/form/indefinite_pronoun.rb +7 -0
- data/lib/llt/form/infinitive.rb +13 -0
- data/lib/llt/form/interrogative_pronoun.rb +7 -0
- data/lib/llt/form/noun.rb +17 -0
- data/lib/llt/form/participle.rb +9 -0
- data/lib/llt/form/personal_pronoun.rb +13 -0
- data/lib/llt/form/ppa.rb +6 -0
- data/lib/llt/form/ppp.rb +6 -0
- data/lib/llt/form/preposition.rb +32 -0
- data/lib/llt/form/pronoun.rb +17 -0
- data/lib/llt/form/relative_pronoun.rb +7 -0
- data/lib/llt/form/subjunction.rb +7 -0
- data/lib/llt/form/supinum.rb +6 -0
- data/lib/llt/form/uninflectable.rb +22 -0
- data/lib/llt/form/verb.rb +28 -0
- data/lib/llt/form/verbal_noun.rb +18 -0
- data/lib/llt/form.rb +80 -0
- data/lib/llt/form_builder/adjective_builder.rb +86 -0
- data/lib/llt/form_builder/adverb_builder.rb +25 -0
- data/lib/llt/form_builder/declinable_builder.rb +164 -0
- data/lib/llt/form_builder/ethnic_builder.rb +17 -0
- data/lib/llt/form_builder/fp_builder.rb +13 -0
- data/lib/llt/form_builder/gerund_builder.rb +37 -0
- data/lib/llt/form_builder/gerundive_builder.rb +24 -0
- data/lib/llt/form_builder/helpers/adjective_like_building.rb +29 -0
- data/lib/llt/form_builder/helpers/pronoun_segments.rb +226 -0
- data/lib/llt/form_builder/helpers/stem_hash_parser.rb +263 -0
- data/lib/llt/form_builder/helpers/verb_segments.rb +562 -0
- data/lib/llt/form_builder/infinitivum_builder.rb +19 -0
- data/lib/llt/form_builder/irregular_gerund_builder.rb +7 -0
- data/lib/llt/form_builder/irregular_gerundive_builder.rb +7 -0
- data/lib/llt/form_builder/irregular_ppa_builder.rb +7 -0
- data/lib/llt/form_builder/irregular_praesens_builder.rb +5 -0
- data/lib/llt/form_builder/irregular_praesens_infinitivum_builder.rb +5 -0
- data/lib/llt/form_builder/noun_builder.rb +24 -0
- data/lib/llt/form_builder/perfectum_builder.rb +14 -0
- data/lib/llt/form_builder/perfectum_infinitivum_builder.rb +7 -0
- data/lib/llt/form_builder/personal_pronoun_builder.rb +107 -0
- data/lib/llt/form_builder/ppa_builder.rb +20 -0
- data/lib/llt/form_builder/ppp_builder.rb +10 -0
- data/lib/llt/form_builder/praesens_builder.rb +41 -0
- data/lib/llt/form_builder/praesens_infinitivum_builder.rb +9 -0
- data/lib/llt/form_builder/pronoun_builder.rb +106 -0
- data/lib/llt/form_builder/supinum_builder.rb +23 -0
- data/lib/llt/form_builder/verb_builder.rb +37 -0
- data/lib/llt/form_builder/version.rb +5 -0
- data/lib/llt/form_builder.rb +370 -0
- data/lib/llt/stem/adjective_pack.rb +122 -0
- data/lib/llt/stem/adjective_stem.rb +23 -0
- data/lib/llt/stem/ethnic_stem.rb +9 -0
- data/lib/llt/stem/noun_pack.rb +14 -0
- data/lib/llt/stem/noun_stem.rb +26 -0
- data/lib/llt/stem/pack.rb +46 -0
- data/lib/llt/stem/verb_pack.rb +53 -0
- data/lib/llt/stem/verb_stem.rb +18 -0
- data/lib/llt/stem.rb +145 -0
- data/lib/llt/stem_builder.rb +53 -0
- data/llt-form_builder.gemspec +30 -0
- data/spec/lib/llt/form/adjective_spec.rb +10 -0
- data/spec/lib/llt/form/adverb_spec.rb +17 -0
- data/spec/lib/llt/form/conjunction_spec.rb +23 -0
- data/spec/lib/llt/form/demonstrative_pronoun_spec.rb +14 -0
- data/spec/lib/llt/form/fp_spec.rb +12 -0
- data/spec/lib/llt/form/functions_spec.rb +13 -0
- data/spec/lib/llt/form/gerund_spec.rb +10 -0
- data/spec/lib/llt/form/gerundive_spec.rb +13 -0
- data/spec/lib/llt/form/noun_spec.rb +18 -0
- data/spec/lib/llt/form/ppa_spec.rb +12 -0
- data/spec/lib/llt/form/ppp_spec.rb +12 -0
- data/spec/lib/llt/form/preposition_spec.rb +43 -0
- data/spec/lib/llt/form/supinum_spec.rb +9 -0
- data/spec/lib/llt/form/verb_spec.rb +14 -0
- data/spec/lib/llt/form_builder/adjective_builder_spec.rb +182 -0
- data/spec/lib/llt/form_builder/adverb_builder_spec.rb +27 -0
- data/spec/lib/llt/form_builder/ethnic_builder_spec.rb +17 -0
- data/spec/lib/llt/form_builder/form_builder_spec.rb +16 -0
- data/spec/lib/llt/form_builder/fp_builder_spec.rb +42 -0
- data/spec/lib/llt/form_builder/gerund_builder_spec.rb +80 -0
- data/spec/lib/llt/form_builder/gerundive_builder_spec.rb +102 -0
- data/spec/lib/llt/form_builder/helpers/stem_hash_parser_spec.rb +197 -0
- data/spec/lib/llt/form_builder/irregular_gerund_builder_spec.rb +22 -0
- data/spec/lib/llt/form_builder/irregular_gerundive_builder_spec.rb +21 -0
- data/spec/lib/llt/form_builder/irregular_praesens_builder_spec.rb +14 -0
- data/spec/lib/llt/form_builder/irregular_praesens_infinitivum_builder_spec.rb +32 -0
- data/spec/lib/llt/form_builder/noun_builder_spec.rb +245 -0
- data/spec/lib/llt/form_builder/personal_pronoun_builder_spec.rb +49 -0
- data/spec/lib/llt/form_builder/ppa_builder_spec.rb +137 -0
- data/spec/lib/llt/form_builder/ppp_builder_spec.rb +45 -0
- data/spec/lib/llt/form_builder/pronoun_builder_spec.rb +203 -0
- data/spec/lib/llt/form_builder/supinum_builder_spec.rb +24 -0
- data/spec/lib/llt/form_builder/verb_builder_spec.rb +557 -0
- data/spec/lib/llt/form_spec.rb +27 -0
- data/spec/lib/llt/stem/adjective_pack_spec.rb +78 -0
- data/spec/lib/llt/stem/adjective_stem_spec.rb +15 -0
- data/spec/lib/llt/stem/noun_pack_spec.rb +20 -0
- data/spec/lib/llt/stem/noun_stem_spec.rb +14 -0
- data/spec/lib/llt/stem/verb_pack_spec.rb +56 -0
- data/spec/lib/llt/stem_builder_spec.rb +20 -0
- data/spec/spec_helper.rb +21 -0
- metadata +330 -0
@@ -0,0 +1,263 @@
|
|
1
|
+
module LLT
|
2
|
+
class FormBuilder
|
3
|
+
class StemHashParser
|
4
|
+
|
5
|
+
include Helpers::Normalizer
|
6
|
+
|
7
|
+
def initialize(stem_hashes)
|
8
|
+
@stem_hashes = stem_hashes.map { |h| normalize_args(h) }
|
9
|
+
@result = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse
|
13
|
+
@stem_hashes.each do |hash|
|
14
|
+
@hash = hash
|
15
|
+
@opts = hash[:options]
|
16
|
+
|
17
|
+
m = "#{type}_changes"
|
18
|
+
if respond_to?(m)
|
19
|
+
send(m)
|
20
|
+
else
|
21
|
+
add_unchanged
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
@result
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
####### Praesens Changes #######
|
30
|
+
|
31
|
+
def praesens_changes
|
32
|
+
verbal_changes do |ext, m, tmp|
|
33
|
+
parse_verb(:extension, ext)
|
34
|
+
parse_verb(:mood, m)
|
35
|
+
|
36
|
+
default_verbal_types(m, ext, tmp)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
####### Perfectum Changes #######
|
41
|
+
|
42
|
+
def perfectum_changes
|
43
|
+
verbal_changes do |ext, m, tmp|
|
44
|
+
parse_verb(:mood, m)
|
45
|
+
parse_verb(:extension, ext)
|
46
|
+
|
47
|
+
default_verbal_types(m, ext, tmp)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
####### PPP Changes #######
|
53
|
+
|
54
|
+
def ppp_changes
|
55
|
+
verbal_changes do |ext, m, tmp|
|
56
|
+
parse_verb(:extension, ext)
|
57
|
+
parse_verb(:mood, m)
|
58
|
+
parse_verb(:tempus, tmp)
|
59
|
+
|
60
|
+
add_with_new_type(*verb_defaults) unless m || ext || tmp
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
####### Adjective Changes #######
|
65
|
+
|
66
|
+
def adjective_changes
|
67
|
+
add_unchanged
|
68
|
+
unless irregular_adverb_building? || invalid_options?
|
69
|
+
stem = comparativus? ? adapted_stem : @hash[:stem]
|
70
|
+
add(@hash.merge(stem: stem, type: :adverb)) unless irregular_adverb_building?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def adapted_stem
|
75
|
+
@hash[:stem].sub(/ior$/, "ius")
|
76
|
+
end
|
77
|
+
|
78
|
+
def irregular_adverb_building?
|
79
|
+
@hash[:irregular_adverb]
|
80
|
+
end
|
81
|
+
|
82
|
+
def comparativus?
|
83
|
+
@hash[:comparatio] == :comparativus
|
84
|
+
end
|
85
|
+
|
86
|
+
def invalid_options?
|
87
|
+
if @opts
|
88
|
+
@opts[:sexus] || @opts[:numerus] || @opts[:casus]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
######### Pronoun Changes #########
|
94
|
+
|
95
|
+
def pronoun_changes
|
96
|
+
if kind_of_quisque && @opts[:ending] == "is"
|
97
|
+
# whether quisque or quisque_s arrive - always return both
|
98
|
+
base_infl = inflection_class.to_s.match(/([a-z]+)_?/)[1]
|
99
|
+
types = [base_infl, base_infl + "_s"].map(&:to_sym)
|
100
|
+
add_with_new_inflection_class(*types)
|
101
|
+
else
|
102
|
+
add_unchanged
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def kind_of_quisque
|
107
|
+
/quisque/ =~ inflection_class
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
####### General Helper #######
|
112
|
+
|
113
|
+
def type
|
114
|
+
@hash[:type]
|
115
|
+
end
|
116
|
+
|
117
|
+
def inflection_class
|
118
|
+
@hash[:inflection_class]
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_with_new_type(*types)
|
122
|
+
types.each do |type|
|
123
|
+
@result << @hash.merge(type: type)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def add_with_new_inflection_class(*infl_classes)
|
128
|
+
infl_classes.each do |infl_cl|
|
129
|
+
@result << @hash.merge(inflection_class: infl_cl)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def add(hash)
|
134
|
+
@result << hash
|
135
|
+
end
|
136
|
+
|
137
|
+
def add_unchanged
|
138
|
+
@result << @hash
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
####### Verb Helpers #######
|
143
|
+
|
144
|
+
def verbal_changes
|
145
|
+
if @opts
|
146
|
+
yield(*attributes)
|
147
|
+
else
|
148
|
+
add_with_new_type(*verb_defaults)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def attributes
|
153
|
+
%i{ extension modus tempus }.map { |attr| @opts[attr] }
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def verb_defaults
|
158
|
+
send("#{type}_defaults")
|
159
|
+
end
|
160
|
+
|
161
|
+
def irregular_verb?
|
162
|
+
@hash[:inflection_class].kind_of?(Symbol) # all irregulars are given as symbol, regulars come as Fixnum
|
163
|
+
end
|
164
|
+
|
165
|
+
IRE_DEFAULTS = %i{ irregular_praesens irregular_praesens_infinitivum irregular_ppa irregular_gerund irregular_gerundive }
|
166
|
+
FERRE_DEFAULTS = %i{ irregular_praesens irregular_praesens_infinitivum ppa gerund gerundive }
|
167
|
+
OTHER_DEFAULTS = %i{ irregular_praesens irregular_praesens_infinitivum }
|
168
|
+
REG_DEFAULTS = %i{ praesens praesens_infinitivum ppa gerund gerundive }
|
169
|
+
def praesens_defaults
|
170
|
+
if irregular_verb?
|
171
|
+
case @hash[:inflection_class]
|
172
|
+
when :ire then IRE_DEFAULTS
|
173
|
+
when :ferre then FERRE_DEFAULTS
|
174
|
+
else OTHER_DEFAULTS
|
175
|
+
end
|
176
|
+
else
|
177
|
+
REG_DEFAULTS
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
PERF_DEFAULTS = %i{ perfectum perfectum_infinitivum }
|
182
|
+
def perfectum_defaults
|
183
|
+
PERF_DEFAULTS
|
184
|
+
end
|
185
|
+
|
186
|
+
PPP_DEFAULTS = %i{ ppp fp supinum }
|
187
|
+
def ppp_defaults
|
188
|
+
PPP_DEFAULTS
|
189
|
+
end
|
190
|
+
|
191
|
+
def default_verbal_types(m, ext, tmp)
|
192
|
+
unless m || ext
|
193
|
+
if tmp || @opts[:finite]
|
194
|
+
add_with_new_type(verb_defaults.first) # praesens or perfectum
|
195
|
+
else
|
196
|
+
add_with_new_type(*verb_defaults)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def parse_verb(category, var)
|
202
|
+
return unless var
|
203
|
+
add_with_new_type(*send("#{category}_mapping", var))
|
204
|
+
end
|
205
|
+
|
206
|
+
def extension_mapping(ext)
|
207
|
+
case ext
|
208
|
+
when "nd" then [:gerund, :gerundive]
|
209
|
+
when /^nt?$/ then :ppa
|
210
|
+
when "ur" then :fp
|
211
|
+
else orig_type
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def mood_mapping(mood)
|
216
|
+
case type
|
217
|
+
when :praesens
|
218
|
+
case mood
|
219
|
+
when mood_term(:participle) then :ppa
|
220
|
+
when mood_term(:infinitive) then :praesens_infinitivum
|
221
|
+
when mood_term(:gerund) then :gerund
|
222
|
+
when mood_term(:gerundive) then :gerundive
|
223
|
+
else orig_type
|
224
|
+
end
|
225
|
+
when :perfectum
|
226
|
+
case mood
|
227
|
+
when mood_term(:infinitive) then :perfectum_infinitivum
|
228
|
+
else type
|
229
|
+
end
|
230
|
+
when :ppp
|
231
|
+
case mood
|
232
|
+
when mood_term(:participle) then [:ppp, :fp]
|
233
|
+
when mood_term(:supinum) then :supinum
|
234
|
+
else type
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def mood_term(val)
|
240
|
+
t.value_term_for(:modus, val)
|
241
|
+
end
|
242
|
+
|
243
|
+
def tempus_mapping(tmp)
|
244
|
+
# more to come, especially for praesens stem probably (ppa? gerundive?)
|
245
|
+
case type
|
246
|
+
when :ppp
|
247
|
+
case tmp
|
248
|
+
when t.fut then :fp
|
249
|
+
when t.pf then :ppp
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def orig_type
|
255
|
+
if irregular_verb?
|
256
|
+
verb_defaults.find { |default| default.match(/#{type}$/) }
|
257
|
+
else
|
258
|
+
type
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|