Changesets · Branches · Tags · Compare
| Changeset | e64f23218dcf13edf6a8256951fcd4584f1c409ab2953f5cbf4a3a4a9d4e62a5 |
|---|---|
| Author | WaylandYang <145302500+WaylandYang@users.noreply.github.com> · 2026-08-31 11:50 +08:00 |
| Committer | GitHub <noreply@github.com> · 2026-08-31 11:50 +08:00 |
| Parents | 2d52f7a2fb65 |
2 files changed
modified crates/utopia-server/src/extraction.rs +23 −8
| @@ -798,7 +798,7 @@ | ||
| 798 | 798 | // |
| 799 | 799 | // **但绝不静默。** 掰正要留信号:0001 反对的是「用可能错的声明驱动 |
| 800 | 800 | // 自动动作」,而看得见、可复查、可反悔的动作不属于那一类。 |
| 801 | - let (subject_id, object_id) = if let Some(pid) = predicate_id { | |
| 801 | + let (predicate_id, subject_id, object_id) = if let Some(pid) = predicate_id { | |
| 802 | 802 | // 类型**从库里的实体读**,不用抽取器手上那份 `entity_type_of`: |
| 803 | 803 | // 那份只覆盖模型在这一块里声明过的实体,而宾语常是别处已存在的实体, |
| 804 | 804 | // 这一块没重新声明它,于是查不到、判不了、掰不动。实测差别不小—— |
| @@ -825,26 +825,41 @@ | ||
| 825 | 825 | )), |
| 826 | 826 | ) |
| 827 | 827 | .await; |
| 828 | - (object_id, subject_id) | |
| 828 | + (Some(pid), object_id, subject_id) | |
| 829 | 829 | } else { |
| 830 | - // 对调也不合法:这是选错了关系或类型判错,不是方向问题。 | |
| 831 | - // 照原样落库 + 记信号,交给人看——**不猜** | |
| 830 | + // **对调也不合法 → 退回没有谓词。** | |
| 831 | + // | |
| 832 | + // 这不是方向问题,是这个关系压根不适用:schema.org 的 | |
| 833 | + // `affectedBy` 是医学检验用的,模型要表达「受……影响」时按名字 | |
| 834 | + // 撞了上来;`amount` 属于融资工具而不是公司,模型没造那个中间 | |
| 835 | + // 节点就把边挂到了公司上。 | |
| 836 | + // | |
| 837 | + // 从前照原样落库,等于**用本体的名义说一件本体不同意的事**—— | |
| 838 | + // 图上写着 "OpenAI affectedBy …",读者会以为那是一条医学断言。 | |
| 839 | + // 这是自信的错误,比空谓词严重得多。 | |
| 840 | + // | |
| 841 | + // 退回空谓词不丢信息:原词落进 `fact_evidence.proposed_predicate`, | |
| 842 | + // 显示时由 `fact_surface_predicate()` 取回(0010)。主宾、时间、 | |
| 843 | + // 证据全都留着,只是不再冒认一个本体关系。**诚实的沉默。** | |
| 832 | 844 | drop_signal( |
| 833 | 845 | state, |
| 834 | 846 | doc.kb_id, |
| 835 | 847 | document_id, |
| 836 | 848 | utopia_store::extraction_drops::reason::DOMAIN_MISMATCH, |
| 837 | 849 | &f.predicate, |
| 838 | - Some(&format!("{} — {} →", f.subject, f.predicate)), | |
| 850 | + Some(&format!( | |
| 851 | + "{} — {} → 主宾都对不上,退回原文说法", | |
| 852 | + f.subject, f.predicate | |
| 853 | + )), | |
| 839 | 854 | ) |
| 840 | 855 | .await; |
| 841 | - (subject_id, object_id) | |
| 856 | + (None, subject_id, object_id) | |
| 842 | 857 | } |
| 843 | 858 | } else { |
| 844 | - (subject_id, object_id) | |
| 859 | + (Some(pid), subject_id, object_id) | |
| 845 | 860 | } |
| 846 | 861 | } else { |
| 847 | - (subject_id, object_id) | |
| 862 | + (predicate_id, subject_id, object_id) | |
| 848 | 863 | }; |
| 849 | 864 | |
| 850 | 865 | { |
modified crates/utopia-server/src/predicate_match.rs +65 −0
| @@ -115,7 +115,24 @@ | ||
| 115 | 115 | s |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | +/// 领头的轻动词:`has_funding` 与 `funding` 是同一个关系,前缀是命名习惯不是意思。 | |
| 119 | +/// | |
| 120 | +/// 实测(ai-timeline-ends × schema.org):空谓词事实的原文说法里 | |
| 121 | +/// `has_funding` ×4 落空,而本体里就有 `funding`;`product` ×2 落空,而本体里有 | |
| 122 | +/// `has_product`——**差的只是这一个前缀**。 | |
| 123 | +/// | |
| 124 | +/// 只在还剩词的时候剥:`has` 单独一个词是它自己,不能剥成空。 | |
| 125 | +/// 过度归并不会造成错配——`insert` 遇到一个键落到两个关系上就作废(撞车即作废), | |
| 126 | +/// 所以最坏情况是退回"匹配不上",而不是匹配到错的那个。 | |
| 127 | +const LEADING_AUX: &[&str] = &[ | |
| 128 | + "has", "have", "had", "is", "are", "was", "were", "be", "been", | |
| 129 | +]; | |
| 130 | + | |
| 118 | 131 | fn stems(words: &[String]) -> Vec<String> { |
| 132 | + let words = match words.split_first() { | |
| 133 | + Some((head, rest)) if !rest.is_empty() && LEADING_AUX.contains(&head.as_str()) => rest, | |
| 134 | + _ => words, | |
| 135 | + }; | |
| 119 | 136 | words.iter().map(|w| inflect_base(w)).collect() |
| 120 | 137 | } |
| 121 | 138 | |
| @@ -219,6 +236,54 @@ | ||
| 219 | 236 | mod tests { |
| 220 | 237 | use super::*; |
| 221 | 238 | |
| 239 | + /// `has_funding` 与 `funding` 是同一个关系,前缀是命名习惯不是意思。 | |
| 240 | + /// | |
| 241 | + /// 实测里这两组各自落空:本体有 `funding`、模型写 `has_funding`(×4); | |
| 242 | + /// 本体有 `has_product`、模型写 `product`(×2)。差的只是这一个前缀。 | |
| 243 | + #[test] | |
| 244 | + fn a_leading_auxiliary_does_not_make_a_different_relation() { | |
| 245 | + let rels = vec![rel("funding"), rel("has_product")]; | |
| 246 | + let idx = PredicateIndex::build(&rels); | |
| 247 | + assert!( | |
| 248 | + idx.lookup("has_funding").is_some(), | |
| 249 | + "has_funding 该落到 funding 上" | |
| 250 | + ); | |
| 251 | + assert!( | |
| 252 | + idx.lookup("product").is_some(), | |
| 253 | + "product 该落到 has_product 上" | |
| 254 | + ); | |
| 255 | + // 两个方向都要通 | |
| 256 | + assert!(idx.lookup("funding").is_some()); | |
| 257 | + assert!(idx.lookup("has_product").is_some()); | |
| 258 | + } | |
| 259 | + | |
| 260 | + /// **只在还剩词的时候剥。** `has` 单独一个词是它自己,剥成空就什么都匹配了。 | |
| 261 | + #[test] | |
| 262 | + fn a_bare_auxiliary_is_still_a_word() { | |
| 263 | + let rels = vec![rel("has")]; | |
| 264 | + let idx = PredicateIndex::build(&rels); | |
| 265 | + assert!(idx.lookup("has").is_some(), "has 自己该匹配得上"); | |
| 266 | + assert!(idx.lookup("owns").is_none(), "剥成空会让不相干的词也匹配上"); | |
| 267 | + } | |
| 268 | + | |
| 269 | + /// 撞车仍然作废:本体同时有 `funding` 与 `has_funding` 时,选谁都是猜。 | |
| 270 | + /// 过度归并的最坏结果是「匹配不上」,不是「匹配到错的那个」。 | |
| 271 | + #[test] | |
| 272 | + fn folding_the_prefix_never_produces_a_wrong_match() { | |
| 273 | + let rels = vec![rel("funding"), rel("has_funding")]; | |
| 274 | + let idx = PredicateIndex::build(&rels); | |
| 275 | + // 精确 key 仍然直达 | |
| 276 | + assert!(idx.lookup("funding").is_some()); | |
| 277 | + assert!(idx.lookup("has_funding").is_some()); | |
| 278 | + // 撞车在**词干**那一层:`funding` 与 `has_funding` 剥掉前缀后都是 ["funding"]。 | |
| 279 | + // 要测它就得给一个走不到写法对齐、只能落到词干的形式—— | |
| 280 | + // `has_fundings` 拼起来是 hasfundings,本体里没有,于是往下走到词干,撞车作废 | |
| 281 | + assert!( | |
| 282 | + idx.lookup("has_fundings").is_none(), | |
| 283 | + "词干层撞车了却还是选了一个" | |
| 284 | + ); | |
| 285 | + } | |
| 286 | + | |
| 222 | 287 | fn rel(key: &str) -> RelationType { |
| 223 | 288 | RelationType { |
| 224 | 289 | id: Uuid::new_v4(), |