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
data/lib/llt/stem.rb ADDED
@@ -0,0 +1,145 @@
1
+ require 'llt/helpers'
2
+
3
+ module LLT
4
+ class Stem
5
+ include Helpers::Initialize
6
+ include Helpers::Transformer
7
+ include Helpers::Normalizer
8
+
9
+ files = %w{ noun_stem verb_stem adjective_stem ethnic_stem
10
+ pack noun_pack verb_pack adjective_pack }
11
+ files.each do |file|
12
+ require "llt/stem/#{file}"
13
+ end
14
+
15
+ attr_reader :type, :stem
16
+
17
+ def initialize(type, args)
18
+ @type = t.send(type, :full)
19
+ extract_normalized_args!(args)
20
+ end
21
+ end
22
+ end
23
+ #class Stem
24
+ # attr_reader :stem, :metrical, :detailed_type
25
+ #
26
+ # include LLT::Helpers::Initialize
27
+ # include LLT::Helpers::Transformer
28
+ #
29
+ # # this should hold inflection type info as well
30
+ # # subclass for type
31
+ #
32
+ # def initialize(type, stem, metrical = nil, args)
33
+ # @type = type
34
+ # @stem = stem
35
+ # @metrical = metrical
36
+ # extract_args!(args)
37
+ # end
38
+ #
39
+ # def init_keys
40
+ # %i{ special_info }
41
+ # end
42
+ #
43
+ # def unicode
44
+ # @stem
45
+ # end
46
+ #
47
+ # def to_s
48
+ # "#{type_info}:\t#{stem} (#{@metrical})\t#{@special_info}"
49
+ # end
50
+ # alias :inspect :to_s
51
+ #
52
+ # def type_info
53
+ # shortened_type
54
+ # end
55
+ #
56
+ # def shortened_type
57
+ # case @type
58
+ # when :adverb then :adv
59
+ # when :conjunction then :conj
60
+ # else @type
61
+ # end
62
+ # end
63
+ #
64
+ # def type
65
+ # @type ||= self.class.name.chomp("Stem").downcase.to_sym
66
+ # end
67
+ #
68
+ # def inflectable_class_type
69
+ # @inflectable_class
70
+ # end
71
+ #end
72
+ #
73
+ #class ComplexStem < Stem
74
+ # def init_keys
75
+ # super + %i{ inflectable_class }
76
+ # end
77
+ #
78
+ # def type_info
79
+ # "#{super} #{inflectable_class_type} #{additional_stem_info}"
80
+ # end
81
+ #end
82
+ #
83
+ #class VerbStem < ComplexStem
84
+ # # what happens when a lemma has two different stems? it infl class right, even for perfstems?
85
+ # def init_keys
86
+ # super + %i{ tense deponens }
87
+ # end
88
+ #
89
+ # def additional_stem_info
90
+ # @tense
91
+ # end
92
+ #
93
+ # def type_info
94
+ # super + (@deponens ? " #{dep_status}" : "")
95
+ # end
96
+ #
97
+ # def dep_status
98
+ # "dep".green if @deponens
99
+ # end
100
+ #end
101
+ #
102
+ ##class NounStem < ComplexStem
103
+ ## def init_keys
104
+ ## super + %i{ sexus } # nominative?
105
+ ## end
106
+ ##
107
+ ## def additional_stem_info
108
+ ## @sexus
109
+ ## end
110
+ ##
111
+ ## def inflectable_class_type
112
+ ## case @inflectable_class
113
+ ## when 1 then "A"
114
+ ## when 2 then "O"
115
+ ## when 3 then "C"
116
+ ## when 31 then
117
+ ## when 32 then
118
+ ## when 33 then
119
+ ## when 4 then "U"
120
+ ## when 5 then "E"
121
+ ## end
122
+ ## end
123
+ ##end
124
+ #
125
+ #class AdjectiveStem < ComplexStem
126
+ # def init_keys
127
+ # super + %i{ number_of_endings }
128
+ # end
129
+ #
130
+ # def additional_stem_info
131
+ # @number_of_endings
132
+ # end
133
+ #
134
+ # def shortened_type
135
+ # :adj
136
+ # end
137
+ #
138
+ # def inflectable_class_type
139
+ # case @inflectable_class
140
+ # when 1 then "A/O"
141
+ # when 3 then "Third"
142
+ # when 5 then "Pronominal"
143
+ # end
144
+ # end
145
+ #end
@@ -0,0 +1,53 @@
1
+ require 'llt/stem'
2
+ require 'llt/helpers/constantize'
3
+
4
+ module LLT
5
+ class StemBuilder
6
+ extend Helpers::Constantize
7
+
8
+ def self.build(type, args, source)
9
+ type = parse_type_and_extend_args(type, args)
10
+ pre = complex_stems.include?(type) ? type : ""
11
+ cl = constant_by_type(:pack, prefix: pre, namespace: LLT::Stem)
12
+ cl.new(type, args, source)
13
+ end
14
+
15
+ private
16
+
17
+ def self.complex_stems
18
+ %i{ noun adjective verb }
19
+ end
20
+
21
+ def self.parse_type_and_extend_args(type, args)
22
+ if type == :persona || type == :place
23
+ add_to_args(type, args)
24
+ :noun
25
+ else
26
+ type
27
+ end
28
+ end
29
+
30
+ def self.add_to_args(type, args)
31
+ args[type] = true
32
+ end
33
+
34
+ def self.pack_factory(args)
35
+ build(:verb, args, 'llt')
36
+ end
37
+
38
+ # TODO 02.10.13 16:07 by LFDM
39
+ # Fill in the string values of the various stems
40
+
41
+ # edo deliberately left out atm...
42
+ IRREGULAR_STEMS = {
43
+ esse: pack_factory(pr: "e/s/es/er", pf: "fu", inflection_class: :esse),
44
+ posse: pack_factory(pr: "pos/pot", pf: "potu", inflection_class: :posse),
45
+ ferre: pack_factory(pr: "fer", pf: "tul", ppp: "lat", inflection_class: :ferre),
46
+ fieri: pack_factory(pr: "fi", inflection_class: :fieri),
47
+ ire: pack_factory(pr: "", pf: "", ppp: "", inflection_class: :ire),
48
+ velle: pack_factory(pr: "", pf: "volu", inflection_class: :velle),
49
+ nolle: pack_factory(pr: "", pf: "nolu", inflection_class: :nolle),
50
+ malle: pack_factory(pr: "", pf: "malu", inflection_class: :malle),
51
+ }
52
+ end
53
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'llt/form_builder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "llt-form_builder"
8
+ spec.version = LLT::FormBuilder::VERSION
9
+ spec.authors = ["LFDM", "lichtr"]
10
+ spec.email = ["1986gh@gmail.com", "robert.lichtensteiner@gmail.com"]
11
+ spec.description = %q{Builds valid Latin forms of given stems}
12
+ spec.summary = %q{#{spec.description}}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "simplecov", "~> 0.7"
25
+ spec.add_development_dependency "blunt_stub_factory"
26
+ spec.add_development_dependency "yard"
27
+ spec.add_dependency "llt-constants"
28
+ spec.add_dependency "llt-core_extensions"
29
+ spec.add_dependency "llt-helpers"
30
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Adjective do
4
+ let(:adj) { LLT::Form::Adjective.new({}) }
5
+
6
+ it "has functions adjective and substantive" do
7
+ adj.has_f?(:adjective).should be_true
8
+ adj.has_f?(:substantive).should be_true
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Adverb do
4
+ describe "#string" do
5
+ it "returns the string value" do
6
+ adv = LLT::Form::Adverb.new(string: 'semper')
7
+ adv.string.should == 'semper'
8
+ end
9
+ end
10
+
11
+ describe "#stem" do
12
+ it "is an alias for string" do
13
+ adv = LLT::Form::Adverb.new(string: 'semper')
14
+ adv.stem.should == 'semper'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Conjunction do
4
+ let(:conj) { LLT::Form::Conjunction.new(string: 'et') }
5
+
6
+ describe "#string" do
7
+ it "returns the string value" do
8
+ conj.string.should == 'et'
9
+ end
10
+ end
11
+
12
+ describe "#stem" do
13
+ it "is an alias to string" do
14
+ conj.stem.should == 'et'
15
+ end
16
+ end
17
+
18
+ describe "#lemma" do
19
+ it "is another alias for string" do
20
+ conj.lemma.should == 'et'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::DemonstrativePronoun do
4
+ let(:dem_pron) { LLT::Form::DemonstrativePronoun.new({}) }
5
+
6
+ it "has function demonstrative_pronoun" do
7
+ dem_pron.has_f?(:demonstrative_pronoun).should be_true
8
+ end
9
+
10
+ it "includes its inflection_class in its functions" do
11
+ dem_pron.instance_variable_set('@inflection_class', :hic)
12
+ dem_pron.has_f?(:hic).should be_true
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Fp do
4
+ let(:fp) { LLT::Form::Fp.new({}) }
5
+
6
+ it "has functions fp, substantive, adjective and participle" do
7
+ fp.has_f?(:fp).should be_true
8
+ fp.has_f?(:substantive).should be_true
9
+ fp.has_f?(:adjective).should be_true
10
+ fp.has_f?(:participle).should be_true
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Verb do
4
+ describe "#init_function" do
5
+ it "returns the correct initial functions of a verb" do
6
+ pending
7
+ options = { ending: "i" }
8
+ args = [{type: :perfectum, stem: "amav", inflection_class: 1, options: options}]
9
+ verb = LLT::FormBuilder.build(*args).first
10
+ verb.init_function.should == [:verb]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Gerund do
4
+ let(:gerund) { LLT::Form::Gerund.new({}) }
5
+
6
+ it "has functions gerund, substantive" do
7
+ gerund.has_f?(:gerund).should be_true
8
+ gerund.has_f?(:substantive).should be_true
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Gerundive do
4
+ let(:gerundive) { LLT::Form::Gerundive.new({}) }
5
+
6
+ it "has function gerundive" do
7
+ gerundive.has_f?(:gerundive).should be_true
8
+ end
9
+
10
+ it "has function substantive - to play the role of a dominant participle" do
11
+ gerundive.has_f?(:substantive).should be_true
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Noun do
4
+ let(:noun) { LLT::Form::Noun.new({}) }
5
+
6
+ it "has functions noun and substantive" do
7
+ noun.has_f?(:noun).should be_true
8
+ noun.has_f?(:substantive).should be_true
9
+ end
10
+
11
+ describe "#stems=" do
12
+ it "sets a noun's stems" do
13
+ dummy = double
14
+ noun.stems = dummy
15
+ noun.stems.should == dummy
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Ppa do
4
+ let(:ppa) { LLT::Form::Ppa.new({}) }
5
+
6
+ it "has functions ppa, substantive, adjective and participle" do
7
+ ppa.has_f?(:ppa).should be_true
8
+ ppa.has_f?(:substantive).should be_true
9
+ ppa.has_f?(:adjective).should be_true
10
+ ppa.has_f?(:participle).should be_true
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Ppp do
4
+ let(:ppp) { LLT::Form::Ppp.new({}) }
5
+
6
+ it "has functions ppp, substantive, adjective and participle" do
7
+ ppp.has_f?(:ppp).should be_true
8
+ ppp.has_f?(:substantive).should be_true
9
+ ppp.has_f?(:adjective).should be_true
10
+ ppp.has_f?(:participle).should be_true
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Preposition do
4
+ describe "#takes_4th?" do
5
+ it "returns true if an acc is taken" do
6
+ args = { string: 'super', takes_4th: true, takes_6th: false }
7
+ prep = LLT::Form::Preposition.new(args)
8
+ prep.takes_4th?.should be_true
9
+ end
10
+ end
11
+
12
+ describe "#takes_6th?" do
13
+ it "returns true if an abl is taken" do
14
+ args = { string: 'ex', takes_4th: false, takes_6th: true }
15
+ prep = LLT::Form::Preposition.new(args)
16
+ prep.takes_6th?.should be_true
17
+ end
18
+ end
19
+
20
+ describe "#string" do
21
+ it "returns the string value" do
22
+ args = { string: 'ex', takes_4th: false, takes_6th: true }
23
+ prep = LLT::Form::Preposition.new(args)
24
+ prep.string.should == 'ex'
25
+ end
26
+ end
27
+
28
+ describe "#stem" do
29
+ it "is an alias for string" do
30
+ args = { string: 'ex', takes_4th: false, takes_6th: true }
31
+ prep = LLT::Form::Preposition.new(args)
32
+ prep.stem.should == 'ex'
33
+ end
34
+ end
35
+
36
+ describe "#lemma" do
37
+ it "is another alias for string" do
38
+ args = { string: 'ex', takes_4th: false, takes_6th: true }
39
+ prep = LLT::Form::Preposition.new(args)
40
+ prep.lemma.should == 'ex'
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Supinum do
4
+ let(:supinum) { LLT::Form::Supinum.new({}) }
5
+
6
+ it "has function supinum" do
7
+ supinum.has_f?(:supinum).should be_true
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::Form::Verb do
4
+ let(:verb) { LLT::Form::Verb.new({}) }
5
+
6
+ it "has function verb" do
7
+ verb.has_f?(:verb)
8
+ end
9
+
10
+ it "has a function named after its conjugation with irregular verbs" do
11
+ verb.instance_variable_set('@inflection_class', :esse)
12
+ verb.has_f?(:esse).should be_true
13
+ end
14
+ end
@@ -0,0 +1,182 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::FormBuilder do
4
+ include LLT::Helpers::Normalizer
5
+
6
+ describe ".build" do
7
+ def form_builder_strings(args)
8
+ forms = LLT::FormBuilder.build(*args)
9
+ forms.map(&:to_s)
10
+ end
11
+
12
+ def with_adjective(options)
13
+ args = [{type: :adjective, nominative: "atrox", stem: "atroc", inflection_class: 3,
14
+ number_of_endings: 1, comparatio: :positivus, options: options}]
15
+ LLT::FormBuilder.build(*args)
16
+ end
17
+
18
+ context "with adjectives" do
19
+ context "without options" do
20
+ it "builds all forms of A/O" do
21
+ args = [{type: :adjective, stem: "amic", inflection_class: 1, number_of_endings: 3, comparatio: :positivus}]
22
+ form_builder_strings(args).should == %w{amicus amici amico amicum amice amico amici amicorum amicis amicos amici amicis
23
+ amica amicae amicae amicam amica amica amicae amicarum amicis amicas amicae amicis
24
+ amicum amici amico amicum amicum amico amica amicorum amicis amica amica amicis
25
+ amice}
26
+ end
27
+
28
+ it "gets casus, numerus and sexus right" do
29
+ args = [{type: :adjective, stem: "amic", inflection_class: 1, number_of_endings: 3, comparatio: :positivus}]
30
+ forms = LLT::FormBuilder.build(*args)
31
+ amicus = forms[ 0]
32
+ amico = forms[ 5]
33
+ amicam = forms[15]
34
+ amica_n = forms[30]
35
+
36
+ amicus.casus.should == 1
37
+ amicus.numerus.should == 1
38
+ amicus.sexus.should == :m
39
+
40
+ amico.casus.should == 6
41
+ amico.numerus.should == 1
42
+ amico.sexus.should == :m
43
+
44
+ amicam.casus.should == 4
45
+ amicam.numerus.should == 1
46
+ amicam.sexus.should == :f
47
+
48
+ amica_n.casus.should == 1
49
+ amica_n.numerus.should == 2
50
+ amica_n.sexus.should == :n
51
+ end
52
+
53
+ it "builds all forms of A/O like pulcher" do
54
+ args = [{type: :adjective, nominative: "pulcher", stem: "pulchr", inflection_class: 1, number_of_endings: 3, comparatio: :positivus}]
55
+ form_builder_strings(args).should ==%w{pulcher pulchri pulchro pulchrum pulcher pulchro pulchri pulchrorum pulchris pulchros pulchri pulchris
56
+ pulchra pulchrae pulchrae pulchram pulchra pulchra pulchrae pulchrarum pulchris pulchras pulchrae pulchris
57
+ pulchrum pulchri pulchro pulchrum pulchrum pulchro pulchra pulchrorum pulchris pulchra pulchra pulchris
58
+ pulchre}
59
+ end
60
+
61
+ it "builds all forms of Third with 1 endings" do
62
+ args = [{type: :adjective, nominative: "atrox", stem: "atroc", inflection_class: 3, number_of_endings: 1, comparatio: :positivus}]
63
+ form_builder_strings(args).should == %w{atrox atrocis atroci atrocem atrox atroci atroces atrocium atrocibus atroces atroces atrocibus
64
+ atrox atrocis atroci atrocem atrox atroci atroces atrocium atrocibus atroces atroces atrocibus
65
+ atrox atrocis atroci atrox atrox atroci atrocia atrocium atrocibus atrocia atrocia atrocibus
66
+ atrociter}
67
+ end
68
+
69
+ it "builds all forms of Third with 2 endings" do
70
+ args = [{type: :adjective, nominative: "facilis", stem: "facil", inflection_class: 3, number_of_endings: 2, comparatio: :positivus}]
71
+ form_builder_strings(args).should == %w{facilis facilis facili facilem facilis facili faciles facilium facilibus faciles faciles facilibus
72
+ facilis facilis facili facilem facilis facili faciles facilium facilibus faciles faciles facilibus
73
+ facile facilis facili facile facile facili facilia facilium facilibus facilia facilia facilibus
74
+ facile}
75
+ end
76
+
77
+ it "builds all forms of Third with 3 endings" do
78
+ args = [{type: :adjective, nominative: "celer", stem: "celer", inflection_class: 3, number_of_endings: 3, comparatio: :positivus}]
79
+ form_builder_strings(args).should == %w{celer celeris celeri celerem celer celeri celeres celerium celeribus celeres celeres celeribus
80
+ celeris celeris celeri celerem celeris celeri celeres celerium celeribus celeres celeres celeribus
81
+ celere celeris celeri celere celere celeri celeria celerium celeribus celeria celeria celeribus
82
+ celeriter}
83
+ end
84
+
85
+ it "builds all forms of Pronominal" do
86
+ args = [{type: :adjective, nominative: "totus", stem: "tot", inflection_class: 5, number_of_endings: 3, comparatio: :positivus}]
87
+ form_builder_strings(args).should == %w{totus totius toti totum tote toto toti totorum totis totos toti totis
88
+ tota totius toti totam tota tota totae totarum totis totas totae totis
89
+ totum totius toti totum totum toto tota totorum totis tota tota totis
90
+ tote} # is tote even a form?
91
+ end
92
+
93
+ it "builds all forms of comparativus stems" do
94
+ args = [{type: :adjective, stem: "altior", inflection_class: 1, number_of_endings: 3, comparatio: :comparativus}]
95
+ form_builder_strings(args).should == %w{altior altioris altiori altiorem altior altiore altiores altiorum altioribus altiores altiores altioribus
96
+ altior altioris altiori altiorem altior altiore altiores altiorum altioribus altiores altiores altioribus
97
+ altius altioris altiori altius altius altiore altiora altiorum altioribus altiora altiora altioribus
98
+ altius}
99
+ end
100
+
101
+ it "knows the comparison sign for comparatives" do
102
+ args = [{type: :adjective, stem: "altior", inflection_class: 1, number_of_endings: 3, comparatio: :comparativus}]
103
+ forms = LLT::FormBuilder.build(*args)
104
+ altioris = forms[1]
105
+ altioris.comparison_sign.should == "ior"
106
+ end
107
+
108
+ it "buids all forms of superlativus stems" do
109
+ args = [{type: :adjective, stem: "altissim", inflection_class: 1, number_of_endings: 3, comparatio: :superlativus}]
110
+ form_builder_strings(args).should == %w{altissimus altissimi altissimo altissimum altissime altissimo altissimi altissimorum altissimis altissimos altissimi altissimis
111
+ altissima altissimae altissimae altissimam altissima altissima altissimae altissimarum altissimis altissimas altissimae altissimis
112
+ altissimum altissimi altissimo altissimum altissimum altissimo altissima altissimorum altissimis altissima altissima altissimis
113
+ altissime}
114
+ end
115
+
116
+ it "knows the comparison sign for superlatives" do
117
+ args = [{type: :adjective, stem: "altissim", inflection_class: 1, number_of_endings: 3, comparatio: :superlativus}]
118
+ forms = LLT::FormBuilder.build(*args)
119
+ altissimi = forms[1]
120
+ altissimi.comparison_sign.should == "issim"
121
+ end
122
+
123
+ it "handles metrical stems" do
124
+ args = [{type: :adjective, stem: "altīssīm", inflection_class: 1, number_of_endings: 3, comparatio: :superlativus}]
125
+ forms = LLT::FormBuilder.build(*args)
126
+ altissimi = forms[1]
127
+ altissimi.comparison_sign.should == "īssīm"
128
+ end
129
+ end
130
+
131
+ context "with options that select a specfic form given in a stem" do
132
+ it "returns only forms specified in options" do
133
+ options = { sexus: :f }
134
+ res = with_adjective(options)
135
+ res.should have(12).items
136
+ end
137
+ end
138
+
139
+ context "with options that indicate the word's components" do
140
+ it "builds correct forms only (several possibilities)" do
141
+ res = with_adjective(ending: "is")
142
+ res2 = with_adjective(ending: "ibus")
143
+ res .should have(3).items
144
+ res2.should have(6).items
145
+ end
146
+
147
+ it "builds correct forms only with nominative" do
148
+ res = with_adjective(ending: "")
149
+ res.should have(7).items
150
+ end
151
+
152
+ it "doesn't build incorrect forms" do
153
+ res = with_adjective(ending: "orum")
154
+ res.should be_empty
155
+ end
156
+
157
+ it "builds correct forms of improviso" do
158
+ opts = { ending: "o", validate: true }
159
+ args = {type: :adjective, stem: "improvis", nom: "improvisus", inflection_class: 1, noe: 3, comparatio: :positivus, options: opts}
160
+ LLT::FormBuilder.build(args).should have(4).item
161
+ end
162
+
163
+ it "builds correct forms of noster" do
164
+ opts = { ending: "", validate: true }
165
+ args = { type: :adjective, stem: "nostr", nom: "noster", inflection_class: 1, noe: 3, comparatio: :positivus, options: opts}
166
+ forms = LLT::FormBuilder.build(args)
167
+ forms.should have(2).items
168
+ nom, voc = forms
169
+ nom.casus.should == 1
170
+ voc.casus.should == 5
171
+ end
172
+
173
+ it "builds correct forms of laete (vocative and adverb)" do
174
+ opts = { ending: "e", validate: true }
175
+ args = { type: :adjective, nom: "laetus", stem: "laet", inflection_class: 1, number_of_endings: 3, options: opts }
176
+ forms = LLT::FormBuilder.build(args)
177
+ forms.should have(2).items
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::FormBuilder do
4
+ describe ".build" do
5
+ it "builds the correct adverb form - positivus" do
6
+ args = { type: :adverb, comparatio: :positivus, stem: "alt", inflection_class: 1 }
7
+ forms = LLT::FormBuilder.build(args)
8
+ forms.should have(1).item
9
+ forms.first.to_s(:segmentized).should == "alt-e"
10
+ end
11
+
12
+ it "builds the correct adverb form - comparativus" do
13
+ args = { type: :adverb, comparatio: :comparativus, stem: "altius", inflection_class: 1 }
14
+ forms = LLT::FormBuilder.build(args)
15
+ forms.should have(1).item
16
+ forms.first.to_s(:segmentized).should == "alt-ius"
17
+ end
18
+
19
+ it "builds the correct adverb form - superlativus" do
20
+ args = { type: :adverb, comparatio: :superlativus, stem: "altissim", inflection_class: 1 }
21
+ forms = LLT::FormBuilder.build(args)
22
+ forms.should have(1).item
23
+ forms.first.to_s(:segmentized).should == "alt-issim-e"
24
+ end
25
+ end
26
+
27
+ end