kreuzberg 4.0.0.pre.rc.6 → 4.0.0.rc1

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 (175) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -6
  3. data/.rubocop.yaml +534 -1
  4. data/Gemfile +2 -1
  5. data/Gemfile.lock +11 -11
  6. data/README.md +5 -10
  7. data/examples/async_patterns.rb +0 -1
  8. data/ext/kreuzberg_rb/extconf.rb +0 -10
  9. data/ext/kreuzberg_rb/native/Cargo.toml +15 -23
  10. data/ext/kreuzberg_rb/native/build.rs +2 -0
  11. data/ext/kreuzberg_rb/native/include/ieeefp.h +1 -1
  12. data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +1 -1
  13. data/ext/kreuzberg_rb/native/include/strings.h +2 -2
  14. data/ext/kreuzberg_rb/native/include/unistd.h +1 -1
  15. data/ext/kreuzberg_rb/native/src/lib.rs +16 -75
  16. data/kreuzberg.gemspec +14 -57
  17. data/lib/kreuzberg/cache_api.rb +0 -1
  18. data/lib/kreuzberg/cli.rb +2 -2
  19. data/lib/kreuzberg/config.rb +2 -9
  20. data/lib/kreuzberg/errors.rb +7 -75
  21. data/lib/kreuzberg/extraction_api.rb +0 -1
  22. data/lib/kreuzberg/setup_lib_path.rb +0 -1
  23. data/lib/kreuzberg/version.rb +1 -1
  24. data/lib/kreuzberg.rb +0 -21
  25. data/pkg/kreuzberg-4.0.0.rc1.gem +0 -0
  26. data/sig/kreuzberg.rbs +3 -55
  27. data/spec/binding/cli_proxy_spec.rb +4 -2
  28. data/spec/binding/cli_spec.rb +11 -12
  29. data/spec/examples.txt +104 -0
  30. data/spec/fixtures/config.yaml +1 -0
  31. data/spec/spec_helper.rb +1 -1
  32. data/vendor/kreuzberg/Cargo.toml +42 -112
  33. data/vendor/kreuzberg/README.md +2 -2
  34. data/vendor/kreuzberg/build.rs +4 -18
  35. data/vendor/kreuzberg/src/bin/profile_extract.rs +455 -0
  36. data/vendor/kreuzberg/src/cache/mod.rs +3 -27
  37. data/vendor/kreuzberg/src/core/batch_mode.rs +0 -60
  38. data/vendor/kreuzberg/src/core/extractor.rs +81 -202
  39. data/vendor/kreuzberg/src/core/io.rs +2 -4
  40. data/vendor/kreuzberg/src/core/mime.rs +12 -2
  41. data/vendor/kreuzberg/src/core/mod.rs +1 -4
  42. data/vendor/kreuzberg/src/core/pipeline.rs +33 -111
  43. data/vendor/kreuzberg/src/embeddings.rs +16 -125
  44. data/vendor/kreuzberg/src/error.rs +1 -1
  45. data/vendor/kreuzberg/src/extraction/docx.rs +1 -1
  46. data/vendor/kreuzberg/src/extraction/image.rs +13 -13
  47. data/vendor/kreuzberg/src/extraction/libreoffice.rs +1 -0
  48. data/vendor/kreuzberg/src/extraction/mod.rs +5 -9
  49. data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +0 -2
  50. data/vendor/kreuzberg/src/extraction/pandoc/batch.rs +275 -0
  51. data/vendor/kreuzberg/src/extraction/pandoc/mime_types.rs +178 -0
  52. data/vendor/kreuzberg/src/extraction/pandoc/mod.rs +491 -0
  53. data/vendor/kreuzberg/src/extraction/pandoc/server.rs +496 -0
  54. data/vendor/kreuzberg/src/extraction/pandoc/subprocess.rs +1188 -0
  55. data/vendor/kreuzberg/src/extraction/pandoc/version.rs +162 -0
  56. data/vendor/kreuzberg/src/extractors/archive.rs +0 -21
  57. data/vendor/kreuzberg/src/extractors/docx.rs +128 -16
  58. data/vendor/kreuzberg/src/extractors/email.rs +0 -14
  59. data/vendor/kreuzberg/src/extractors/excel.rs +20 -19
  60. data/vendor/kreuzberg/src/extractors/html.rs +154 -137
  61. data/vendor/kreuzberg/src/extractors/image.rs +4 -7
  62. data/vendor/kreuzberg/src/extractors/mod.rs +9 -106
  63. data/vendor/kreuzberg/src/extractors/pandoc.rs +201 -0
  64. data/vendor/kreuzberg/src/extractors/pdf.rs +15 -12
  65. data/vendor/kreuzberg/src/extractors/pptx.rs +3 -17
  66. data/vendor/kreuzberg/src/extractors/structured.rs +0 -14
  67. data/vendor/kreuzberg/src/extractors/text.rs +5 -23
  68. data/vendor/kreuzberg/src/extractors/xml.rs +0 -7
  69. data/vendor/kreuzberg/src/keywords/rake.rs +1 -0
  70. data/vendor/kreuzberg/src/lib.rs +1 -4
  71. data/vendor/kreuzberg/src/mcp/mod.rs +1 -1
  72. data/vendor/kreuzberg/src/mcp/server.rs +3 -5
  73. data/vendor/kreuzberg/src/ocr/processor.rs +2 -18
  74. data/vendor/kreuzberg/src/pdf/error.rs +1 -1
  75. data/vendor/kreuzberg/src/pdf/table.rs +44 -17
  76. data/vendor/kreuzberg/src/pdf/text.rs +3 -0
  77. data/vendor/kreuzberg/src/plugins/extractor.rs +5 -8
  78. data/vendor/kreuzberg/src/plugins/ocr.rs +11 -2
  79. data/vendor/kreuzberg/src/plugins/processor.rs +1 -2
  80. data/vendor/kreuzberg/src/plugins/registry.rs +0 -13
  81. data/vendor/kreuzberg/src/plugins/validator.rs +8 -9
  82. data/vendor/kreuzberg/src/stopwords/mod.rs +2 -2
  83. data/vendor/kreuzberg/src/types.rs +12 -42
  84. data/vendor/kreuzberg/tests/batch_orchestration.rs +5 -19
  85. data/vendor/kreuzberg/tests/batch_processing.rs +3 -15
  86. data/vendor/kreuzberg/tests/chunking_offset_demo.rs +92 -0
  87. data/vendor/kreuzberg/tests/concurrency_stress.rs +1 -17
  88. data/vendor/kreuzberg/tests/config_features.rs +0 -18
  89. data/vendor/kreuzberg/tests/config_loading_tests.rs +39 -15
  90. data/vendor/kreuzberg/tests/core_integration.rs +7 -24
  91. data/vendor/kreuzberg/tests/csv_integration.rs +81 -71
  92. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +25 -23
  93. data/vendor/kreuzberg/tests/pandoc_integration.rs +503 -0
  94. data/vendor/kreuzberg/tests/pipeline_integration.rs +1 -0
  95. data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +1 -0
  96. data/vendor/kreuzberg/tests/registry_integration_tests.rs +22 -1
  97. data/vendor/kreuzberg/tests/security_validation.rs +1 -12
  98. metadata +25 -90
  99. data/.rubocop.yml +0 -538
  100. data/ext/kreuzberg_rb/native/Cargo.lock +0 -6535
  101. data/lib/kreuzberg/error_context.rb +0 -32
  102. data/vendor/kreuzberg/benches/otel_overhead.rs +0 -48
  103. data/vendor/kreuzberg/src/extraction/markdown.rs +0 -213
  104. data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +0 -287
  105. data/vendor/kreuzberg/src/extractors/bibtex.rs +0 -469
  106. data/vendor/kreuzberg/src/extractors/docbook.rs +0 -502
  107. data/vendor/kreuzberg/src/extractors/epub.rs +0 -707
  108. data/vendor/kreuzberg/src/extractors/fictionbook.rs +0 -491
  109. data/vendor/kreuzberg/src/extractors/fictionbook.rs.backup2 +0 -738
  110. data/vendor/kreuzberg/src/extractors/jats.rs +0 -1051
  111. data/vendor/kreuzberg/src/extractors/jupyter.rs +0 -367
  112. data/vendor/kreuzberg/src/extractors/latex.rs +0 -652
  113. data/vendor/kreuzberg/src/extractors/markdown.rs +0 -700
  114. data/vendor/kreuzberg/src/extractors/odt.rs +0 -628
  115. data/vendor/kreuzberg/src/extractors/opml.rs +0 -634
  116. data/vendor/kreuzberg/src/extractors/orgmode.rs +0 -528
  117. data/vendor/kreuzberg/src/extractors/rst.rs +0 -576
  118. data/vendor/kreuzberg/src/extractors/rtf.rs +0 -810
  119. data/vendor/kreuzberg/src/extractors/security.rs +0 -484
  120. data/vendor/kreuzberg/src/extractors/security_tests.rs +0 -367
  121. data/vendor/kreuzberg/src/extractors/typst.rs +0 -650
  122. data/vendor/kreuzberg/src/panic_context.rs +0 -154
  123. data/vendor/kreuzberg/tests/api_extract_multipart.rs +0 -52
  124. data/vendor/kreuzberg/tests/bibtex_parity_test.rs +0 -421
  125. data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +0 -498
  126. data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +0 -370
  127. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +0 -275
  128. data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +0 -228
  129. data/vendor/kreuzberg/tests/html_table_test.rs +0 -551
  130. data/vendor/kreuzberg/tests/instrumentation_test.rs +0 -139
  131. data/vendor/kreuzberg/tests/jats_extractor_tests.rs +0 -639
  132. data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +0 -704
  133. data/vendor/kreuzberg/tests/latex_extractor_tests.rs +0 -496
  134. data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +0 -490
  135. data/vendor/kreuzberg/tests/odt_extractor_tests.rs +0 -695
  136. data/vendor/kreuzberg/tests/opml_extractor_tests.rs +0 -616
  137. data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +0 -822
  138. data/vendor/kreuzberg/tests/rst_extractor_tests.rs +0 -692
  139. data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +0 -776
  140. data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +0 -1259
  141. data/vendor/kreuzberg/tests/typst_extractor_tests.rs +0 -647
  142. data/vendor/rb-sys/.cargo-ok +0 -1
  143. data/vendor/rb-sys/.cargo_vcs_info.json +0 -6
  144. data/vendor/rb-sys/Cargo.lock +0 -393
  145. data/vendor/rb-sys/Cargo.toml +0 -70
  146. data/vendor/rb-sys/Cargo.toml.orig +0 -57
  147. data/vendor/rb-sys/LICENSE-APACHE +0 -190
  148. data/vendor/rb-sys/LICENSE-MIT +0 -21
  149. data/vendor/rb-sys/bin/release.sh +0 -21
  150. data/vendor/rb-sys/build/features.rs +0 -108
  151. data/vendor/rb-sys/build/main.rs +0 -246
  152. data/vendor/rb-sys/build/stable_api_config.rs +0 -153
  153. data/vendor/rb-sys/build/version.rs +0 -48
  154. data/vendor/rb-sys/readme.md +0 -36
  155. data/vendor/rb-sys/src/bindings.rs +0 -21
  156. data/vendor/rb-sys/src/hidden.rs +0 -11
  157. data/vendor/rb-sys/src/lib.rs +0 -34
  158. data/vendor/rb-sys/src/macros.rs +0 -371
  159. data/vendor/rb-sys/src/memory.rs +0 -53
  160. data/vendor/rb-sys/src/ruby_abi_version.rs +0 -38
  161. data/vendor/rb-sys/src/special_consts.rs +0 -31
  162. data/vendor/rb-sys/src/stable_api/compiled.c +0 -179
  163. data/vendor/rb-sys/src/stable_api/compiled.rs +0 -257
  164. data/vendor/rb-sys/src/stable_api/ruby_2_6.rs +0 -316
  165. data/vendor/rb-sys/src/stable_api/ruby_2_7.rs +0 -316
  166. data/vendor/rb-sys/src/stable_api/ruby_3_0.rs +0 -324
  167. data/vendor/rb-sys/src/stable_api/ruby_3_1.rs +0 -317
  168. data/vendor/rb-sys/src/stable_api/ruby_3_2.rs +0 -315
  169. data/vendor/rb-sys/src/stable_api/ruby_3_3.rs +0 -326
  170. data/vendor/rb-sys/src/stable_api/ruby_3_4.rs +0 -327
  171. data/vendor/rb-sys/src/stable_api.rs +0 -261
  172. data/vendor/rb-sys/src/symbol.rs +0 -31
  173. data/vendor/rb-sys/src/tracking_allocator.rs +0 -332
  174. data/vendor/rb-sys/src/utils.rs +0 -89
  175. data/vendor/rb-sys/src/value_type.rs +0 -7
