synapse_core/ingest/
mod.rs1use crate::store::{IngestTriple, SynapseStore};
2use anyhow::{Context, Result};
3use std::fs;
4use std::path::Path;
5use std::sync::Arc;
6
7pub mod extractor;
8pub mod processor;
9
10use extractor::{CsvExtractor, Extractor, MarkdownExtractor};
11
12pub struct IngestionEngine {
13 store: Arc<SynapseStore>,
14}
15
16impl IngestionEngine {
17 pub fn new(store: Arc<SynapseStore>) -> Self {
18 Self { store }
19 }
20
21 pub async fn ingest_file(&self, path: &Path, _namespace: &str) -> Result<u32> {
22 let content =
23 fs::read_to_string(path).with_context(|| format!("Failed to read file: {:?}", path))?;
24
25 let extension = path.extension().and_then(|s| s.to_str()).unwrap_or("");
26
27 let result = match extension {
28 "csv" => CsvExtractor::new().extract(&content)?,
29 "md" | "markdown" => MarkdownExtractor.extract(&content)?,
30 _ => anyhow::bail!("Unsupported file type: {}", extension),
31 };
32
33 let ingest_triples = result
35 .triples
36 .into_iter()
37 .map(|(s, p, o)| {
38 IngestTriple {
39 subject: s,
40 predicate: p,
41 object: o,
42 provenance: None, }
44 })
45 .collect();
46
47 let (added, _) = self.store.ingest_triples(ingest_triples).await?;
48 Ok(added)
49 }
50}