lingo 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.rspec +1 -0
  2. data/COPYING +663 -0
  3. data/ChangeLog +754 -0
  4. data/README +322 -0
  5. data/Rakefile +100 -0
  6. data/TODO +28 -0
  7. data/bin/lingo +5 -0
  8. data/bin/lingoctl +6 -0
  9. data/de.lang +121 -0
  10. data/de/lingo-abk.txt +74 -0
  11. data/de/lingo-dic.txt +56822 -0
  12. data/de/lingo-mul.txt +3209 -0
  13. data/de/lingo-syn.txt +14841 -0
  14. data/de/test_dic.txt +24 -0
  15. data/de/test_mul.txt +17 -0
  16. data/de/test_mul2.txt +2 -0
  17. data/de/test_singleword.txt +2 -0
  18. data/de/test_syn.txt +4 -0
  19. data/de/test_syn2.txt +1 -0
  20. data/de/user-dic.txt +10 -0
  21. data/en.lang +113 -0
  22. data/en/lingo-dic.txt +55434 -0
  23. data/en/lingo-mul.txt +456 -0
  24. data/en/user-dic.txt +5 -0
  25. data/info/Objekte.png +0 -0
  26. data/info/Typen.png +0 -0
  27. data/info/database.png +0 -0
  28. data/info/db_small.png +0 -0
  29. data/info/download.png +0 -0
  30. data/info/gpl-hdr.txt +27 -0
  31. data/info/kerze.png +0 -0
  32. data/info/language.png +0 -0
  33. data/info/lingo.png +0 -0
  34. data/info/logo.png +0 -0
  35. data/info/meeting.png +0 -0
  36. data/info/types.png +0 -0
  37. data/lib/lingo.rb +321 -0
  38. data/lib/lingo/attendee/abbreviator.rb +119 -0
  39. data/lib/lingo/attendee/debugger.rb +111 -0
  40. data/lib/lingo/attendee/decomposer.rb +101 -0
  41. data/lib/lingo/attendee/dehyphenizer.rb +167 -0
  42. data/lib/lingo/attendee/multiworder.rb +301 -0
  43. data/lib/lingo/attendee/noneword_filter.rb +103 -0
  44. data/lib/lingo/attendee/objectfilter.rb +86 -0
  45. data/lib/lingo/attendee/sequencer.rb +190 -0
  46. data/lib/lingo/attendee/synonymer.rb +105 -0
  47. data/lib/lingo/attendee/textreader.rb +237 -0
  48. data/lib/lingo/attendee/textwriter.rb +196 -0
  49. data/lib/lingo/attendee/tokenizer.rb +218 -0
  50. data/lib/lingo/attendee/variator.rb +185 -0
  51. data/lib/lingo/attendee/vector_filter.rb +158 -0
  52. data/lib/lingo/attendee/wordsearcher.rb +96 -0
  53. data/lib/lingo/attendees.rb +289 -0
  54. data/lib/lingo/cli.rb +62 -0
  55. data/lib/lingo/config.rb +104 -0
  56. data/lib/lingo/const.rb +131 -0
  57. data/lib/lingo/ctl.rb +173 -0
  58. data/lib/lingo/database.rb +587 -0
  59. data/lib/lingo/language.rb +530 -0
  60. data/lib/lingo/modules.rb +98 -0
  61. data/lib/lingo/types.rb +285 -0
  62. data/lib/lingo/utilities.rb +40 -0
  63. data/lib/lingo/version.rb +27 -0
  64. data/lingo-all.cfg +85 -0
  65. data/lingo-call.cfg +15 -0
  66. data/lingo.cfg +78 -0
  67. data/lingo.rb +3 -0
  68. data/lir.cfg +72 -0
  69. data/porter/stem.cfg +311 -0
  70. data/porter/stem.rb +150 -0
  71. data/spec/spec_helper.rb +0 -0
  72. data/test.cfg +79 -0
  73. data/test/attendee/ts_abbreviator.rb +35 -0
  74. data/test/attendee/ts_decomposer.rb +31 -0
  75. data/test/attendee/ts_multiworder.rb +390 -0
  76. data/test/attendee/ts_noneword_filter.rb +19 -0
  77. data/test/attendee/ts_objectfilter.rb +19 -0
  78. data/test/attendee/ts_sequencer.rb +43 -0
  79. data/test/attendee/ts_synonymer.rb +33 -0
  80. data/test/attendee/ts_textreader.rb +58 -0
  81. data/test/attendee/ts_textwriter.rb +98 -0
  82. data/test/attendee/ts_tokenizer.rb +32 -0
  83. data/test/attendee/ts_variator.rb +24 -0
  84. data/test/attendee/ts_vector_filter.rb +62 -0
  85. data/test/attendee/ts_wordsearcher.rb +119 -0
  86. data/test/lir.csv +3 -0
  87. data/test/lir.txt +12 -0
  88. data/test/lir2.txt +12 -0
  89. data/test/mul.txt +1 -0
  90. data/test/ref/artikel.mul +1 -0
  91. data/test/ref/artikel.non +159 -0
  92. data/test/ref/artikel.seq +270 -0
  93. data/test/ref/artikel.syn +16 -0
  94. data/test/ref/artikel.vec +928 -0
  95. data/test/ref/artikel.ven +928 -0
  96. data/test/ref/artikel.ver +928 -0
  97. data/test/ref/lir.csv +328 -0
  98. data/test/ref/lir.mul +1 -0
  99. data/test/ref/lir.non +274 -0
  100. data/test/ref/lir.seq +249 -0
  101. data/test/ref/lir.syn +94 -0
  102. data/test/test_helper.rb +113 -0
  103. data/test/ts_database.rb +269 -0
  104. data/test/ts_language.rb +396 -0
  105. data/txt/artikel-en.txt +157 -0
  106. data/txt/artikel.txt +170 -0
  107. data/txt/lir.txt +1317 -0
  108. metadata +211 -0