@@ -1,367 +0,0 @@
1
- //! Jupyter Notebook extractor for .ipynb files.
2
- //!
3
- //! This extractor provides native Rust parsing of Jupyter notebooks,
4
- //! extracting:
5
- //! - Notebook metadata (kernelspec, language_info, nbformat)
6
- //! - Cell content (markdown and code cells in order)
7
- //! - Cell outputs (text, HTML, images)
8
- //! - Cell metadata (execution_count, tags)
9
- //!
10
- //! Requires the `office` feature.
11
-
12
- #[cfg(feature = "office")]
13
- use crate::Result;
14
- #[cfg(feature = "office")]
15
- use crate::core::config::ExtractionConfig;
16
- #[cfg(feature = "office")]
17
- use crate::plugins::{DocumentExtractor, Plugin};
18
- #[cfg(feature = "office")]
19
- use crate::types::{ExtractionResult, Metadata};
20
- #[cfg(feature = "office")]
21
- use async_trait::async_trait;
22
- #[cfg(feature = "office")]
23
- use serde_json::{Value, json};
24
- #[cfg(feature = "office")]
25
- use std::collections::HashMap;
26
-
27
- /// Jupyter Notebook extractor.
28
- ///
29
- /// Extracts content from Jupyter notebook JSON files, including:
30
- /// - Notebook metadata (kernel, language, nbformat version)
31
- /// - Cell content (code and markdown)
32
- /// - Cell outputs (text, HTML, etc.)
33
- /// - Cell-level metadata (tags, execution counts)
34
- #[cfg(feature = "office")]
35
- pub struct JupyterExtractor;
36
-
37
- #[cfg(feature = "office")]
38
- impl JupyterExtractor {
39
- /// Create a new Jupyter extractor.
40
- pub fn new() -> Self {
41
- Self
42
- }
43
-
44
- /// Extract content from a Jupyter notebook.
45
- fn extract_notebook(content: &[u8]) -> Result<(String, HashMap<String, Value>)> {
46
- let notebook: Value = serde_json::from_slice(content)
47
- .map_err(|e| crate::KreuzbergError::parsing(format!("Failed to parse JSON: {}", e)))?;
48
-
49
- let mut extracted_content = String::new();
50
- let mut metadata = HashMap::new();
51
-
52
- if let Some(notebook_metadata) = notebook.get("metadata").and_then(|m| m.as_object()) {
53
- if let Some(kernelspec) = notebook_metadata.get("kernelspec")
54
- && let Some(name) = kernelspec.get("name").and_then(|n| n.as_str())
55
- {
56
- extracted_content.push_str(&format!("Kernelspec: {}\n", name));
57
- metadata.insert("kernelspec".to_string(), kernelspec.clone());
58
- }
59
-
60
- if let Some(language_info) = notebook_metadata.get("language_info")
61
- && let Some(name) = language_info.get("name").and_then(|n| n.as_str())
62
- {
63
- extracted_content.push_str(&format!("Language: {}\n", name));
64
- metadata.insert("language_info".to_string(), language_info.clone());
65
- }
66
- }
67
-
68
- if let Some(nbformat) = notebook.get("nbformat") {
69
- extracted_content.push_str(&format!("NBFormat: {}\n", nbformat));
70
- metadata.insert("nbformat".to_string(), nbformat.clone());
71
- }
72
-
73
- extracted_content.push('\n');
74
-
75
- if let Some(cells) = notebook.get("cells").and_then(|c| c.as_array()) {
76
- for (cell_idx, cell) in cells.iter().enumerate() {
77
- Self::extract_cell(cell, cell_idx, &mut extracted_content, &mut metadata)?;
78
- }
79
- }
80
-
81
- Ok((extracted_content, metadata))
82
- }
83
-
84
- /// Extract content from a single cell.
85
- fn extract_cell(
86
- cell: &Value,
87
- cell_idx: usize,
88
- content: &mut String,
89
- _metadata: &mut HashMap<String, Value>,
90
- ) -> Result<()> {
91
- let cell_type = cell.get("cell_type").and_then(|t| t.as_str()).unwrap_or("unknown");
92
-
93
- let cell_id = cell.get("id").and_then(|id| id.as_str());
94
-
95
- if let Some(id) = cell_id {
96
- content.push_str(&format!(":::: {{#{} .cell .{}}}\n", id, cell_type));
97
- } else {
98
- content.push_str(&format!(":::: {{#cell_{} .cell .{}}}\n", cell_idx, cell_type));
99
- }
100
-
101
- if let Some(cell_metadata) = cell.get("metadata").and_then(|m| m.as_object())
102
- && let Some(tags) = cell_metadata.get("tags").and_then(|t| t.as_array())
103
- {
104
- let tag_strs: Vec<String> = tags
105
- .iter()
106
- .filter_map(|tag| tag.as_str().map(|s| s.to_string()))
107
- .collect();
108
- if !tag_strs.is_empty() {
109
- content.push_str(&format!(" tags=[{}]", tag_strs.join(", ")));
110
- }
111
- }
112
- content.push('\n');
113
-
114
- match cell_type {
115
- "markdown" => Self::extract_markdown_cell(cell, content)?,
116
- "code" => Self::extract_code_cell(cell, content)?,
117
- "raw" => Self::extract_raw_cell(cell, content)?,
118
- _ => {
119
- content.push_str(&format!("Unknown cell type: {}\n", cell_type));
120
- }
121
- }
122
-
123
- content.push_str("::::\n\n");
124
- Ok(())
125
- }
126
-
127
- /// Extract markdown cell content.
128
- fn extract_markdown_cell(cell: &Value, content: &mut String) -> Result<()> {
129
- if let Some(source) = cell.get("source") {
130
- let cell_text = Self::extract_source(source);
131
- content.push_str(&cell_text);
132
- }
133
- Ok(())
134
- }
135
-
136
- /// Extract code cell content and outputs.
137
- fn extract_code_cell(cell: &Value, content: &mut String) -> Result<()> {
138
- if let Some(exec_count) = cell.get("execution_count")
139
- && !exec_count.is_null()
140
- {
141
- content.push_str(&format!("::: {{execution_count={}}}\n", exec_count));
142
- }
143
-
144
- if let Some(source) = cell.get("source") {
145
- let cell_text = Self::extract_source(source);
146
- content.push_str("```python\n");
147
- content.push_str(&cell_text);
148
- content.push_str("```\n");
149
- }
150
-
151
- if let Some(outputs) = cell.get("outputs").and_then(|o| o.as_array()) {
152
- for output in outputs {
153
- Self::extract_output(output, content)?;
154
- }
155
- }
156
-
157
- Ok(())
158
- }
159
-
160
- /// Extract raw cell content.
161
- fn extract_raw_cell(cell: &Value, content: &mut String) -> Result<()> {
162
- if let Some(source) = cell.get("source") {
163
- let cell_text = Self::extract_source(source);
164
- content.push_str(&cell_text);
165
- }
166
- Ok(())
167
- }
168
-
169
- /// Extract source content from various formats.
170
- ///
171
- /// Source can be either a string or an array of strings.
172
- fn extract_source(source: &Value) -> String {
173
- match source {
174
- Value::String(s) => s.clone(),
175
- Value::Array(arr) => arr.iter().filter_map(|v| v.as_str()).collect::<Vec<_>>().join(""),
176
- _ => String::new(),
177
- }
178
- }
179
-
180
- /// Extract output from a cell.
181
- fn extract_output(output: &Value, content: &mut String) -> Result<()> {
182
- let output_type = output.get("output_type").and_then(|t| t.as_str()).unwrap_or("unknown");
183
-
184
- content.push_str(&format!("::: {{.output .{}", output_type));
185
-
186
- if let Some(exec_count) = output.get("execution_count")
187
- && !exec_count.is_null()
188
- {
189
- content.push_str(&format!(" execution_count={}", exec_count));
190
- }
191
-
192
- content.push_str("}\n");
193
-
194
- match output_type {
195
- "stream" => Self::extract_stream_output(output, content)?,
196
- "execute_result" | "display_data" => Self::extract_data_output(output, content)?,
197
- "error" => Self::extract_error_output(output, content)?,
198
- _ => {
199
- content.push_str(&format!("Unknown output type: {}\n", output_type));
200
- }
201
- }
202
-
203
- content.push_str(":::\n");
204
- Ok(())
205
- }
206
-
207
- /// Extract stream output (stdout, stderr).
208
- fn extract_stream_output(output: &Value, content: &mut String) -> Result<()> {
209
- if let Some(name) = output.get("name").and_then(|n| n.as_str()) {
210
- content.push_str(&format!("Stream: {}\n", name));
211
- }
212
-
213
- if let Some(text) = output.get("text") {
214
- let text_content = Self::extract_source(text);
215
- content.push_str(&text_content);
216
- }
217
-
218
- Ok(())
219
- }
220
-
221
- /// Extract data output (execute_result or display_data).
222
- fn extract_data_output(output: &Value, content: &mut String) -> Result<()> {
223
- if let Some(data) = output.get("data").and_then(|d| d.as_object()) {
224
- let mime_types = vec![
225
- "text/markdown",
226
- "text/html",
227
- "image/svg+xml",
228
- "image/png",
229
- "image/jpeg",
230
- "application/json",
231
- "text/plain",
232
- ];
233
-
234
- for mime_type in mime_types {
235
- if let Some(mime_content) = data.get(mime_type) {
236
- content.push_str(&format!("MIME: {}\n", mime_type));
237
- let mime_text = Self::extract_source(mime_content);
238
- if !mime_text.is_empty() {
239
- content.push_str(&mime_text);
240
- content.push('\n');
241
- }
242
- }
243
- }
244
- }
245
-
246
- Ok(())
247
- }
248
-
249
- /// Extract error output.
250
- fn extract_error_output(output: &Value, content: &mut String) -> Result<()> {
251
- if let Some(ename) = output.get("ename").and_then(|e| e.as_str()) {
252
- content.push_str(&format!("Error: {}\n", ename));
253
- }
254
-
255
- if let Some(evalue) = output.get("evalue").and_then(|e| e.as_str()) {
256
- content.push_str(&format!("Value: {}\n", evalue));
257
- }
258
-
259
- if let Some(traceback) = output.get("traceback").and_then(|t| t.as_array()) {
260
- for line in traceback {
261
- if let Some(line_str) = line.as_str() {
262
- content.push_str(line_str);
263
- content.push('\n');
264
- }
265
- }
266
- }
267
-
268
- Ok(())
269
- }
270
- }
271
-
272
- #[cfg(feature = "office")]
273
- impl Default for JupyterExtractor {
274
- fn default() -> Self {
275
- Self::new()
276
- }
277
- }
278
-
279
- #[cfg(feature = "office")]
280
- impl Plugin for JupyterExtractor {
281
- fn name(&self) -> &str {
282
- "jupyter-extractor"
283
- }
284
-
285
- fn version(&self) -> String {
286
- env!("CARGO_PKG_VERSION").to_string()
287
- }
288
-
289
- fn initialize(&self) -> Result<()> {
290
- Ok(())
291
- }
292
-
293
- fn shutdown(&self) -> Result<()> {
294
- Ok(())
295
- }
296
-
297
- fn description(&self) -> &str {
298
- "Extracts content from Jupyter notebooks (.ipynb files)"
299
- }
300
-
301
- fn author(&self) -> &str {
302
- "Kreuzberg Team"
303
- }
304
- }
305
-
306
- #[cfg(feature = "office")]
307
- #[async_trait]
308
- impl DocumentExtractor for JupyterExtractor {
309
- #[cfg_attr(
310
- feature = "otel",
311
- tracing::instrument(
312
- skip(self, content, _config),
313
- fields(
314
- extractor.name = self.name(),
315
- content.size_bytes = content.len(),
316
- )
317
- )
318
- )]
319
- async fn extract_bytes(
320
- &self,
321
- content: &[u8],
322
- mime_type: &str,
323
- _config: &ExtractionConfig,
324
- ) -> Result<ExtractionResult> {
325
- let (extracted_content, additional_metadata) = Self::extract_notebook(content)?;
326
-
327
- let mut metadata_additional = HashMap::new();
328
- for (key, value) in additional_metadata {
329
- metadata_additional.insert(key, json!(value));
330
- }
331
-
332
- Ok(ExtractionResult {
333
- content: extracted_content,
334
- mime_type: mime_type.to_string(),
335
- metadata: Metadata {
336
- additional: metadata_additional,
337
- ..Default::default()
338
- },
339
- tables: vec![],
340
- detected_languages: None,
341
- chunks: None,
342
- images: None,
343
- })
344
- }
345
-
346
- fn supported_mime_types(&self) -> &[&str] {
347
- &["application/x-ipynb+json"]
348
- }
349
-
350
- fn priority(&self) -> i32 {
351
- 50
352
- }
353
- }
354
-
355
- #[cfg(test)]
356
- mod tests {
357
- use super::*;
358
-
359
- #[test]
360
- fn test_jupyter_extractor_plugin_interface() {
361
- let extractor = JupyterExtractor::new();
362
- assert_eq!(extractor.name(), "jupyter-extractor");
363
- assert_eq!(extractor.version(), env!("CARGO_PKG_VERSION"));
364
- assert_eq!(extractor.priority(), 50);
365
- assert!(extractor.supported_mime_types().contains(&"application/x-ipynb+json"));
366
- }
367
- }