From 23e3623057d26f2496f8837e1fdbef47b270acbf Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 20 Nov 2026 13:39:08 +0100 Subject: [PATCH] K1: a posted line carries a standalone quotation's inside, never its marks (map 16.7, I16.2) built() maps every standalone quotation inside a located run to its inside, so a line is the same whether the model cites the marks or the words. Framed quotations are unchanged. The tests' texts() helper refuses any said line that starts or ends with a speech mark. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection/interpret.rs | 34 ++++++++++++++----- .../src/projection/interpret/tests.rs | 28 ++++++++++++++- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 3627989..f405af0 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -11,7 +11,9 @@ //! whole sentences of her prose. A line may not start or end inside a quotation her sentence frames ("I won't say //! \"Nibu is lying.\"", "If she pushes, I'll say \"Fine.\""): that is what she would or would not say. An opening //! mark a budget left unclosed is not part of the sentence it starts. So a line is always whole sentences of her own, -//! verbatim and in their order: no stitching, no dropped negation, no condition lifted off its clause. What this gives +//! verbatim and in their order: no stitching, no dropped negation, no condition lifted off its clause. A standalone +//! quotation's marks say that paragraph is speech, so the line carries its inside and not its marks, whether the model +//! cited the marks or not (map section 16.7, I16.2). What this gives //! up: indirect speech ("I'll tell her I'm fine" says nothing), any paraphrase by the Interpreter, half a sentence, and //! a line quoted inside a sentence of narration ("\"Fine,\" I tell her."): she says a sentence whole or not at all. //! @@ -143,6 +145,7 @@ fn segment(offset: usize, text: &str) -> Vec<(usize, usize)> { /// unclosed at a sentence's start is not part of that sentence. struct Reading { lists: Vec>, + standalone: Vec, framed: Vec, } @@ -158,23 +161,38 @@ fn read(prose: &str) -> Reading { sentence.0 = start; } } - let standalone = |quote: &Quotation| { + let stands = |quote: &Quotation| { let opens = top.iter().position(|sentence| sentence.0 == quote.open); let closes = top.iter().position(|sentence| sentence.0 < quote.close && sentence.1 >= quote.close && prose[quote.close..sentence.1].chars().all(|c| c.is_ascii_punctuation())); matches!((opens, closes), (Some(opens), Some(closes)) if opens <= closes) }; - let framed = quotes.iter().copied().filter(|quote| !standalone(quote)).collect(); + let (standalone, framed) = quotes.iter().copied().partition(stands); let mut lists = vec![top]; lists.extend(quotes.iter().map(|quote| segment(quote.inside.0, &prose[quote.inside.0..quote.inside.1]))); - Reading { lists, framed } + Reading { lists, standalone, framed } +} + +/// `prose[first..end]` without the marks of the standalone quotations inside it (I16.2): her marks say a paragraph is +/// speech, and the line is the speech. What lies between two quotations, a paragraph break, stays. +fn unmarked(prose: &str, first: usize, end: usize, standalone: &[Quotation]) -> String { + let mut line = String::new(); + let mut at = first; + for quote in standalone.iter().filter(|quote| first <= quote.open && quote.close <= end) { + line.push_str(&prose[at..quote.open]); + line.push_str(&prose[quote.inside.0..quote.inside.1]); + at = quote.close; + } + line.push_str(&prose[at..end]); + line } /// The line her cited spans make, or why not. Each span is located in her prose after the one before it and must be /// whole sentences of one list (`read`), each span's first sentence the one after the last span's last; the line is her -/// prose from the first sentence to the last, verbatim, and it may neither start nor end inside a framed quotation. A -/// line that holds a framed quotation whole ("Kiko's "plan" is a mess.") is hers to say. +/// prose from the first sentence to the last, verbatim but for the marks of a standalone quotation (`unmarked`), and it +/// may neither start nor end inside a framed quotation. A line that holds a framed quotation whole ("Kiko's "plan" is a +/// mess.") is hers to say, marks and all. fn built(prose: &str, spans: &[String]) -> Result<(String, Vec), &'static str> { - let Reading { lists, framed } = read(prose); + let Reading { lists, standalone, framed } = read(prose); let mut from = 0; // The list the line is in, and its last sentence so far. let mut run: Option<(usize, usize)> = None; @@ -212,7 +230,7 @@ fn built(prose: &str, spans: &[String]) -> Result<(String, Vec), &'static if inside(first) || inside(from) { return Err("it starts or ends inside a quotation her sentence frames: words she would or would not say, not words she says"); } - Ok((prose[first..from].to_owned(), located)) + Ok((unmarked(prose, first, from, &standalone), located)) } /// Whether a line is someone else's words: long enough to judge, and nearly all a run of what she heard, by word diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index b43d837..7a5171a 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -58,8 +58,14 @@ fn decided(prose: &str, say: serde_json::Value) -> Value { decided_in(&packet(), prose, say) } +/// The lines said. Every line any test here says is held to I16.2: no speech mark at either end. fn texts(decision: &Value) -> Vec { - decision["said"].as_array().unwrap().iter().map(|line| line["text"].as_str().unwrap().to_owned()).collect() + let said: Vec = decision["said"].as_array().unwrap().iter().map(|line| line["text"].as_str().unwrap().to_owned()).collect(); + for line in &said { + let marks = ['"', '\u{201C}', '\u{201D}']; + assert!(!line.starts_with(marks) && !line.ends_with(marks), "a posted line keeps a speech mark: {line:?}"); + } + said } fn refused_why(decision: &Value) -> String { @@ -101,6 +107,26 @@ fn a_standalone_quotation_is_sayable_sentence_by_sentence() { assert!(texts(&decided(curly, json!([{ "spans": ["Not"] }]))).is_empty()); } +#[test] +fn a_quoted_paragraph_posts_without_its_marks_however_it_is_cited() { + let prose = "I lean in.\n\n\"Hi there.\"\n\nThat's enough."; + // Cited with its marks, the run is in her prose's own list; cited by its inside, in the quotation's. One line. + assert_eq!(says(prose, &["\"Hi there.\""]).0, ["Hi there."]); + assert_eq!(says(prose, &["Hi there."]).0, ["Hi there."]); + let curly = "\u{201C}No. Not yet.\u{201D} I shake my head."; + assert_eq!(says(curly, &["\u{201C}No.", "Not yet.\u{201D}"]).0, ["No. Not yet."]); + // Closing punctuation after the mark stays with the sentence. + assert_eq!(says("\"Fine\". I mean it.", &["\"Fine\"."]).0, ["Fine."]); +} + +#[test] +fn a_run_of_quoted_paragraphs_posts_each_inside_and_what_lies_between() { + let prose = "I think it over.\n\n\"Hi Meta.\"\n\n\"I'm here, and I'm fine.\"\n\nThen I wait."; + assert_eq!(says(prose, &["\"Hi Meta.\"", "\"I'm here, and I'm fine.\""]).0, ["Hi Meta.\n\nI'm here, and I'm fine."]); + // A framed quotation the line holds whole keeps its marks: they are hers, inside her sentence. + assert_eq!(says("\"Yes.\" Kiko's \"plan\" is a mess.", &["\"Yes.\"", "Kiko's \"plan\" is a mess."]).0, ["Yes. Kiko's \"plan\" is a mess."]); +} + /// Whether citing `spans` of `prose` says anything, and why not. fn says(prose: &str, spans: &[&str]) -> (Vec, String) { let decision = decided(prose, json!([{ "spans": spans }]));