kreuzberg 4.3.5-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yaml +1 -0
  5. data/.rubocop.yml +543 -0
  6. data/Gemfile +8 -0
  7. data/Gemfile.lock +260 -0
  8. data/README.md +399 -0
  9. data/Rakefile +34 -0
  10. data/Steepfile +51 -0
  11. data/examples/async_patterns.rb +283 -0
  12. data/extconf.rb +60 -0
  13. data/kreuzberg.gemspec +253 -0
  14. data/lib/kreuzberg/api_proxy.rb +125 -0
  15. data/lib/kreuzberg/cache_api.rb +67 -0
  16. data/lib/kreuzberg/cli.rb +57 -0
  17. data/lib/kreuzberg/cli_proxy.rb +118 -0
  18. data/lib/kreuzberg/config.rb +1241 -0
  19. data/lib/kreuzberg/djot_content.rb +225 -0
  20. data/lib/kreuzberg/document_structure.rb +204 -0
  21. data/lib/kreuzberg/error_context.rb +136 -0
  22. data/lib/kreuzberg/errors.rb +116 -0
  23. data/lib/kreuzberg/extraction_api.rb +329 -0
  24. data/lib/kreuzberg/mcp_proxy.rb +176 -0
  25. data/lib/kreuzberg/ocr_backend_protocol.rb +40 -0
  26. data/lib/kreuzberg/post_processor_protocol.rb +15 -0
  27. data/lib/kreuzberg/result.rb +712 -0
  28. data/lib/kreuzberg/setup_lib_path.rb +99 -0
  29. data/lib/kreuzberg/types.rb +414 -0
  30. data/lib/kreuzberg/validator_protocol.rb +16 -0
  31. data/lib/kreuzberg/version.rb +5 -0
  32. data/lib/kreuzberg.rb +102 -0
  33. data/lib/kreuzberg_rb.so +0 -0
  34. data/lib/libpdfium.so +0 -0
  35. data/sig/kreuzberg/internal.rbs +184 -0
  36. data/sig/kreuzberg.rbs +1337 -0
  37. data/spec/binding/async_operations_spec.rb +473 -0
  38. data/spec/binding/batch_operations_spec.rb +677 -0
  39. data/spec/binding/batch_spec.rb +360 -0
  40. data/spec/binding/cache_spec.rb +227 -0
  41. data/spec/binding/cli_proxy_spec.rb +85 -0
  42. data/spec/binding/cli_spec.rb +55 -0
  43. data/spec/binding/config_result_spec.rb +377 -0
  44. data/spec/binding/config_spec.rb +419 -0
  45. data/spec/binding/config_validation_spec.rb +377 -0
  46. data/spec/binding/embeddings_spec.rb +816 -0
  47. data/spec/binding/error_handling_spec.rb +399 -0
  48. data/spec/binding/error_recovery_spec.rb +488 -0
  49. data/spec/binding/errors_spec.rb +66 -0
  50. data/spec/binding/font_config_spec.rb +220 -0
  51. data/spec/binding/images_spec.rb +732 -0
  52. data/spec/binding/keywords_extraction_spec.rb +600 -0
  53. data/spec/binding/metadata_types_spec.rb +1253 -0
  54. data/spec/binding/pages_extraction_spec.rb +550 -0
  55. data/spec/binding/plugins/ocr_backend_spec.rb +307 -0
  56. data/spec/binding/plugins/postprocessor_spec.rb +269 -0
  57. data/spec/binding/plugins/validator_spec.rb +273 -0
  58. data/spec/binding/tables_spec.rb +650 -0
  59. data/spec/fixtures/config.toml +38 -0
  60. data/spec/fixtures/config.yaml +41 -0
  61. data/spec/fixtures/invalid_config.toml +3 -0
  62. data/spec/serialization_spec.rb +134 -0
  63. data/spec/smoke/package_spec.rb +177 -0
  64. data/spec/spec_helper.rb +40 -0
  65. data/spec/unit/config/chunking_config_spec.rb +213 -0
  66. data/spec/unit/config/embedding_config_spec.rb +343 -0
  67. data/spec/unit/config/extraction_config_spec.rb +434 -0
  68. data/spec/unit/config/font_config_spec.rb +285 -0
  69. data/spec/unit/config/hierarchy_config_spec.rb +314 -0
  70. data/spec/unit/config/image_extraction_config_spec.rb +209 -0
  71. data/spec/unit/config/image_preprocessing_config_spec.rb +230 -0
  72. data/spec/unit/config/keyword_config_spec.rb +229 -0
  73. data/spec/unit/config/language_detection_config_spec.rb +258 -0
  74. data/spec/unit/config/ocr_config_spec.rb +171 -0
  75. data/spec/unit/config/output_format_spec.rb +380 -0
  76. data/spec/unit/config/page_config_spec.rb +221 -0
  77. data/spec/unit/config/pdf_config_spec.rb +267 -0
  78. data/spec/unit/config/postprocessor_config_spec.rb +290 -0
  79. data/spec/unit/config/tesseract_config_spec.rb +181 -0
  80. data/spec/unit/config/token_reduction_config_spec.rb +251 -0
  81. data/test/metadata_types_test.rb +959 -0
  82. metadata +292 -0
