llt-form_builder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +8 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +8 -0
  9. data/lib/llt/form/adjective.rb +19 -0
  10. data/lib/llt/form/adverb.rb +13 -0
  11. data/lib/llt/form/cardinal.rb +31 -0
  12. data/lib/llt/form/conjunction.rb +7 -0
  13. data/lib/llt/form/declinable.rb +23 -0
  14. data/lib/llt/form/demonstrative_pronoun.rb +7 -0
  15. data/lib/llt/form/ethnic.rb +6 -0
  16. data/lib/llt/form/fp.rb +6 -0
  17. data/lib/llt/form/gerund.rb +9 -0
  18. data/lib/llt/form/gerundive.rb +12 -0
  19. data/lib/llt/form/indefinite_pronoun.rb +7 -0
  20. data/lib/llt/form/infinitive.rb +13 -0
  21. data/lib/llt/form/interrogative_pronoun.rb +7 -0
  22. data/lib/llt/form/noun.rb +17 -0
  23. data/lib/llt/form/participle.rb +9 -0
  24. data/lib/llt/form/personal_pronoun.rb +13 -0
  25. data/lib/llt/form/ppa.rb +6 -0
  26. data/lib/llt/form/ppp.rb +6 -0
  27. data/lib/llt/form/preposition.rb +32 -0
  28. data/lib/llt/form/pronoun.rb +17 -0
  29. data/lib/llt/form/relative_pronoun.rb +7 -0
  30. data/lib/llt/form/subjunction.rb +7 -0
  31. data/lib/llt/form/supinum.rb +6 -0
  32. data/lib/llt/form/uninflectable.rb +22 -0
  33. data/lib/llt/form/verb.rb +28 -0
  34. data/lib/llt/form/verbal_noun.rb +18 -0
  35. data/lib/llt/form.rb +80 -0
  36. data/lib/llt/form_builder/adjective_builder.rb +86 -0
  37. data/lib/llt/form_builder/adverb_builder.rb +25 -0
  38. data/lib/llt/form_builder/declinable_builder.rb +164 -0
  39. data/lib/llt/form_builder/ethnic_builder.rb +17 -0
  40. data/lib/llt/form_builder/fp_builder.rb +13 -0
  41. data/lib/llt/form_builder/gerund_builder.rb +37 -0
  42. data/lib/llt/form_builder/gerundive_builder.rb +24 -0
  43. data/lib/llt/form_builder/helpers/adjective_like_building.rb +29 -0
  44. data/lib/llt/form_builder/helpers/pronoun_segments.rb +226 -0
  45. data/lib/llt/form_builder/helpers/stem_hash_parser.rb +263 -0
  46. data/lib/llt/form_builder/helpers/verb_segments.rb +562 -0
  47. data/lib/llt/form_builder/infinitivum_builder.rb +19 -0
  48. data/lib/llt/form_builder/irregular_gerund_builder.rb +7 -0
  49. data/lib/llt/form_builder/irregular_gerundive_builder.rb +7 -0
  50. data/lib/llt/form_builder/irregular_ppa_builder.rb +7 -0
  51. data/lib/llt/form_builder/irregular_praesens_builder.rb +5 -0
  52. data/lib/llt/form_builder/irregular_praesens_infinitivum_builder.rb +5 -0
  53. data/lib/llt/form_builder/noun_builder.rb +24 -0
  54. data/lib/llt/form_builder/perfectum_builder.rb +14 -0
  55. data/lib/llt/form_builder/perfectum_infinitivum_builder.rb +7 -0
  56. data/lib/llt/form_builder/personal_pronoun_builder.rb +107 -0
  57. data/lib/llt/form_builder/ppa_builder.rb +20 -0
  58. data/lib/llt/form_builder/ppp_builder.rb +10 -0
  59. data/lib/llt/form_builder/praesens_builder.rb +41 -0
  60. data/lib/llt/form_builder/praesens_infinitivum_builder.rb +9 -0
  61. data/lib/llt/form_builder/pronoun_builder.rb +106 -0
  62. data/lib/llt/form_builder/supinum_builder.rb +23 -0
  63. data/lib/llt/form_builder/verb_builder.rb +37 -0
  64. data/lib/llt/form_builder/version.rb +5 -0
  65. data/lib/llt/form_builder.rb +370 -0
  66. data/lib/llt/stem/adjective_pack.rb +122 -0
  67. data/lib/llt/stem/adjective_stem.rb +23 -0
  68. data/lib/llt/stem/ethnic_stem.rb +9 -0
  69. data/lib/llt/stem/noun_pack.rb +14 -0
  70. data/lib/llt/stem/noun_stem.rb +26 -0
  71. data/lib/llt/stem/pack.rb +46 -0
  72. data/lib/llt/stem/verb_pack.rb +53 -0
  73. data/lib/llt/stem/verb_stem.rb +18 -0
  74. data/lib/llt/stem.rb +145 -0
  75. data/lib/llt/stem_builder.rb +53 -0
  76. data/llt-form_builder.gemspec +30 -0
  77. data/spec/lib/llt/form/adjective_spec.rb +10 -0
  78. data/spec/lib/llt/form/adverb_spec.rb +17 -0
  79. data/spec/lib/llt/form/conjunction_spec.rb +23 -0
  80. data/spec/lib/llt/form/demonstrative_pronoun_spec.rb +14 -0
  81. data/spec/lib/llt/form/fp_spec.rb +12 -0
  82. data/spec/lib/llt/form/functions_spec.rb +13 -0
  83. data/spec/lib/llt/form/gerund_spec.rb +10 -0
  84. data/spec/lib/llt/form/gerundive_spec.rb +13 -0
  85. data/spec/lib/llt/form/noun_spec.rb +18 -0
  86. data/spec/lib/llt/form/ppa_spec.rb +12 -0
  87. data/spec/lib/llt/form/ppp_spec.rb +12 -0
  88. data/spec/lib/llt/form/preposition_spec.rb +43 -0
  89. data/spec/lib/llt/form/supinum_spec.rb +9 -0
  90. data/spec/lib/llt/form/verb_spec.rb +14 -0
  91. data/spec/lib/llt/form_builder/adjective_builder_spec.rb +182 -0
  92. data/spec/lib/llt/form_builder/adverb_builder_spec.rb +27 -0
  93. data/spec/lib/llt/form_builder/ethnic_builder_spec.rb +17 -0
  94. data/spec/lib/llt/form_builder/form_builder_spec.rb +16 -0
  95. data/spec/lib/llt/form_builder/fp_builder_spec.rb +42 -0
  96. data/spec/lib/llt/form_builder/gerund_builder_spec.rb +80 -0
  97. data/spec/lib/llt/form_builder/gerundive_builder_spec.rb +102 -0
  98. data/spec/lib/llt/form_builder/helpers/stem_hash_parser_spec.rb +197 -0
  99. data/spec/lib/llt/form_builder/irregular_gerund_builder_spec.rb +22 -0
  100. data/spec/lib/llt/form_builder/irregular_gerundive_builder_spec.rb +21 -0
  101. data/spec/lib/llt/form_builder/irregular_praesens_builder_spec.rb +14 -0
  102. data/spec/lib/llt/form_builder/irregular_praesens_infinitivum_builder_spec.rb +32 -0
  103. data/spec/lib/llt/form_builder/noun_builder_spec.rb +245 -0
  104. data/spec/lib/llt/form_builder/personal_pronoun_builder_spec.rb +49 -0
  105. data/spec/lib/llt/form_builder/ppa_builder_spec.rb +137 -0
  106. data/spec/lib/llt/form_builder/ppp_builder_spec.rb +45 -0
  107. data/spec/lib/llt/form_builder/pronoun_builder_spec.rb +203 -0
  108. data/spec/lib/llt/form_builder/supinum_builder_spec.rb +24 -0
  109. data/spec/lib/llt/form_builder/verb_builder_spec.rb +557 -0
  110. data/spec/lib/llt/form_spec.rb +27 -0
  111. data/spec/lib/llt/stem/adjective_pack_spec.rb +78 -0
  112. data/spec/lib/llt/stem/adjective_stem_spec.rb +15 -0
  113. data/spec/lib/llt/stem/noun_pack_spec.rb +20 -0
  114. data/spec/lib/llt/stem/noun_stem_spec.rb +14 -0
  115. data/spec/lib/llt/stem/verb_pack_spec.rb +56 -0
  116. data/spec/lib/llt/stem_builder_spec.rb +20 -0
  117. data/spec/spec_helper.rb +21 -0
  118. metadata +330 -0
