World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
A column header that is a number is not a period (#789)
WaylandYang527a61dd1873
diff --git a/crates/utopia-ingest/src/lib.rs b/crates/utopia-ingest/src/lib.rsindex b340695c..94a76e44 100644--- a/crates/utopia-ingest/src/lib.rs+++ b/crates/utopia-ingest/src/lib.rs@@ -173,12 +173,10 @@ mod table;pub mod transcript;pub use chunker::{chunk_segments, chunk_text, chunk_with_budget, ChunkPiece, BUDGET_TOKENS};-// 抽取那一侧要按值找回它那一列的表头(#729):写出这个表格式的模块,也负责读回它/// Decode fetched text with the same encoding detection as file ingestion.pub use parsers::plain_text as decode_text;pub use provenance::{Origin, Provenance, Segment};pub use reading::Reading;-pub use table::column_header;/// 解析产物:纯文本 + 可选结构信息。#[derive(Debug)]diff --git a/crates/utopia-ingest/src/table.rs b/crates/utopia-ingest/src/table.rsindex e56a5c9d..dc03b3ab 100644--- a/crates/utopia-ingest/src/table.rs+++ b/crates/utopia-ingest/src/table.rs@@ -603,160 +603,10 @@ fn collapse_spans(cols: Vec<usize>, headers: &[Row], data: &[(String, Row)]) ->out}-/// 一行切成格:每格的文字,以及它在这一行里的字节偏移。行首行尾的空段不算格。-/// **带着偏移**,因为表头里两列同名是常事(两个「Amount」),光按文字回头找会指错格-fn cells(row: &str) -> Vec<(&str, usize)> {- let lead = row.len() - row.trim_start().len();- let trimmed = row.trim();- let (inner, open) = match trimmed.strip_prefix('|') {- Some(rest) => (rest, 1),- None => (trimmed, 0),- };- let inner = inner.strip_suffix('|').unwrap_or(inner);- let mut at = lead + open;- let mut out = Vec::new();- for piece in inner.split('|') {- let pad = piece.len() - piece.trim_start().len();- out.push((piece.trim(), at + pad));- at += piece.len() + 1;- }- out-}--/// 比较一格与一个值:空白、千分位逗号、货币符号不算数,别的一个字都不能差。-/// **不做包含**:一格写着 `$1,234`,值是 `234` 的那一条不该认领它-fn same_number(cell: &str, value: &str) -> bool {- let strip = |s: &str| {- s.chars()- .filter(|c| !c.is_whitespace() && !is_currency(*c) && *c != ',')- .collect::<String>()- };- let (a, b) = (strip(cell), strip(value));- !a.is_empty() && a == b-}--/// 这个值落在这一行的哪一列,以及那一列的表头是什么(#729:财务表格单元的期间列)。-///-/// 一张财务表的列头写着期间(「Three Months Ended July 26, 2026」),值写在行里。**人是-/// 按列读表的,抽取却是按行读的**:一行五个数进了图,五条陈述除了值一模一样,没有任何-/// 东西说得出哪个数属于哪个期间。这里把那一列的表头找回来,交给时间解析去判它是不是一个-/// 期间——代码不认「Months Ended」这类字眼,只认位置。-///-/// 它宁可什么都不给,也不给错的:-///-/// * 这一行在这一块里出现不止一次——说不清是哪张表的哪一行;-/// * 这一行里没有恰好一格等于这个值——两格相等就分不出是哪一列;-/// * 这一行上面不是 `| --- |` 分隔线,或分隔线上面不是表头行;-/// * 表头那一格是空的,或一个数字都没有(「Amount」不是期间,而任何期间都会写出年份、-/// 日期或季度的数字)。-///-/// 返回表头那一格的文字和它在这一块里的字节偏移——一条提及要说得出自己在原文的哪个位置。-pub fn column_header<'a>(chunk: &'a str, row: &str, value: &str) -> Option<(&'a str, usize)> {- let row = row.trim();- if !row.starts_with('|') {- return None;- }- let at = chunk.find(row)?;- if chunk[at + row.len()..].contains(row) {- return None;- }- let mut hit = cells(row)- .into_iter()- .enumerate()- .filter(|(_, (c, _))| same_number(c, value));- let (col, _) = hit.next()?;- if hit.next().is_some() {- return None;- }- // 紧挨着这一行往上:一条分隔线,再上去一行是表头。位置用 rfind 从原文里量,- // 不靠换行符占几个字节- let before = &chunk[..at];- let mut lines = before.lines().rev();- let sep = lines.next()?;- if !sep.trim_start().starts_with("| ---") {- return None;- }- let head = lines.next()?;- if !head.trim_start().starts_with('|') {- return None;- }- let sep_at = before.rfind(sep)?;- let head_at = before[..sep_at].rfind(head)?;- let (cell, in_line) = *cells(head).get(col)?;- if cell.is_empty() || !cell.chars().any(|c| c.is_ascii_digit()) {- return None;- }- let from = head_at + in_line;- Some((&chunk[from..from + cell.len()], from))-}-#[cfg(test)]mod tests {use super::*;- /// #729:一行五个数,每个数的期间在它那一列的表头上- const COSTS: &str = "(A) Acquisition-related and other costs are comprised of amortization.\n\n\-| | Three Months Ended July 26, 2026 | Three Months Ended April 26, 2026 | Six Months Ended July 26, 2026 |\n\-| --- | --- | --- | --- |\n\-| Cost of revenue | $46 | $47 | $93 |\n\-| Sales, general and administrative | $6 | $5 | $11 |\n";-- #[test]- fn a_cell_takes_the_period_of_its_own_column() {- let row = "| Cost of revenue | $46 | $47 | $93 |";- let (head, at) = column_header(COSTS, row, "$46").expect("46 是第一列的值");- assert_eq!(head, "Three Months Ended July 26, 2026");- assert_eq!(&COSTS[at..at + head.len()], head, "偏移指回原文那一格");- assert_eq!(- column_header(COSTS, row, "$47").unwrap().0,- "Three Months Ended April 26, 2026",- "同一行的下一个数换了一列,期间也跟着换"- );- assert_eq!(- column_header(COSTS, row, "93").unwrap().0,- "Six Months Ended July 26, 2026",- "货币符号与千分位不算数"- );- }-- #[test]- fn a_header_that_names_no_time_gives_nothing() {- let t = "| Item | Amount |\n| --- | --- |\n| Cost of revenue | $46 |\n";- assert_eq!(column_header(t, "| Cost of revenue | $46 |", "$46"), None);- }-- #[test]- fn an_ambiguous_cell_gives_nothing() {- // 同一行两格相同:说不出是哪一列- let t = "| | Q1 2026 | Q2 2026 |\n| --- | --- | --- |\n| Cost | $46 | $46 |\n";- assert_eq!(column_header(t, "| Cost | $46 | $46 |", "$46"), None);- // 同一块里两张表有一模一样的行:说不出是哪张表- let twice = format!("{COSTS}\n{COSTS}");- assert_eq!(- column_header(&twice, "| Cost of revenue | $46 | $47 | $93 |", "$46"),- None- );- }-- #[test]- fn a_row_with_no_table_above_it_gives_nothing() {- // 没有分隔线就没有表头- let t = "| Cost of revenue | $46 |\n";- assert_eq!(column_header(t, "| Cost of revenue | $46 |", "$46"), None);- // 引文不是一行表格- assert_eq!(- column_header(COSTS, "Acquisition-related and other costs", "$46"),- None- );- // 一格写着 $1,234,值是 234 的不该认领它- let t2 = "| | Q1 2026 |\n| --- | --- |\n| Cost | $1,234 |\n";- assert_eq!(column_header(t2, "| Cost | $1,234 |", "234"), None);- assert_eq!(- column_header(t2, "| Cost | $1,234 |", "1234").unwrap().0,- "Q1 2026"- );- }-fn render(html: &str) -> String {let (_, tables) = lift_tables(html);tables.join("\n=====\n")diff --git a/crates/utopia-server/src/extraction_open.rs b/crates/utopia-server/src/extraction_open.rsindex fac83eb1..6b76cad7 100644--- a/crates/utopia-server/src/extraction_open.rs+++ b/crates/utopia-server/src/extraction_open.rs@@ -580,20 +580,6 @@ pub(crate) async fn run_open(}}}- // **表格单元的期间在它那一列的表头上**(#729)。模型自己说了时间就不动它——- // 它看得见整块原文,说得出的比一根列头多。这一条不是模型报的,所以不走- // `time_not_in_quote`:它的出处是位置(这个值在这一行的第几格),- // 而那一格的表头上写着期间。它是不是一个期间,由时间解析去判(0045:- // 模型读、代码算),这里一个字眼都不认- if !time_words.iter().any(|(_, _, role)| *role == "when") {- if let (Some(v), Some((q, _))) = (stated_value, quote) {- if let Some((head, at)) = utopia_ingest::column_header(&chunk.text, q, v) {- if let Ok(at) = i32::try_from(at) {- time_words.push((head, at, "when"));- }- }- }- }if await_nod {// 记忆日志:一切原样进待确认表(0015),人点头时 `pending::confirm` 才把它// 落成开放陈述——同样的短语、限定、时间词、引文偏移