@@ -0,0 +1,600 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'Keyword Extraction' do
4
+ describe 'basic keyword extraction' do
5
+ it 'extracts keywords from text' do
6
+ config = Kreuzberg::Config::Extraction.new(
7
+ keywords: Kreuzberg::Config::Keywords.new(
8
+ algorithm: 'yake',
9
+ max_keywords: 10
10
+ )
11
+ )
12
+
13
+ text = 'Machine learning and artificial intelligence are transforming technology. Neural networks and deep learning are key areas of AI research. These technologies enable predictions and data analysis.'
14
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
15
+
16
+ expect(result).not_to be_nil
17
+ expect(result.content).not_to be_nil
18
+ expect(result.content).to include('Machine learning')
19
+ end
20
+
21
+ it 'returns keywords in metadata' do
22
+ config = Kreuzberg::Config::Extraction.new(
23
+ keywords: Kreuzberg::Config::Keywords.new(
24
+ algorithm: 'yake',
25
+ max_keywords: 5
26
+ )
27
+ )
28
+
29
+ text = 'Artificial intelligence transforms technology development. Machine learning algorithms improve with training data.'
30
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
31
+
32
+ expect(result).not_to be_nil
33
+ expect(result.metadata).to be_a(Hash)
34
+ end
35
+
36
+ it 'respects max_keywords parameter' do
37
+ max_keywords_values = [1, 5, 10]
38
+
39
+ max_keywords_values.each do |max_kw|
40
+ config = Kreuzberg::Config::Extraction.new(
41
+ keywords: Kreuzberg::Config::Keywords.new(
42
+ algorithm: 'yake',
43
+ max_keywords: max_kw
44
+ )
45
+ )
46
+
47
+ text = 'Machine learning and artificial intelligence are transforming technology. Neural networks and deep learning are key research areas. Data science enables predictions. Algorithms process information efficiently.'
48
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
49
+
50
+ expect(result).not_to be_nil
51
+ expect(result.content).not_to be_nil
52
+ end
53
+ end
54
+
55
+ it 'returns content when keywords enabled' do
56
+ config = Kreuzberg::Config::Extraction.new(
57
+ keywords: Kreuzberg::Config::Keywords.new(
58
+ algorithm: 'yake',
59
+ max_keywords: 5
60
+ )
61
+ )
62
+
63
+ text = 'Artificial intelligence is transforming the world.'
64
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
65
+
66
+ expect(result).not_to be_nil
67
+ expect(result.content).not_to be_nil
68
+ expect(result.content).to include('Artificial intelligence')
69
+ end
70
+ end
71
+
72
+ describe 'multilingual keyword extraction' do
73
+ it 'extracts keywords from English text' do
74
+ config = Kreuzberg::Config::Extraction.new(
75
+ keywords: Kreuzberg::Config::Keywords.new(
76
+ algorithm: 'yake',
77
+ language: 'en',
78
+ max_keywords: 5
79
+ )
80
+ )
81
+
82
+ text = 'Machine learning and artificial intelligence are transforming technology development globally.'
83
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
84
+
85
+ expect(result).not_to be_nil
86
+ expect(result.content).not_to be_nil
87
+ end
88
+
89
+ it 'extracts keywords from German text' do
90
+ config = Kreuzberg::Config::Extraction.new(
91
+ keywords: Kreuzberg::Config::Keywords.new(
92
+ algorithm: 'yake',
93
+ language: 'de',
94
+ max_keywords: 5
95
+ )
96
+ )
97
+
98
+ text = 'Maschinelles Lernen und künstliche Intelligenz transformieren die Technologieentwicklung.'
99
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
100
+
101
+ expect(result).not_to be_nil
102
+ expect(result.content).not_to be_nil
103
+ end
104
+
105
+ it 'extracts keywords from French text' do
106
+ config = Kreuzberg::Config::Extraction.new(
107
+ keywords: Kreuzberg::Config::Keywords.new(
108
+ algorithm: 'yake',
109
+ language: 'fr',
110
+ max_keywords: 5
111
+ )
112
+ )
113
+
114
+ text = "L'apprentissage automatique et l'intelligence artificielle transforment le développement technologique."
115
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
116
+
117
+ expect(result).not_to be_nil
118
+ expect(result.content).not_to be_nil
119
+ end
120
+
121
+ it 'handles language parameter correctly' do
122
+ languages = %w[en de fr es it pt nl]
123
+
124
+ languages.each do |lang|
125
+ config = Kreuzberg::Config::Extraction.new(
126
+ keywords: Kreuzberg::Config::Keywords.new(
127
+ algorithm: 'yake',
128
+ language: lang,
129
+ max_keywords: 3
130
+ )
131
+ )
132
+
133
+ text = 'Machine learning and artificial intelligence.'
134
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
135
+
136
+ expect(result).not_to be_nil
137
+ end
138
+ end
139
+ end
140
+
141
+ describe 'min_score filtering' do
142
+ it 'filters keywords with different score thresholds' do
143
+ text = 'Machine learning and artificial intelligence are transforming technology. Neural networks and deep learning are key research areas.'
144
+
145
+ results_by_threshold = {}
146
+ thresholds = [0.1, 0.5, 0.9]
147
+
148
+ thresholds.each do |threshold|
149
+ config = Kreuzberg::Config::Extraction.new(
150
+ keywords: Kreuzberg::Config::Keywords.new(
151
+ algorithm: 'yake',
152
+ max_keywords: 100,
153
+ min_score: threshold
154
+ )
155
+ )
156
+
157
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
158
+ results_by_threshold[threshold] = result
159
+
160
+ expect(result).not_to be_nil
161
+ expect(result.content).not_to be_nil
162
+ end
163
+
164
+ # Lower thresholds should produce more or equal results
165
+ low_score_content = results_by_threshold[0.1]
166
+ high_score_content = results_by_threshold[0.9]
167
+ expect(low_score_content.content.length).to be >= high_score_content.content.length
168
+ end
169
+
170
+ it 'produces consistent results with same score threshold' do
171
+ config = Kreuzberg::Config::Extraction.new(
172
+ keywords: Kreuzberg::Config::Keywords.new(
173
+ algorithm: 'yake',
174
+ max_keywords: 50,
175
+ min_score: 0.3
176
+ )
177
+ )
178
+
179
+ text = 'Artificial intelligence is transforming data science and machine learning research globally with neural networks.'
180
+ result1 = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
181
+ result2 = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
182
+ result3 = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
183
+
184
+ # Results should be identical across runs
185
+ expect(result1.content).to eq(result2.content)
186
+ expect(result2.content).to eq(result3.content)
187
+ end
188
+ end
189
+
190
+ describe 'ngram_range variations' do
191
+ it 'extracts keywords with different ngram configurations' do
192
+ text = 'Machine learning and artificial intelligence are transforming data science and technology development globally.'
193
+
194
+ configs = {
195
+ 'single_words' => [1, 1],
196
+ 'bigrams' => [2, 2],
197
+ 'unigram_bigram' => [1, 2],
198
+ 'unigram_trigram' => [1, 3]
199
+ }
200
+
201
+ results = {}
202
+ configs.each do |label, range|
203
+ config = Kreuzberg::Config::Extraction.new(
204
+ keywords: Kreuzberg::Config::Keywords.new(
205
+ algorithm: 'yake',
206
+ max_keywords: 15,
207
+ ngram_range: range
208
+ )
209
+ )
210
+
211
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
212
+ results[label] = result
213
+
214
+ expect(result).not_to be_nil
215
+ expect(result.content).not_to be_nil
216
+ expect(result.content.length).to be > 0
217
+ end
218
+
219
+ # Wider n-gram ranges typically produce more content due to phrase inclusion
220
+ expect(results['unigram_trigram'].content.length).to be >= results['single_words'].content.length
221
+ end
222
+
223
+ it 'produces consistent results with same ngram_range' do
224
+ config = Kreuzberg::Config::Extraction.new(
225
+ keywords: Kreuzberg::Config::Keywords.new(
226
+ algorithm: 'yake',
227
+ max_keywords: 10,
228
+ ngram_range: [1, 2]
229
+ )
230
+ )
231
+
232
+ text = 'Machine learning and artificial intelligence are transforming technology development across industry.'
233
+ result1 = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
234
+ result2 = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
235
+
236
+ # Results should be identical
237
+ expect(result1.content).to eq(result2.content)
238
+ end
239
+ end
240
+
241
+ describe 'algorithm selection' do
242
+ it 'both YAKE and RAKE algorithms produce results' do
243
+ text = 'Machine learning and artificial intelligence are transforming technology and neural networks enable deep learning.'
244
+
245
+ yake_config = Kreuzberg::Config::Extraction.new(
246
+ keywords: Kreuzberg::Config::Keywords.new(
247
+ algorithm: 'yake',
248
+ max_keywords: 10
249
+ )
250
+ )
251
+
252
+ rake_config = Kreuzberg::Config::Extraction.new(
253
+ keywords: Kreuzberg::Config::Keywords.new(
254
+ algorithm: 'rake',
255
+ max_keywords: 10
256
+ )
257
+ )
258
+
259
+ yake_result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: yake_config)
260
+ rake_result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: rake_config)
261
+
262
+ expect(yake_result).not_to be_nil
263
+ expect(yake_result.content).not_to be_nil
264
+ expect(yake_result.content.length).to be > 0
265
+
266
+ expect(rake_result).not_to be_nil
267
+ expect(rake_result.content).not_to be_nil
268
+ expect(rake_result.content.length).to be > 0
269
+ end
270
+
271
+ it 'algorithm-specific parameters affect extraction' do
272
+ text = 'Machine learning and artificial intelligence are transforming technology development and research.'
273
+
274
+ # YAKE with different window sizes
275
+ yake_config_small = Kreuzberg::Config::Extraction.new(
276
+ keywords: Kreuzberg::Config::Keywords.new(
277
+ algorithm: 'yake',
278
+ max_keywords: 10,
279
+ yake_params: Kreuzberg::Config::KeywordYakeParams.new(window_size: 2)
280
+ )
281
+ )
282
+
283
+ yake_config_large = Kreuzberg::Config::Extraction.new(
284
+ keywords: Kreuzberg::Config::Keywords.new(
285
+ algorithm: 'yake',
286
+ max_keywords: 10,
287
+ yake_params: Kreuzberg::Config::KeywordYakeParams.new(window_size: 4)
288
+ )
289
+ )
290
+
291
+ result_small = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: yake_config_small)
292
+ result_large = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: yake_config_large)
293
+
294
+ expect(result_small).not_to be_nil
295
+ expect(result_large).not_to be_nil
296
+ # Both should produce valid results
297
+ expect(result_small.content.length).to be > 0
298
+ expect(result_large.content.length).to be > 0
299
+ end
300
+
301
+ it 'RAKE with min_word_length parameter works' do
302
+ config = Kreuzberg::Config::Extraction.new(
303
+ keywords: Kreuzberg::Config::Keywords.new(
304
+ algorithm: 'rake',
305
+ max_keywords: 10,
306
+ rake_params: Kreuzberg::Config::KeywordRakeParams.new(
307
+ min_word_length: 2,
308
+ max_words_per_phrase: 4
309
+ )
310
+ )
311
+ )
312
+
313
+ text = 'Machine learning and artificial intelligence are transforming technology.'
314
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
315
+
316
+ expect(result).not_to be_nil
317
+ expect(result.content).not_to be_nil
318
+ expect(result.content.length).to be > 0
319
+ end
320
+ end
321
+
322
+ describe 'batch keyword extraction' do
323
+ it 'processes multiple texts with same configuration' do
324
+ config = Kreuzberg::Config::Extraction.new(
325
+ keywords: Kreuzberg::Config::Keywords.new(
326
+ algorithm: 'yake',
327
+ max_keywords: 5
328
+ )
329
+ )
330
+
331
+ texts = [
332
+ 'Machine learning and artificial intelligence are transforming technology.',
333
+ 'Deep learning neural networks enable advanced data science applications.',
334
+ 'Artificial intelligence enables predictions and automation globally.'
335
+ ]
336
+
337
+ results = texts.map { |text| Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config) }
338
+
339
+ expect(results.length).to eq(3)
340
+ results.each do |result|
341
+ expect(result).not_to be_nil
342
+ expect(result.content).not_to be_nil
343
+ end
344
+ end
345
+
346
+ it 'maintains consistency across batch processing' do
347
+ config = Kreuzberg::Config::Extraction.new(
348
+ keywords: Kreuzberg::Config::Keywords.new(
349
+ algorithm: 'yake',
350
+ max_keywords: 10
351
+ )
352
+ )
353
+
354
+ text = 'Machine learning and artificial intelligence are transforming technology development globally.'
355
+
356
+ result1 = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
357
+ result2 = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
358
+
359
+ expect(result1).not_to be_nil
360
+ expect(result2).not_to be_nil
361
+ expect(result1.content).to eq(result2.content)
362
+ end
363
+
364
+ it 'handles different configurations per batch item' do
365
+ text = 'Machine learning and artificial intelligence are transforming technology.'
366
+
367
+ configs = [
368
+ Kreuzberg::Config::Extraction.new(
369
+ keywords: Kreuzberg::Config::Keywords.new(algorithm: 'yake', max_keywords: 5)
370
+ ),
371
+ Kreuzberg::Config::Extraction.new(
372
+ keywords: Kreuzberg::Config::Keywords.new(algorithm: 'rake', max_keywords: 5)
373
+ ),
374
+ Kreuzberg::Config::Extraction.new(
375
+ keywords: Kreuzberg::Config::Keywords.new(algorithm: 'yake', max_keywords: 10)
376
+ )
377
+ ]
378
+
379
+ results = configs.map { |cfg| Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: cfg) }
380
+
381
+ expect(results.length).to eq(3)
382
+ results.each do |result|
383
+ expect(result).not_to be_nil
384
+ end
385
+ end
386
+ end
387
+
388
+ describe 'score normalization validation' do
389
+ it 'returns normalized scores between 0 and 1' do
390
+ config = Kreuzberg::Config::Extraction.new(
391
+ keywords: Kreuzberg::Config::Keywords.new(
392
+ algorithm: 'yake',
393
+ max_keywords: 20
394
+ )
395
+ )
396
+
397
+ text = 'Machine learning and artificial intelligence are transforming technology. Neural networks and deep learning enable data science applications.'
398
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
399
+
400
+ expect(result).not_to be_nil
401
+ expect(result.content).not_to be_nil
402
+ end
403
+
404
+ it 'validates score values are realistic' do
405
+ config = Kreuzberg::Config::Extraction.new(
406
+ keywords: Kreuzberg::Config::Keywords.new(
407
+ algorithm: 'yake',
408
+ max_keywords: 50
409
+ )
410
+ )
411
+
412
+ text = 'Artificial intelligence machine learning data science neural networks deep learning transforming technology.'
413
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
414
+
415
+ expect(result).not_to be_nil
416
+ expect(result.content).not_to be_nil
417
+ end
418
+
419
+ it 'handles score filtering with normalized ranges' do
420
+ scores_to_test = [0.0, 0.25, 0.5, 0.75, 1.0]
421
+
422
+ scores_to_test.each do |score_threshold|
423
+ config = Kreuzberg::Config::Extraction.new(
424
+ keywords: Kreuzberg::Config::Keywords.new(
425
+ algorithm: 'yake',
426
+ max_keywords: 100,
427
+ min_score: score_threshold
428
+ )
429
+ )
430
+
431
+ text = 'Machine learning artificial intelligence data science neural networks deep learning technology.'
432
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
433
+
434
+ expect(result).not_to be_nil
435
+ end
436
+ end
437
+
438
+ it 'ensures score consistency for same text' do
439
+ config = Kreuzberg::Config::Extraction.new(
440
+ keywords: Kreuzberg::Config::Keywords.new(
441
+ algorithm: 'yake',
442
+ max_keywords: 10
443
+ )
444
+ )
445
+
446
+ text = 'Machine learning and artificial intelligence transform technology.'
447
+ result1 = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
448
+ result2 = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
449
+
450
+ expect(result1).not_to be_nil
451
+ expect(result2).not_to be_nil
452
+ end
453
+ end
454
+
455
+ describe 'empty and edge cases' do
456
+ it 'handles very short text gracefully' do
457
+ config = Kreuzberg::Config::Extraction.new(
458
+ keywords: Kreuzberg::Config::Keywords.new(
459
+ algorithm: 'yake',
460
+ max_keywords: 5
461
+ )
462
+ )
463
+
464
+ text = 'AI'
465
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
466
+
467
+ expect(result).not_to be_nil
468
+ expect(result.content).not_to be_nil
469
+ end
470
+
471
+ it 'handles text with no obvious keywords' do
472
+ config = Kreuzberg::Config::Extraction.new(
473
+ keywords: Kreuzberg::Config::Keywords.new(
474
+ algorithm: 'yake',
475
+ max_keywords: 5
476
+ )
477
+ )
478
+
479
+ text = 'a b c d e'
480
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
481
+
482
+ expect(result).not_to be_nil
483
+ end
484
+
485
+ it 'handles text with repeated keywords' do
486
+ config = Kreuzberg::Config::Extraction.new(
487
+ keywords: Kreuzberg::Config::Keywords.new(
488
+ algorithm: 'yake',
489
+ max_keywords: 5
490
+ )
491
+ )
492
+
493
+ text = 'Machine machine machine learning learning learning artificial artificial artificial intelligence intelligence.'
494
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
495
+
496
+ expect(result).not_to be_nil
497
+ expect(result.content).not_to be_nil
498
+ end
499
+
500
+ it 'handles max_keywords of 0' do
501
+ config = Kreuzberg::Config::Extraction.new(
502
+ keywords: Kreuzberg::Config::Keywords.new(
503
+ algorithm: 'yake',
504
+ max_keywords: 0
505
+ )
506
+ )
507
+
508
+ text = 'Machine learning and artificial intelligence.'
509
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
510
+
511
+ expect(result).not_to be_nil
512
+ end
513
+
514
+ it 'handles large max_keywords value' do
515
+ config = Kreuzberg::Config::Extraction.new(
516
+ keywords: Kreuzberg::Config::Keywords.new(
517
+ algorithm: 'yake',
518
+ max_keywords: 1000
519
+ )
520
+ )
521
+
522
+ text = 'Machine learning and artificial intelligence are transforming technology.'
523
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
524
+
525
+ expect(result).not_to be_nil
526
+ end
527
+
528
+ it 'handles disabled keyword extraction' do
529
+ config = Kreuzberg::Config::Extraction.new
530
+ text = 'Machine learning and artificial intelligence.'
531
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
532
+
533
+ expect(result).not_to be_nil
534
+ expect(result.content).not_to be_nil
535
+ end
536
+
537
+ it 'handles keywords config with nil values' do
538
+ config = Kreuzberg::Config::Extraction.new(
539
+ keywords: Kreuzberg::Config::Keywords.new(
540
+ algorithm: nil,
541
+ max_keywords: nil
542
+ )
543
+ )
544
+
545
+ text = 'Machine learning and artificial intelligence.'
546
+ result = Kreuzberg.extract_bytes_sync(data: text, mime_type: 'text/plain', config: config)
547
+
548
+ expect(result).not_to be_nil
549
+ end
550
+ end
551
+
552
+ describe 'integration with Extraction config' do
553
+ it 'accepts Keywords config in Extraction' do
554
+ keywords = Kreuzberg::Config::Keywords.new(
555
+ algorithm: 'yake',
556
+ max_keywords: 10
557
+ )
558
+ config = Kreuzberg::Config::Extraction.new(keywords: keywords)
559
+
560
+ expect(config.keywords).to be_a(Kreuzberg::Config::Keywords)
561
+ expect(config.keywords.algorithm).to eq('yake')
562
+ end
563
+
564
+ it 'accepts keywords config as hash in Extraction' do
565
+ config = Kreuzberg::Config::Extraction.new(
566
+ keywords: {
567
+ algorithm: 'rake',
568
+ max_keywords: 15,
569
+ min_score: 0.3
570
+ }
571
+ )
572
+
573
+ expect(config.keywords).to be_a(Kreuzberg::Config::Keywords)
574
+ expect(config.keywords.algorithm).to eq('rake')
575
+ expect(config.keywords.max_keywords).to eq(15)
576
+ end
577
+
578
+ it 'includes keywords config in to_h' do
579
+ keywords = Kreuzberg::Config::Keywords.new(
580
+ algorithm: 'yake',
581
+ max_keywords: 10
582
+ )
583
+ config = Kreuzberg::Config::Extraction.new(keywords: keywords)
584
+
585
+ hash = config.to_h
586
+
587
+ expect(hash).to include(:keywords)
588
+ expect(hash[:keywords]).to be_a(Hash)
589
+ expect(hash[:keywords][:algorithm]).to eq('yake')
590
+ end
591
+
592
+ it 'handles nil keywords config' do
593
+ config = Kreuzberg::Config::Extraction.new(keywords: nil)
594
+
595
+ expect(config.keywords).to be_nil
596
+ hash = config.to_h
597
+ expect(hash[:keywords]).to be_nil
598
+ end
599
+ end
600
+ end