@@ -0,0 +1,107 @@
1
+ module LLT
2
+ class PersonalPronounBuilder < DeclinableBuilder
3
+ endings_defined_through :inflection_class
4
+
5
+ validate :suffix
6
+
7
+ def indices
8
+ {
9
+ casus: [0, 1, 2, 3, nil, 5],
10
+ numerus: [0, 6],
11
+ }
12
+ end
13
+
14
+ def compute
15
+ (regular_forms + forms_with_suffix + additional_genetives).sort_by(&:index)
16
+ end
17
+
18
+ def forms
19
+ endings
20
+ end
21
+
22
+ def forms_with_suffix
23
+ suffixeds = SUFFIXED_FORMS[@inflection_class]
24
+ res = []
25
+ return res unless suffixeds
26
+ suffixeds.each do |i, suffixes|
27
+ if @lookup_indices.include?(i)
28
+ suffixes.each do |suffix|
29
+ f = forms[i]
30
+ res << new_form_through_index(f, i, suffix)
31
+ end
32
+ end
33
+ end
34
+ res.flatten.compact
35
+ end
36
+
37
+ def additional_genetives
38
+ if nos_or_vos && @lookup_indices.include?(7) # gen.pl
39
+ [new_form_through_index("#{@inflection_class}trum", 7)]
40
+ else
41
+ []
42
+ end
43
+ end
44
+
45
+ def nos_or_vos
46
+ @inflection_class == :nos || @inflection_class == :vos
47
+ end
48
+
49
+ def new_form_through_index(form, i, suffix = "")
50
+ # nil values in ending == form present, vocatives f.e., or se in nom.
51
+ return unless form
52
+ c, n = casus_numerus_sexus_by_index(i)
53
+ new_form(stem: form, casus: c, numerus: n, suffix: suffix, index: i)
54
+ end
55
+
56
+ def default_args
57
+ # need to override, because we want to use our custom "stem", which is actually the form itself
58
+ { inflection_class: @inflection_class }
59
+ end
60
+
61
+
62
+ private
63
+
64
+ def self.compute_suffixed_forms
65
+ hash = container
66
+ # arrays are styled as casus, numerus, suffix
67
+ # 0: cum, 1: met, 2: te, 3: se
68
+ suffixes = %w{ cum met te se }
69
+ # -cum
70
+ hash[:ego] << [6,1,0]
71
+ hash[:tu] << [6,1,0]
72
+ hash[:se] << [6,1,0] << [6,2,0]
73
+ hash[:nos] << [6,2,0]
74
+ hash[:vos] << [6,2,0]
75
+ # -met
76
+ hash[:ego] << [1,1,1] << [2,1,1] << [3,1,1] << [4,1,1] << [6,1,1]
77
+ hash[:nos] << [1,2,1] << [3,2,1] << [4,2,1] << [6,2,1]
78
+ hash[:vos] << [1,2,1] << [3,2,1] << [4,2,1] << [6,2,1]
79
+ hash[:tu] << [3,1,1]
80
+ # -te
81
+ hash[:tu] << [1,1,2] << [4,1,2] << [6,1,2]
82
+ # -se
83
+ hash[:se] << [4,1,3] << [6,1,3] << [4,2,3] << [6,2,3]
84
+
85
+
86
+ res = {}
87
+ hash.each do |key, values|
88
+ h = container
89
+ values.each do |casus, numerus, suffix|
90
+ h[ioe(casus, numerus)] << suffixes[suffix]
91
+ end
92
+ res[key] = h
93
+ end
94
+ res
95
+ end
96
+
97
+ def self.ioe(casus, numerus)
98
+ casus + (numerus == 1 ? -1 : 5)
99
+ end
100
+
101
+ def self.container
102
+ Hash.new { |h, k| h[k] = [] }
103
+ end
104
+
105
+ SUFFIXED_FORMS = compute_suffixed_forms
106
+ end
107
+ end
@@ -0,0 +1,20 @@
1
+ module LLT
2
+ class PpaBuilder < DeclinableBuilder
3
+ builds_like_an :adjective
4
+ builds_with :modus, :tempus, :extension, :genus
5
+
6
+ has_extension "nt"
7
+ has_modus t.participium
8
+ has_tempus t.praesens
9
+ has_genus t.activum
10
+
11
+ look_up :thematic
12
+ validate :extension
13
+
14
+ def corrections(args)
15
+ if args[:ending] == "s"
16
+ args[:extension] = args[:extension].chop
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ module LLT
2
+ class PppBuilder < DeclinableBuilder
3
+ builds_like_an :adjective
4
+ builds_with :modus, :tempus, :genus, :prefix
5
+
6
+ has_modus t.participium
7
+ has_tempus t.perfectum
8
+ has_genus t.passivum
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ module LLT
2
+ class PraesensBuilder < VerbBuilder
3
+ endings_defined_through :inflection_class
4
+
5
+ look_up :thematic, :extension
6
+
7
+ def indices
8
+ { persona: persona_index,
9
+ numerus: [0, 3],
10
+ genus: genus_index,
11
+ modus: [0, 12, 24],
12
+ tempus: [0, 36, 72]
13
+ }
14
+ end
15
+
16
+ def indices_by_ending(ending)
17
+ indices = super
18
+ if @deponens
19
+ PASSIVE_INDICES & indices
20
+ else
21
+ indices
22
+ end
23
+ end
24
+
25
+
26
+ def self.passive_indices
27
+ # build all possible indices, slice them according to their genus, select only even ones,
28
+ # i.e. the passive endings
29
+ (0..107).each_slice(6).each_with_index.each_with_object([]) { |(e, i), r| r << e if i.odd? }.flatten
30
+ end
31
+ PASSIVE_INDICES = passive_indices
32
+
33
+ def corrections(args)
34
+ if args[:inflection_class] == 1
35
+ if args[:tempus] == t.pr && (args[:modus] == t.con || args[:ending].match(/or?$/))
36
+ args[:stem] = args[:stem].chop
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ module LLT
2
+ class PraesensInfinitivumBuilder < InfinitivumBuilder
3
+ endings_defined_through :inflection_class
4
+
5
+ def indices
6
+ super.merge(tempus: [0])
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,106 @@
1
+ module LLT
2
+ class PronounBuilder < DeclinableBuilder
3
+ builds_like_an :adjective
4
+ lookup_class PronounSegments
5
+ look_up :stem, :particle, :prefixed_particle
6
+
7
+ endings_defined_through :inflection_class
8
+
9
+ validate :suffix # quibuscum etc.
10
+
11
+ def indices
12
+ { casus: [0, 1, 2, 3, nil, 5],
13
+ numerus: [0, 6],
14
+ sexus: [0, 12, 24] }
15
+ end
16
+
17
+ def compute
18
+ (regular_forms + forms_with_suffix).sort_by(&:index) # quibuscum etc.
19
+ end
20
+
21
+ def init_keys
22
+ %i{ type inflection_class }
23
+ end
24
+
25
+ def default_args
26
+ { inflection_class: @inflection_class }
27
+ end
28
+
29
+ def endings_lookup(ending, x)
30
+ if ending == "s" && is_or_idem
31
+ x.to_s =~ /^i?s$/
32
+ elsif ending == "ic"
33
+ x.to_s == "id"
34
+ else
35
+ super
36
+ end
37
+ end
38
+ #quo quibus qua quibus quo quibus
39
+ INDICES_OF_CUM_WITH_QUI = [5, 11, 17, 23, 29, 35]
40
+ def forms_with_suffix
41
+ if @inflection_class == :qui
42
+ indices = INDICES_OF_CUM_WITH_QUI & @lookup_indices
43
+ indices.map { |i| [endings[i], i] }.map do |ending, i|
44
+ casus, numerus, sexus = casus_numerus_sexus_by_index(i)
45
+ ending = ending.to_s
46
+ new_form(ending: ending, casus: casus, numerus: numerus, sexus: sexus, index: i, suffix: "cum")
47
+ end.compact # for forms that don't make it through validation
48
+ else
49
+ []
50
+ end
51
+ end
52
+
53
+ def corrections(args)
54
+ if @options[:ending] == "ic"
55
+ keep_given_value(args, :ending)
56
+ end
57
+
58
+ super
59
+ end
60
+
61
+ # Allows i and e stem for specific forms like ii/ei.
62
+ # If such a form is detected return the validation,
63
+ # in every other case use the default rule.
64
+ def validation_rule(args, validator)
65
+ if is_or_idem
66
+ case validator
67
+ when :stem
68
+ c, n, s = %i{ casus numerus sexus }.map { |k| args[k] }
69
+
70
+ if n == 2 && ((c == 1 && s == :m) || (c == 3 || c == 6))
71
+ val_values = [args[validator], @options[validator]]
72
+ if val_values.all? { |stem| stem =~ /^[ei]$/ }
73
+ keep_given_value(args, validator)
74
+ # also keep the ending to catch is, iis and eis
75
+ keep_given_value(args, :ending)
76
+ return true # to prevent the super call
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ super
83
+ end
84
+
85
+ def is_or_idem
86
+ @inflection_class == :is || @inflection_class == :idem
87
+ end
88
+
89
+ pt = {
90
+ demonstrative_pronoun: %i{ hic is idem iste ipse ille },
91
+ relative_pronoun: %i{ qui quicumque quisquis },
92
+ indefinite_pronoun: %i{ aliqui quilibet quivis quis aliquis
93
+ quisquam quisque quisque_s quidam quinam
94
+ unusquisque unusquisque_s uterque quispiam },
95
+ interrogative_pronoun: %i{ uter }
96
+ }
97
+
98
+ PRON_TYPE = pt.each_with_object({}) do |(type, infl_classes), h|
99
+ infl_classes.each { |infl_cl| h[infl_cl] = type }
100
+ end
101
+
102
+ def form_class
103
+ constant_by_type(PRON_TYPE[@inflection_class], namespace: LLT::Form)
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,23 @@
1
+ module LLT
2
+ class SupinumBuilder < DeclinableBuilder
3
+ builds_with :modus
4
+ has_modus t.supinum
5
+
6
+ def index_of_ending(casus, numerus, sexus = nil)
7
+ case casus
8
+ when 3 then 0
9
+ when 4 then 1
10
+ when 6 then 2
11
+ end
12
+ end
13
+ alias :ioe :index_of_ending
14
+
15
+ def casus_numerus_sexus_by_index(index, sexus = nil)
16
+ case index
17
+ when 0 then [3, 1, :n]
18
+ when 1 then [4, 1, :n]
19
+ when 2 then [6, 1, :n]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ module LLT
2
+ class VerbBuilder < FormBuilder
3
+ builds_with :impersonalium, :contraction, :prefix
4
+
5
+ form_class :verb
6
+
7
+ look_up :thematic, :extension
8
+
9
+ def persona_index
10
+ @impersonalium ? [nil, nil, 2] : [0, 1, 2]
11
+ end
12
+
13
+ def genus_index
14
+ @deponens ? [6] : [0, 6]
15
+ end
16
+
17
+ def regular_forms
18
+ endings.each_with_index.map do |ending, i|
19
+ next unless (@lookup_indices.include?(i) && ending) # nil values in verb endings are escaped
20
+ new_form_through_index(ending, i)
21
+ end.compact
22
+ end
23
+
24
+ def new_form_through_index(ending, i)
25
+ p, n, g, m, t = attributes_by_index(i)
26
+ new_form(ending: ending, persona: p, numerus: n, tempus: t, modus: m, genus: g, index: i)
27
+ end
28
+
29
+ def contraction
30
+ @options[:contraction]
31
+ end
32
+
33
+ def endings_namespace
34
+ super::Verb
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module LLT
2
+ class FormBuilder
3
+ VERSION = "0.0.1"
4
+ end
5
+ end