@@ -0,0 +1,269 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'test_helper'
4
+
5
+ class Lingo::Txt2DbmConverter
6
+ alias_method :original_initialize, :initialize
7
+ def initialize(id, lingo, verbose = false)
8
+ original_initialize(id, lingo, verbose)
9
+ end
10
+ end
11
+
12
+ class TestDatabase < LingoTestCase
13
+
14
+ def setup
15
+ @lingo = Lingo.new
16
+
17
+ @singleword = <<-EOT
18
+ Wort1
19
+ Wort2
20
+ Wort2
21
+ juristische Personen
22
+ höher schneller weiter
23
+ höher schneller weiter größer
24
+ ganz großer und blöder quatsch
25
+ ganz großer und blöder mist
26
+ ganz großer und blöder schwach sinn
27
+ EOT
28
+
29
+ @keyvalue = <<-EOT
30
+ Wort1*Projektion1
31
+ Wort2*Projektion2
32
+ Wort3*Projektion3
33
+ Wort4*
34
+ Wort1*Projektion4
35
+ Wort1 * Projektion5
36
+ Mehr Wort Satz*Pro Jeck Zion 1
37
+ Mehr Wort Satz*Pro Jeck Zion 2
38
+ Albert Einstein*Einstein, Albert
39
+ EOT
40
+
41
+ @wordclass = <<-EOT
42
+ Wort1=Projektion1#h
43
+ Wort2=Projektion2#i
44
+ Wort3=Projektion3#e
45
+ Wort1=Projektion4 #e
46
+ Wort1=#s
47
+ Wort2=
48
+ EOT
49
+ end
50
+
51
+ def test_singleword
52
+ compare({
53
+ 'txt-format' => 'SingleWord'
54
+ }, @singleword, {
55
+ 'wort1' => '#s',
56
+ 'wort2' => '#s',
57
+ 'juristische personen' => '#s',
58
+ 'höher schneller weiter' => '#s',
59
+ 'höher schneller weiter größer' => '#s',
60
+ 'ganz großer und blöder quatsch' => '#s',
61
+ 'ganz großer und blöder mist' => '#s',
62
+ 'ganz großer und blöder schwach sinn' => '#s'
63
+ })
64
+ end
65
+
66
+ def test_singleword_defwc
67
+ compare({
68
+ 'txt-format' => 'SingleWord',
69
+ 'def-wc' => '*'
70
+ }, @singleword, {
71
+ 'wort1' => '#*',
72
+ 'wort2' => '#*',
73
+ 'juristische personen' => '#*',
74
+ 'höher schneller weiter' => '#*',
75
+ 'höher schneller weiter größer' => '#*',
76
+ 'ganz großer und blöder quatsch' => '#*',
77
+ 'ganz großer und blöder mist' => '#*',
78
+ 'ganz großer und blöder schwach sinn' => '#*'
79
+ })
80
+ end
81
+
82
+ def test_singleword_defmulwc
83
+ compare({
84
+ 'txt-format' => 'SingleWord',
85
+ 'def-mul-wc' => 'm'
86
+ }, @singleword, {
87
+ 'wort1' => '#s',
88
+ 'wort2' => '#s',
89
+ 'juristische personen' => '#m',
90
+ 'höher schneller weiter' => '#m',
91
+ 'höher schneller weiter größer' => '#m',
92
+ 'ganz großer und blöder quatsch' => '#m',
93
+ 'ganz großer und blöder mist' => '#m',
94
+ 'ganz großer und blöder schwach sinn' => '#m'
95
+ })
96
+ end
97
+
98
+ def test_singleword_uselex
99
+ compare({
100
+ 'txt-format' => 'SingleWord',
101
+ 'use-lex' => set_config('lex',
102
+ 'name' => 'de/lingo-dic.txt',
103
+ 'txt-format' => 'WordClass'
104
+ )
105
+ }, @singleword, {
106
+ 'wort1' => '#s',
107
+ 'wort2' => '#s',
108
+ 'ganz groß und blöd mist' => 'ganz großer und blöder mist#s',
109
+ 'juristisch person' => 'juristische personen#s',
110
+ 'hoch schnell weit' => '*4|höher schneller weiter#s',
111
+ 'ganz groß und blöd quatsch' => 'ganz großer und blöder quatsch#s',
112
+ 'hoch schnell weit groß' => 'höher schneller weiter größer#s',
113
+ 'ganz groß und blöd schwach sinn' => 'ganz großer und blöder schwach sinn#s',
114
+ 'ganz groß und' => '*5|*6'
115
+ })
116
+ end
117
+
118
+ def test_singleword_crypt
119
+ config = {
120
+ 'txt-format' => 'SingleWord',
121
+ 'crypt' => true
122
+ }
123
+
124
+ compare(config, @singleword, {
125
+ 'd8ac4360a5f707d518212e27dcba9dd42d980f96' => '5116',
126
+ '81463f9c7e0ad40e329e83d3358232851d50ed9a' => '4d16',
127
+ '8da4a0c30c912543be2d88da64c0192e577efa9d' => '1107',
128
+ '2c24b4707e77c74abfb12748317693dc1e43c215' => '5700',
129
+ '810ff7a76f39febcb1cf67993d4fb29819ce40a6' => '5116',
130
+ 'a28b4ca84ac08aeef4e420445f94f632ad010a30' => '1207',
131
+ '1496f4febbc647f3ac74b0af11dadbd6322f6732' => '4d1d',
132
+ 'b7501a62cb083be6730a7a179a4ab346d23efe53' => '4b10'
133
+ })
134
+
135
+ compare(config, @singleword) { |dbm| {
136
+ 'wort1' => '#s',
137
+ 'wort2' => '#s',
138
+ 'juristische personen' => '#s',
139
+ 'höher schneller weiter' => '#s',
140
+ 'höher schneller weiter größer' => '#s',
141
+ 'ganz großer und blöder quatsch' => '#s',
142
+ 'ganz großer und blöder mist' => '#s',
143
+ 'ganz großer und blöder schwach sinn' => '#s'
144
+ }.each { |key, val| assert_equal([val], dbm[key]) } }
145
+ end
146
+
147
+ def test_keyvalue
148
+ compare({
149
+ 'txt-format' => 'KeyValue'
150
+ }, @keyvalue, {
151
+ 'wort1' => 'projektion1#?|projektion4#?|projektion5#?',
152
+ 'wort2' => 'projektion2#?',
153
+ 'wort3' => 'projektion3#?',
154
+ 'mehr wort satz' => 'pro jeck zion 1#?|pro jeck zion 2#?',
155
+ 'albert einstein' => 'einstein, albert#?'
156
+ })
157
+ end
158
+
159
+ def test_keyvalue_separator
160
+ compare({
161
+ 'txt-format' => 'KeyValue',
162
+ 'separator' => '*'
163
+ }, @keyvalue, {
164
+ 'wort1' => 'projektion1#?|projektion4#?|projektion5#?',
165
+ 'wort2' => 'projektion2#?',
166
+ 'wort3' => 'projektion3#?',
167
+ 'mehr wort satz' => 'pro jeck zion 1#?|pro jeck zion 2#?',
168
+ 'albert einstein' => 'einstein, albert#?'
169
+ })
170
+ end
171
+
172
+ def test_keyvalue_defwc
173
+ compare({
174
+ 'txt-format' => 'KeyValue',
175
+ 'separator' => '*',
176
+ 'def-wc' => 's'
177
+ }, @keyvalue, {
178
+ 'wort1'=>'projektion1#s|projektion4#s|projektion5#s',
179
+ 'wort2'=>'projektion2#s',
180
+ 'wort3'=>'projektion3#s',
181
+ 'mehr wort satz'=>'pro jeck zion 1#s|pro jeck zion 2#s',
182
+ 'albert einstein'=>'einstein, albert#s'
183
+ })
184
+ end
185
+
186
+ def test_wordclass
187
+ compare({
188
+ 'txt-format' => 'WordClass',
189
+ 'separator' => '='
190
+ }, %q{
191
+ Wort1=Projektion1#h
192
+ Wort2=Projektion2#i
193
+ Wort3=Projektion3#e
194
+ Wort1=Projektion4 #e
195
+ Wort1=#s
196
+ Wort2=
197
+ }, {
198
+ 'wort1' => 'projektion1#h|projektion4#e',
199
+ 'wort2' => 'projektion2#i',
200
+ 'wort3' => 'projektion3#e'
201
+ })
202
+ end
203
+
204
+ def test_multivalue
205
+ compare({
206
+ 'txt-format' => 'MultiValue',
207
+ 'separator' => ';'
208
+ }, %q{
209
+ Hasen;Nasen;Vasen;Rasen
210
+ Gold;Edelmetall;Mehrwert
211
+ Rasen;Gras;Grüne Fläche
212
+ Rasen;Rennen;Wettrennen
213
+ }, {
214
+ '^0' => 'hasen|nasen|rasen|vasen',
215
+ '^1' => 'edelmetall|gold|mehrwert',
216
+ '^2' => 'gras|grüne fläche|rasen',
217
+ '^3' => 'rasen|rennen|wettrennen',
218
+ 'hasen' => '^0',
219
+ 'nasen' => '^0',
220
+ 'rasen' => '^0|^2|^3',
221
+ 'vasen' => '^0',
222
+ 'edelmetall' => '^1',
223
+ 'gold' => '^1',
224
+ 'mehrwert' => '^1',
225
+ 'gras' => '^2',
226
+ 'grüne fläche' => '^2',
227
+ 'wettrennen' => '^3',
228
+ 'rennen' => '^3'
229
+ })
230
+ end
231
+
232
+ def test_multikey
233
+ compare({
234
+ 'txt-format' => 'MultiKey'
235
+ }, %q{
236
+ Hasen;Nasen;Vasen;Rasen
237
+ Gold;Edelmetall;Mehrwert
238
+ }, {
239
+ 'nasen' => 'hasen',
240
+ 'vasen' => 'hasen',
241
+ 'rasen' => 'hasen',
242
+ 'edelmetall' => 'gold',
243
+ 'mehrwert' => 'gold',
244
+ })
245
+ end
246
+
247
+ def compare(config, input, output = nil)
248
+ FileUtils.mkdir_p(File.dirname(TEST_FILE))
249
+ File.write(TEST_FILE, input, encoding: Lingo::ENC)
250
+
251
+ Lingo::DbmFile.open(set_config('tst', config.merge('name' => TEST_FILE)), @lingo) { |dbm|
252
+ if block_given?
253
+ yield dbm
254
+ else
255
+ store = dbm.to_h
256
+ store.delete(Lingo::SYS_KEY)
257
+
258
+ assert_equal(output, store)
259
+ end
260
+ }
261
+ ensure
262
+ cleanup_store
263
+ end
264
+
265
+ def set_config(id, config)
266
+ "_test_#{id}_".tap { |id| @lingo.config["language/dictionary/databases/#{id}"] = config }
267
+ end
268
+
269
+ end
@@ -0,0 +1,396 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'test_helper'
4
+
5
+ class TestLexicalHash < LingoTestCase
6
+
7
+ def setup
8
+ @lingo = Lingo.new
9
+ @database_config = @lingo.config['language/dictionary/databases']
10
+ end
11
+
12
+ def teardown
13
+ cleanup_store
14
+ end
15
+
16
+ def test_params
17
+ old_stderr, $stderr = $stderr, StringIO.new('')
18
+
19
+ # Datenquelle nicht in Konfiguration enthalten
20
+ assert_raise(SystemExit) { Lingo::LexicalHash.new('nonsens', @lingo) }
21
+ ensure
22
+ $stderr = old_stderr
23
+ end
24
+
25
+ # TODO: Crypt testen...
26
+
27
+ def test_cache
28
+ ds = Lingo::LexicalHash.new('sys-dic', @lingo)
29
+ assert_equal([lx('regen|s'), lx('regen|v'), lx('rege|a')], ds['regen'])
30
+ assert_equal([lx('regen|s'), lx('regen|v'), lx('rege|a')], ds['regen'])
31
+ assert_equal([lx('regen|s'), lx('regen|v'), lx('rege|a')], ds['regen'])
32
+ ds.close
33
+ end
34
+
35
+ def test_report
36
+ ds = Lingo::LexicalHash.new('tst-syn', @lingo)
37
+ ds['abwickeln'] # source read
38
+ ds['abwickeln'] # cache hit
39
+ ds['regen'] # source read
40
+ ds['nonesens'] # source read, nothing found
41
+
42
+ expect = { \
43
+ "tst-syn: cache hits" => 1, \
44
+ "tst-syn: total requests" => 4, \
45
+ "tst-syn: source reads" => 3, \
46
+ "tst-syn: data found" => 2
47
+ }
48
+
49
+ assert_equal(expect, ds.report)
50
+ ds.close
51
+ end
52
+
53
+ def test_auto_create
54
+ txt_file = @database_config['tst-sgw']['name']
55
+ sto_file = Lingo.find(:store, txt_file) << '.pag'
56
+
57
+ ds = Lingo::LexicalHash.new('tst-sgw', @lingo)
58
+ assert_equal([lx('substantiv|s')], ds['substantiv'])
59
+ ds.close
60
+
61
+ # Keine Store-Datei vorhanden, nur Text vorhanden
62
+ File.delete(sto_file)
63
+ ds = Lingo::LexicalHash.new('tst-sgw', @lingo)
64
+ assert_equal([lx('substantiv|s')], ds['substantiv'])
65
+ ds.close
66
+
67
+ # Store vorhanden, aber Text ist neuer
68
+ ds = Lingo::LexicalHash.new('tst-sgw', @lingo)
69
+ assert_equal([lx('substantiv|s')], ds['substantiv'])
70
+ ds.close
71
+ end
72
+
73
+ def test_singleword
74
+ ds = Lingo::LexicalHash.new('tst-sgw', @lingo)
75
+ assert_equal([lx('substantiv|s')], ds['substantiv'])
76
+ assert_equal([lx('mehr wort gruppe|s')], ds['mehr wort gruppe'])
77
+ assert_equal(nil, ds['nicht vorhanden'])
78
+ ds.close
79
+ end
80
+
81
+ def test_keyvalue
82
+ ds = Lingo::LexicalHash.new('sys-mul', @lingo)
83
+ assert_equal([lx('abelscher ring ohne nullteiler|m')], ds['abelscher ring ohne nullteiler'])
84
+ assert_equal(['*4'], ds['abelscher ring ohne'])
85
+ assert_equal([lx('alleinreisende frau|m')], ds['alleinreisend frau'])
86
+ assert_equal([lx('abschaltbarer leistungshalbleiter|m')], ds['abschaltbar leistungshalbleiter'])
87
+ assert_equal(nil, ds['abschaltbarer leistungshalbleiter'])
88
+ ds.close
89
+ end
90
+
91
+ def test_wordclass
92
+ ds = Lingo::LexicalHash.new('sys-dic', @lingo)
93
+ assert_equal([lx('a-dur|s')], ds['a-dur'])
94
+ assert_equal([lx('aalen|v'), lx('aalen|e')], ds['aalen'])
95
+ assert_equal([lx('abarbeitend|a')], ds['abarbeitend'])
96
+ ds.close
97
+ end
98
+
99
+ def test_case
100
+ ds = Lingo::LexicalHash.new('sys-dic', @lingo)
101
+ assert_equal([lx('abänderung|s')], ds['abänderung'])
102
+ assert_equal([lx('abänderung|s')], ds['Abänderung'])
103
+ assert_equal([lx('abänderung|s')], ds['ABÄNDERUNG'])
104
+ ds.close
105
+ end
106
+
107
+ def test_multivalue
108
+ ds = Lingo::LexicalHash.new('sys-syn', @lingo)
109
+ # assert_equal([lx('abrollen', LA_SYNONYM), lx('abschaffen', LA_SYNONYM), lx('abwickeln', LA_SYNONYM), lx('auflösen (geschäft)','y')], ds['abwickeln'])
110
+ # assert_equal([lx('niederschlag', LA_SYNONYM), lx('regen', LA_SYNONYM), lx('schauer', LA_SYNONYM)], ds['regen'])
111
+ ds.close
112
+ end
113
+
114
+ end
115
+
116
+ class TestDictionary < LingoTestCase
117
+
118
+ def setup
119
+ @lingo = Lingo.new
120
+ end
121
+
122
+ def test_params
123
+ # Keine Sprach-Konfiguration angegeben
124
+ #assert_raise(RuntimeError) { Lingo::Dictionary.new({'source'=>['sys-dic']}, @lingo) }
125
+ # Keine Parameter angegeben
126
+ assert_raise(RuntimeError) { Lingo::Dictionary.new(nil, @lingo) }
127
+ # Falsche Parameter angegeben (Pflichtparameter ohne Defaultwert)
128
+ assert_raise(RuntimeError) { Lingo::Dictionary.new({'course'=>['sys-dic']}, @lingo) }
129
+ end
130
+
131
+ def test_cache
132
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic']}, @lingo)
133
+ assert_equal([lx('nase|s')], dic.select('nase'))
134
+ assert_equal([lx('nase|s')], dic.select('nase'))
135
+ assert_equal([lx('nase|s')], dic.select('nase'))
136
+ dic.close
137
+ end
138
+
139
+ def test_report
140
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic']}, @lingo)
141
+ dic.select('abwickeln') # source read
142
+ dic.select('abwickeln') # cache hit
143
+ dic.select('regen') # source read
144
+ dic.select('nonesens') # source read, nothing found
145
+
146
+ expect = {
147
+ "sys-dic: total requests" => 4,
148
+ "sys-dic: data found" => 2,
149
+ "sys-dic: cache hits" => 1,
150
+ "sys-dic: source reads" => 3
151
+ }
152
+
153
+ assert_equal(expect, dic.report)
154
+ dic.close
155
+ end
156
+
157
+ def test_select_one_source
158
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic']}, @lingo)
159
+ assert_equal([lx('nase|s')], dic.select('nase'))
160
+ assert_equal([lx('nase|s')], dic.select('NASE'))
161
+ assert_equal([], dic.select('hasennasen'))
162
+ dic.close
163
+ end
164
+
165
+ def test_select_two_sources_mode_first
166
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic', 'tst-dic'], 'mode'=>'first'}, @lingo)
167
+ # in keiner Quelle vorhanden
168
+ assert_equal([], dic.select('hasennasen'))
169
+ # nur in erster Quelle vorhanden
170
+ assert_equal([lx('knaller|s')], dic.select('knaller'))
171
+ # nur in zweiter Quelle vorhanden
172
+ assert_equal([lx('super indexierungssystem|m')], dic.select('lex-lingo'))
173
+ # in beiden Quellen vorhanden
174
+ assert_equal([lx('a-dur|s')], dic.select('a-dur'))
175
+ dic.close
176
+ end
177
+
178
+ def test_select_two_sources_mode_first_flipped
179
+ dic = Lingo::Dictionary.new({'source'=>['tst-dic','sys-dic'], 'mode'=>'first'}, @lingo)
180
+ # in keiner Quelle vorhanden
181
+ assert_equal([], dic.select('hasennasen'))
182
+ # nur in erster Quelle vorhanden
183
+ assert_equal([lx('knaller|s')], dic.select('knaller'))
184
+ # nur in zweiter Quelle vorhanden
185
+ assert_equal([lx('super indexierungssystem|m')], dic.select('lex-lingo'))
186
+ # in beiden Quellen vorhanden
187
+ assert_equal([lx('b-dur|s')], dic.select('a-dur'))
188
+ dic.close
189
+ end
190
+
191
+ def test_select_two_sources_mode_all
192
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic','tst-dic'], 'mode'=>'all'}, @lingo)
193
+ # in keiner Quelle vorhanden
194
+ assert_equal([], dic.select('hasennasen'))
195
+ # nur in erster Quelle vorhanden
196
+ assert_equal([lx('knaller|s')], dic.select('knaller'))
197
+ # nur in zweiter Quelle vorhanden
198
+ assert_equal([lx('super indexierungssystem|m')], dic.select('lex-lingo'))
199
+ # in beiden Quellen vorhanden
200
+ assert_equal([lx('a-dur|s'), lx('b-dur|s')], dic.select('a-dur'))
201
+ assert_equal([lx('aas|s')], dic.select('aas'))
202
+ dic.close
203
+ end
204
+
205
+ def test_select_two_sources_mode_default
206
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic','tst-dic']}, @lingo)
207
+ # in keiner Quelle vorhanden
208
+ assert_equal([], dic.select('hasennasen'))
209
+ # nur in erster Quelle vorhanden
210
+ assert_equal([lx('knaller|s')], dic.select('knaller'))
211
+ # nur in zweiter Quelle vorhanden
212
+ assert_equal([lx('super indexierungssystem|m')], dic.select('lex-lingo'))
213
+ # in beiden Quellen vorhanden
214
+ assert_equal([lx('a-dur|s'), lx('b-dur|s')], dic.select('a-dur'))
215
+ assert_equal([lx('aas|s')], dic.select('aas'))
216
+ dic.close
217
+ end
218
+
219
+ def test_suffix_lexicals
220
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic']}, @lingo)
221
+ assert_equal([lx('mau|s'), lx('mauer|s')], dic.suffix_lexicals('mauern'))
222
+ assert_equal([lx('hasen|s'), lx('hasen|v'), lx('hasen|e')], dic.suffix_lexicals('hasens'))
223
+ assert_equal([lx('schönst|s'), lx('schön|a'), lx('schönst|a')], dic.suffix_lexicals('schönster'))
224
+ assert_equal([lx('segnen|v'), lx('segneen|v')], dic.suffix_lexicals('segnet'))
225
+ dic.close
226
+ end
227
+
228
+ def test_infix_lexicals
229
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic']}, @lingo)
230
+ assert_equal( [lx('information|s'), lx('information|v'), lx('information|e')], dic.suffix_lexicals('informations'))
231
+ dic.close
232
+ end
233
+
234
+ def test_select_with_suffix
235
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic']}, @lingo)
236
+ assert_equal([lx('mauern|v')], dic.select_with_suffix('mauern'))
237
+ assert_equal([lx('hase|s')], dic.select_with_suffix('hasen'))
238
+ assert_equal([lx('schön|a')], dic.select_with_suffix('schönster'))
239
+ assert_equal([lx('segnen|v')], dic.select_with_suffix('segnet'))
240
+ dic.close
241
+ end
242
+
243
+ def test_select_with_infix
244
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic']}, @lingo)
245
+ assert_equal( [lx('information|s'), lx('information|v'), lx('information|e')], dic.suffix_lexicals('informations'))
246
+ dic.close
247
+ end
248
+
249
+ def test_find_word
250
+ dic = Lingo::Dictionary.new({'source'=>['sys-dic']}, @lingo)
251
+ assert_equal(wd('hasennasen|?'), dic.find_word('hasennasen'))
252
+ assert_equal(wd('hase|IDF', 'hase|s'), dic.find_word('hase'))
253
+ assert_equal(wd('haseses|IDF', 'hase|s'), dic.find_word('haseses'))
254
+ dic.close
255
+ end
256
+
257
+ end
258
+
259
+ class TestGrammar < LingoTestCase
260
+
261
+ def setup
262
+ @lingo = Lingo.new
263
+ end
264
+
265
+ def test_params
266
+ # Die gleichen Fälle wie bei Dictionary, daher nicht notwendig
267
+ end
268
+
269
+ def test_cache
270
+ gra = Lingo::Grammar.new({'source'=>['sys-dic']}, @lingo)
271
+ assert_equal(
272
+ wd('informationswissenschaften|KOM', 'informationswissenschaft|k', 'information|s+', 'wissenschaft|s+'),
273
+ gra.find_compositum('informationswissenschaften')
274
+ )
275
+ assert_equal(
276
+ wd('informationswissenschaften|KOM', 'informationswissenschaft|k', 'information|s+', 'wissenschaft|s+'),
277
+ gra.find_compositum('informationswissenschaften')
278
+ )
279
+ assert_equal(
280
+ wd('informationswissenschaften|KOM', 'informationswissenschaft|k', 'information|s+', 'wissenschaft|s+'),
281
+ gra.find_compositum('informationswissenschaften')
282
+ )
283
+ gra.close
284
+ end
285
+
286
+ def t1est_test_compositum
287
+ gra = Lingo::Grammar.new({'source'=>['sys-dic']}, @lingo)
288
+ # hinterer Teil ist ein Wort mit Suffix
289
+ assert_equal([ [5, 6], [lx('hasenbraten|k'), lx('braten|s'), lx('hase|s'), lx('braten|v')] ],
290
+ gra.test_compositum('hasen', '', 'braten', 1, false)
291
+ )
292
+ # hinterer Teil ist ein Wort mit Infix ohne Schwanz
293
+ assert_equal([ [5, 7], [lx('nasenlaufen|k'), lx('laufen|s'), lx('nase|s'), lx('laufen|v')] ],
294
+ gra.test_compositum('nasen', '', 'laufens', 1, false)
295
+ )
296
+ # hinterer Teil ist ein Wort mit Infix mit Schwanz
297
+ assert_equal([ [5, 7], [lx('nasenlaufens|k'), lx('laufen|s'), lx('nase|s'), lx('laufen|v')] ],
298
+ gra.test_compositum('nasen', '', 'laufens', 1, true)
299
+ )
300
+ # hinterer Teil ist ein Kompositum nach Bindestrich
301
+ assert_equal([ [7, 9, 6], [lx('arrafat-nachfolgebedarf|k'), lx('bedarf|s'), lx('nachfolge|s'), lx('arrafat|x')] ],
302
+ gra.test_compositum('arrafat', '-', 'nachfolgebedarf', 1, false)
303
+ )
304
+ # hinterer Teil ist ein TakeItAsIs nach Bindestrich
305
+ assert_equal([ [9, 7], [lx('nachfolge-arrafat|k'), lx('nachfolge|s'), lx('arrafat|x')] ],
306
+ gra.test_compositum('nachfolge', '-', 'arrafat', 1, false)
307
+ )
308
+ # vorderer Teil ist ein Wort mit Suffix => siehe Hasenbraten
309
+ # vorderer Teil ist ein Kompositum
310
+ assert_equal([ [6, 5, 6], [lx('morgenonkelmantel|k'), lx('mantel|s'), lx('morgen|s'), lx('onkel|s'), lx('morgen|w')] ],
311
+ gra.test_compositum('morgenonkel', '', 'mantel', 1, false)
312
+ )
313
+ # vorderer Teil ist ein TakeItAsIs vor Bindestrich
314
+ assert_equal([ [7, 10], [lx('arrafat-nachfolger|k'), lx('nachfolger|s'), lx('arrafat|x')] ],
315
+ gra.test_compositum('arrafat', '-', 'nachfolger', 1, false)
316
+ )
317
+ gra.close
318
+ end
319
+
320
+ def t1est_permute_compositum
321
+ gra = Lingo::Grammar.new({'source'=>['sys-dic']}, @lingo)
322
+ # bindestrichversion
323
+ assert_equal([ [7, 10], [lx('arrafat-nachfolger|k'), lx('nachfolger|s'), lx('arrafat|x')] ],
324
+ gra.permute_compositum('arrafat-nachfolger', 1, false)
325
+ )
326
+ # bindestrichversion zwei-teilig
327
+ assert_equal([ [6, 11], \
328
+ [ lx('cd-rom-technologie|k'), \
329
+ lx('cd-rom|s'), \
330
+ lx('technologie|s')] ], \
331
+ gra.permute_compositum('cd-rom-technologie', 1, false) \
332
+ )
333
+ # bindestrichversion drei-teilig
334
+ assert_equal([ [6, 7, 11], \
335
+ [ lx('albert-ludwigs-universität|k'), \
336
+ lx('universität|s'), \
337
+ lx('albert|e'), \
338
+ lx('ludwig|e')] ], \
339
+ gra.permute_compositum('albert-ludwigs-universität', 1, false) \
340
+ )
341
+ # normal mit suggestion
342
+ assert_equal([ [8, 9], \
343
+ [ lx('benutzerforschung|k'), \
344
+ lx('benutzer|s'), \
345
+ lx('forschung|s')] ], \
346
+ gra.permute_compositum('benutzerforschung', 1, false) \
347
+ )
348
+ gra.close
349
+ end
350
+
351
+ def test_find_compositum
352
+ gra = Lingo::Grammar.new({'source'=>['sys-dic']}, @lingo)
353
+ assert_equal(
354
+ wd('informationswissenschaften|KOM', 'informationswissenschaft|k', 'information|s+', 'wissenschaft|s+'),
355
+ gra.find_compositum('informationswissenschaften') \
356
+ )
357
+ assert_equal(
358
+ wd('cd-rom-technologie|KOM', 'cd-rom-technologie|k', 'technologie|s+', 'cd-rom|x+'),
359
+ gra.find_compositum('cd-rom-technologie')
360
+ )
361
+ assert_equal(
362
+ wd('albert-ludwigs-universität|KOM', 'albert-ludwigs-universität|k', 'albert|e+', 'ludwig|e+', 'universität|s+'),
363
+ gra.find_compositum('albert-ludwigs-universität')
364
+ )
365
+ assert_equal(
366
+ wd('client-server-system|KOM', 'client-server-system|k', 'client|s+', 'server|s+', 'system|s+'),
367
+ gra.find_compositum('client-server-system')
368
+ )
369
+ assert_equal(
370
+ wd('benutzerforschung|KOM', 'benutzerforschung|k', 'erforschung|s+', 'benutzen|v+'),
371
+ gra.find_compositum('benutzerforschung')
372
+ )
373
+ assert_equal(
374
+ wd('clustersuche|KOM', 'clustersuche|k', 'cluster|s+', 'suche|s+', 'suchen|v+'),
375
+ gra.find_compositum('clustersuche')
376
+ )
377
+ gra.close
378
+ end
379
+
380
+ def test_min_word_size
381
+ gra = Lingo::Grammar.new({'source'=>['sys-dic']}, @lingo)
382
+ assert_equal( wd('undsund|?'), gra.find_compositum('undsund'))
383
+ gra.close
384
+ end
385
+
386
+ def test_max_parts
387
+ gra = Lingo::Grammar.new({'source'=>['sys-dic']}, @lingo)
388
+ assert_equal(
389
+ wd('baumsbaumsbaum|KOM', 'baumsbaumsbaum|k', 'baum|s+'),
390
+ gra.find_compositum('baumsbaumsbaum')
391
+ )
392
+ assert_equal( Lingo::Word.new('baumsbaumsbaumsbaumsbaumsbaum', Lingo::WA_UNKNOWN), gra.find_compositum('baumsbaumsbaumsbaumsbaumsbaum'))
393
+ gra.close
394
+ end
395
+
396
+ end