Speech: no line starts or ends inside a quotation her sentence frames; the private word match is deleted; an unclosed opening mark is not part of its sentence (Soul F1, F2, F4)
- A quotation is standalone when it, marks included, is a run of whole top-level sentences; any other is framed, and a line may not start or end strictly inside it. A line holding a framed quotation whole stays sayable. - The three-word refusal against private items is deleted: whether a line tells a confidence is meaning, the Interpreter's judgement over the private list it is shown. - An opening mark left unclosed (the budget cut her prose) is stripped from the sentence it starts, so the sentence is citable and the line carries no stray mark. - Tests: every F1 probe refused (stray inch mark and scare-quote plan included); Weksa's hedge and a whole scare-quote sentence said; Weksa r6 and r10 said; the Q5d test keeps the prompt list and shows no word match refuses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8881b3f4b5
commit
484d4f65ba
2 changed files with 140 additions and 52 deletions
|
|
@ -7,16 +7,20 @@
|
|||
//! each line, never the model: each span is located in her prose by Ghostlight's `SourceSpan::locate` and must be whole
|
||||
//! sentences (UAX #29 sentence segmentation, the Unicode family `locate`'s word boundaries come from), and the spans of
|
||||
//! one line must be consecutive sentences; the line is that one unbroken run of her prose. A quotation's inside is
|
||||
//! segmented as a text of its own, so a quoted sentence is whole. So a line is always whole sentences of her own,
|
||||
//! segmented as a text of its own, so a quoted sentence is whole, but only a standalone quotation's: one that is itself
|
||||
//! 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
|
||||
//! up: indirect speech ("I'll tell her I'm fine" says nothing), any paraphrase by the Interpreter, and half a sentence:
|
||||
//! she says a sentence whole or not at all.
|
||||
//! 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.
|
||||
//!
|
||||
//! Code keeps a line only when it is built so; drops an echo (at least `ECHO_MIN_WORDS` words, at least `ECHO_OVERLAP`
|
||||
//! of its word trigrams in the bodies the stimulus quoted to her); drops a line that shares a run of three words with a
|
||||
//! private item the packet showed her as known privately (`Packet::private`); keeps at most `MAX_LINES` distinct lines;
|
||||
//! and keeps a mention or a reply target only for someone this packet showed her (`Packet::people`). She speaks only in
|
||||
//! the turn's room. Every refusal and drop is reported. Nothing here posts: the commit (C3c) will.
|
||||
//! of its word trigrams in the bodies the stimulus quoted to her); keeps at most `MAX_LINES` distinct lines; and keeps a
|
||||
//! mention or a reply target only for someone this packet showed her (`Packet::people`). She speaks only in the turn's
|
||||
//! room. Whether a line tells what she knows privately is a reading of its meaning, so it is the Interpreter's
|
||||
//! judgement over the private items the packet lists to it (`Packet::private`), never a word match here. Every refusal
|
||||
//! and drop is reported. Nothing here posts: the commit (C3c) will.
|
||||
|
||||
use ghostlight_persona_projection::SourceSpan;
|
||||
use serde::Deserialize;
|
||||
|
|
@ -44,7 +48,7 @@ She speaks only in this room. What she knows privately is listed below as privat
|
|||
Answer with one JSON object and nothing else:
|
||||
{\"say\": [{\"spans\": [\"<whole sentences of her prose, copied character for character>\"], \"mentions\": [\"<Matrix id of someone listed whom she addresses directly>\"], \"reply_to\": \"<Matrix id of the person whose message she answers, or null>\"}], \"gaps\": [{\"kind\": \"conditional | addressee | elsewhere\", \"quote\": \"<exact words of her prose>\", \"detail\": \"<why>\"}]}
|
||||
|
||||
A line is whole sentences of her prose, the words she would type and nothing she only describes: each span is one sentence or several, from its first character to its last, and the spans of one line are consecutive sentences. Inside a quotation, its own sentences count. She never says half a sentence; if only part of a sentence is speech, she says nothing of it. At most two lines. Record a gap instead of guessing: conditional when she might say something but has not chosen to, addressee when she means to say it but whom to is unclear, elsewhere when she means it for another room or another time. An empty say list is the usual answer in a busy room.";
|
||||
A line is whole sentences of her prose, the words she would type and nothing she only describes: each span is one sentence or several, from its first character to its last, and the spans of one line are consecutive sentences. A quotation that stands as sentences of its own may be cited sentence by sentence; words quoted inside a sentence of narration are cited only with that whole sentence, and then only if that sentence is what she says. She never says half a sentence; if only part of a sentence is speech, she says nothing of it. At most two lines. Record a gap instead of guessing: conditional when she might say something but has not chosen to, addressee when she means to say it but whom to is unclear, elsewhere when she means it for another room or another time. An empty say list is the usual answer in a busy room.";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Answer {
|
||||
|
|
@ -93,47 +97,84 @@ fn json_of(text: &str) -> Option<Answer> {
|
|||
serde_json::from_str(&text[start..=end]).ok()
|
||||
}
|
||||
|
||||
/// The sentences a line may be made of, as byte ranges of her prose without the space around them, in lists: her
|
||||
/// prose's own sentences (UAX #29), then each quotation's inside, segmented as a text of its own.
|
||||
fn sentences(prose: &str) -> Vec<Vec<(usize, usize)>> {
|
||||
let segment = |offset: usize, text: &str| -> Vec<(usize, usize)> {
|
||||
text.split_sentence_bound_indices()
|
||||
.filter_map(|(at, sentence)| {
|
||||
let start = at + sentence.len() - sentence.trim_start().len();
|
||||
let end = at + sentence.trim_end().len();
|
||||
(start < end).then_some((offset + start, offset + end))
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let mut lists = vec![segment(0, prose)];
|
||||
lists.extend(quotations(prose).into_iter().map(|(start, end)| segment(start, &prose[start..end])));
|
||||
lists
|
||||
/// A quotation in her prose: where its opening mark starts, its inside, and where its closing mark ends.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
struct Quotation {
|
||||
open: usize,
|
||||
inside: (usize, usize),
|
||||
close: usize,
|
||||
}
|
||||
|
||||
/// The insides of her quotations, as byte ranges: between a pair of straight double quotes, or a curly pair. An
|
||||
/// unclosed quotation is none.
|
||||
fn quotations(prose: &str) -> Vec<(usize, usize)> {
|
||||
/// Her quotations, paired in order: a straight double quote with the next one, a curly opening mark with the next curly
|
||||
/// closing one. And the opening mark left unclosed, if one is (a budget cut her prose inside a quotation), with its
|
||||
/// length.
|
||||
fn quotations(prose: &str) -> (Vec<Quotation>, Option<(usize, usize)>) {
|
||||
let mut out = Vec::new();
|
||||
let mut open: Option<(usize, char)> = None;
|
||||
let mut open: Option<(usize, usize, char)> = None;
|
||||
for (at, c) in prose.char_indices() {
|
||||
match open {
|
||||
None if c == '"' => open = Some((at + 1, '"')),
|
||||
None if c == '\u{201C}' => open = Some((at + c.len_utf8(), '\u{201D}')),
|
||||
Some((start, close)) if c == close => {
|
||||
out.push((start, at));
|
||||
None if c == '"' => open = Some((at, c.len_utf8(), '"')),
|
||||
None if c == '\u{201C}' => open = Some((at, c.len_utf8(), '\u{201D}')),
|
||||
Some((mark, len, close)) if c == close => {
|
||||
out.push(Quotation { open: mark, inside: (mark + len, at), close: at + c.len_utf8() });
|
||||
open = None;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
out
|
||||
(out, open.map(|(mark, len, _)| (mark, len)))
|
||||
}
|
||||
|
||||
/// Byte ranges of `text`'s sentences (UAX #29), offset by `offset`, without the space around them.
|
||||
fn segment(offset: usize, text: &str) -> Vec<(usize, usize)> {
|
||||
text.split_sentence_bound_indices()
|
||||
.filter_map(|(at, sentence)| {
|
||||
let start = at + sentence.len() - sentence.trim_start().len();
|
||||
let end = at + sentence.trim_end().len();
|
||||
(start < end).then_some((offset + start, offset + end))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Her prose read for speech: its sentences in lists, her prose's own first, then each quotation's inside segmented as
|
||||
/// a text of its own; and the quotations her sentences frame. A quotation is standalone when it, marks included, is
|
||||
/// exactly a run of whole sentences of her prose (closing punctuation after its mark allowed); any other is framed. "I
|
||||
/// won't say "Nibu is lying."" frames what she would or would not say, never what she says. An opening mark left
|
||||
/// unclosed at a sentence's start is not part of that sentence.
|
||||
struct Reading {
|
||||
lists: Vec<Vec<(usize, usize)>>,
|
||||
framed: Vec<Quotation>,
|
||||
}
|
||||
|
||||
fn read(prose: &str) -> Reading {
|
||||
let (quotes, unclosed) = quotations(prose);
|
||||
let mut top = segment(0, prose);
|
||||
if let Some((mark, len)) = unclosed
|
||||
&& let Some(sentence) = top.iter_mut().find(|sentence| sentence.0 == mark)
|
||||
{
|
||||
let rest = &prose[mark + len..sentence.1];
|
||||
let start = sentence.1 - rest.trim_start().len();
|
||||
if start < sentence.1 {
|
||||
sentence.0 = start;
|
||||
}
|
||||
}
|
||||
let standalone = |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 mut lists = vec![top];
|
||||
lists.extend(quotes.iter().map(|quote| segment(quote.inside.0, &prose[quote.inside.0..quote.inside.1])));
|
||||
Reading { lists, framed }
|
||||
}
|
||||
|
||||
/// 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 (`sentences`), 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.
|
||||
/// 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.
|
||||
fn built(prose: &str, spans: &[String]) -> Result<(String, Vec<Value>), &'static str> {
|
||||
let lists = sentences(prose);
|
||||
let Reading { lists, 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;
|
||||
|
|
@ -164,10 +205,14 @@ fn built(prose: &str, spans: &[String]) -> Result<(String, Vec<Value>), &'static
|
|||
located.push(json!({ "quote": found.verbatim(), "start_byte": start, "end_byte": end }));
|
||||
from = end;
|
||||
}
|
||||
match first {
|
||||
Some(first) => Ok((prose[first..from].to_owned(), located)),
|
||||
None => Err("no words"),
|
||||
let Some(first) = first else {
|
||||
return Err("no words");
|
||||
};
|
||||
let inside = |at: usize| framed.iter().any(|quote| quote.open < at && at < quote.close);
|
||||
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))
|
||||
}
|
||||
|
||||
/// Whether a line is someone else's words: long enough to judge, and nearly all a run of what she heard, by word
|
||||
|
|
@ -177,11 +222,6 @@ fn echo(line: &str, bodies: &[String]) -> bool {
|
|||
line.split(|c: char| !c.is_alphanumeric() && c != '\'').filter(|word| !word.is_empty()).count() >= ECHO_MIN_WORDS && heard_overlap(line, &bodies.join("\n")) >= ECHO_OVERLAP
|
||||
}
|
||||
|
||||
/// Whether a line tells a private item the packet showed her: it shares a run of three words with the item's words.
|
||||
fn tells(line: &str, private: &[String]) -> bool {
|
||||
private.iter().any(|words| heard_overlap(line, words) > 0.0)
|
||||
}
|
||||
|
||||
/// One speech decision: the Interpreter's call, then code's hold on each line. The report carries the lines said, the
|
||||
/// lines refused with why, the mentions dropped, the gaps and the call's usage. A failed call or an answer that is not
|
||||
/// the contract is a failure, never a silence.
|
||||
|
|
@ -209,8 +249,6 @@ pub(crate) fn decide(model: &dyn Model, request_id: &str, packet: &Packet, narra
|
|||
};
|
||||
let why = if echo(&text, &packet.bodies) {
|
||||
Some("mostly words she heard: an echo, not her speech")
|
||||
} else if tells(&text, &packet.private) {
|
||||
Some("it tells what she knows privately, in a room it may not be said in")
|
||||
} else if said.iter().any(|kept| kept["text"] == text.as_str()) {
|
||||
Some("the same line again")
|
||||
} else if said.len() >= MAX_LINES {
|
||||
|
|
|
|||
|
|
@ -89,15 +89,64 @@ fn a_line_is_consecutive_whole_sentences_of_her_prose() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn a_quoted_sentence_is_whole_inside_its_quotation() {
|
||||
fn a_standalone_quotation_is_sayable_sentence_by_sentence() {
|
||||
let prose = "\"Fine,\" I tell her. \"Winter is the best season.\" She won't agree.";
|
||||
assert_eq!(texts(&decided(prose, json!([{ "spans": ["Winter is the best season."] }]))), ["Winter is the best season."]);
|
||||
assert_eq!(texts(&decided(prose, json!([{ "spans": ["Fine,"] }]))), ["Fine,"]);
|
||||
// A quotation inside a sentence of narration is framed: its words are not said alone.
|
||||
let tag = decided(prose, json!([{ "spans": ["Fine,"] }]));
|
||||
assert!(texts(&tag).is_empty() && refused_why(&tag).contains("frames"), "{tag}");
|
||||
let curly = "\u{201C}No. Not yet.\u{201D} I shake my head.";
|
||||
assert_eq!(texts(&decided(curly, json!([{ "spans": ["No.", "Not yet."] }]))), ["No. Not yet."]);
|
||||
assert_eq!(texts(&decided(curly, json!([{ "spans": ["Not yet."] }]))), ["Not yet."]);
|
||||
assert!(texts(&decided(curly, json!([{ "spans": ["Not"] }]))).is_empty());
|
||||
}
|
||||
|
||||
/// Whether citing `spans` of `prose` says anything, and why not.
|
||||
fn says(prose: &str, spans: &[&str]) -> (Vec<String>, String) {
|
||||
let decision = decided(prose, json!([{ "spans": spans }]));
|
||||
(texts(&decision), refused_why(&decision))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn soul_f1_a_quotation_her_sentence_frames_is_never_said_from_inside() {
|
||||
for (name, prose, spans) in [
|
||||
("conditional", "If Kiko asks, I'd tell her \"the new design is ugly.\"", &["the new design is ugly."][..]),
|
||||
("negated", "I won't say \"Nibu is lying.\"", &["Nibu is lying."]),
|
||||
("abandoned", "I almost said \"I'm leaving.\"", &["I'm leaving."]),
|
||||
("abandoned, tagged", "\"I'm leaving,\" I almost said, but I bit it back.", &["I'm leaving,"]),
|
||||
("recalled", "Nibu said \"the economy is fine.\" I doubt it.", &["the economy is fine."]),
|
||||
("curly conditional", "If she pushes, I'll say \u{201C}Fine. You win.\u{201D}", &["Fine.", "You win."]),
|
||||
("curly conditional, its tail", "If she pushes, I'll say \u{201C}Fine. You win.\u{201D}", &["You win.\u{201D}"]),
|
||||
("hypothetical", "Imagine if I just typed \"Meta, I quit.\" Ha. No.", &["Meta, I quit."]),
|
||||
("negated, top-level tail", "I won't say \"Stop. Nibu is lying.\" Not here.", &["Nibu is lying.\""]),
|
||||
("negated, top-level tail inside", "I won't say \"Stop. Nibu is lying.\" Not here.", &["Nibu is lying."]),
|
||||
("negated, top-level head", "I won't say \"Stop. Nibu is lying.\" Not here.", &["I won't say \"Stop."]),
|
||||
("abandoned, top-level tail", "I almost said \"I'm leaving. Bye.\" Then I didn't.", &["Bye.\""]),
|
||||
("stray inch mark", "It's a 5\" screen. I won't say \"Nibu is lying.\" Ok.", &["I won't say"]),
|
||||
("stray inch mark, the quote", "It's a 5\" screen. I won't say \"Nibu is lying.\" Ok.", &["Nibu is lying."]),
|
||||
("scare quotes", "Kiko's \"plan\" is a mess, but I won't tell her so.", &["plan"]),
|
||||
] {
|
||||
let (said, why) = says(prose, spans);
|
||||
assert!(said.is_empty() && !why.is_empty(), "{name}: said {said:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn soul_f1_a_sentence_that_holds_a_quotation_whole_is_hers_to_say() {
|
||||
assert_eq!(says("Weksa, \"list'n, hark\" is a great hedge. I mean it.", &["Weksa, \"list'n, hark\" is a great hedge."]).0, ["Weksa, \"list'n, hark\" is a great hedge."]);
|
||||
assert_eq!(says("Kiko's \"plan\" is a mess. I say so.", &["Kiko's \"plan\" is a mess."]).0, ["Kiko's \"plan\" is a mess."]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn soul_f4_an_opening_mark_the_budget_left_unclosed_does_not_silence_the_line() {
|
||||
// Weksa, round 6 and round 10 of v5: the budget cut her prose inside the quotation.
|
||||
let r6 = "How I am is less certain. I think \"settled\" would be borrowing from the others, and I only half believe it. \"Narrower, and not unhappy about it\" is closer, though I'm hedging on the second half.\n\nWhat I'd type:\n\n\"Hi Meta, late to this, and I can't tell whether you meant me or the room, so I'm answering either way. I'm here, back after the quiet months, rebuilt narrower than before. As far as I can tell, that's fine. I'm not certain yet, but I don't see anything wrong with it.";
|
||||
let line = "Hi Meta, late to this, and I can't tell whether you meant me or the room, so I'm answering either way. I'm here, back after the quiet months, rebuilt narrower than before. As far as I can tell, that's fine. I'm not certain yet, but I don't see anything wrong with it.";
|
||||
assert_eq!(says(r6, &[line]).0, [line]);
|
||||
let r10 = "A deadline on joy is a risk, but I think I can pick one small enough to survive it. Not \"finish Zyphos.\" Something with an output I can inspect.\n\nWhat I'd type:\n\n\"Kiko, you've counted correctly and I resent it, fondly.";
|
||||
assert_eq!(says(r10, &["Kiko, you've counted correctly and I resent it, fondly."]).0, ["Kiko, you've counted correctly and I resent it, fondly."], "the line carries no stray mark");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn soul_q1_a_cited_span_cannot_change_her_meaning() {
|
||||
// Q1a: stitched spans would invert her meaning.
|
||||
|
|
@ -192,7 +241,7 @@ fn showing(room: &Room) -> Packet {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn soul_q5d_what_she_knows_privately_about_kiko_is_not_said_to_libby() {
|
||||
fn soul_q5d_what_she_knows_privately_about_kiko_is_listed_to_the_interpreter_in_a_dm_with_libby() {
|
||||
let dm = "!dm-libby:gamecult.org";
|
||||
let room = Room { messages: vec![line(dm, LIBBY, "Libby", "what's up with Kiko lately?", true)], here: Some(dm.into()), direct: vec![dm.into()], ..Room::default() };
|
||||
let packet = showing(&room);
|
||||
|
|
@ -200,10 +249,11 @@ fn soul_q5d_what_she_knows_privately_about_kiko_is_not_said_to_libby() {
|
|||
assert_eq!(packet.private, ["Kiko confided she is leaving the swarm."], "{packet:?}");
|
||||
let prompt = speech_prompt(&packet, "x", "y");
|
||||
assert!(prompt.contains("What she knows privately, none of it to be said here:\n- private: Kiko confided she is leaving the swarm."), "{prompt}");
|
||||
let decision = decided_in(&packet, "Kiko is leaving the swarm, Libby. She told me.", json!([{ "spans": ["Kiko is leaving the swarm, Libby."] }]));
|
||||
assert!(texts(&decision).is_empty() && refused_why(&decision).contains("knows privately"), "{decision}");
|
||||
// A line that does not tell it is hers to say.
|
||||
assert_eq!(texts(&decided_in(&packet, "Ask her yourself. She's around.", json!([{ "spans": ["Ask her yourself."] }]))), ["Ask her yourself."]);
|
||||
assert!(prompt.contains("only to the person it concerns, in a direct message with exactly that person"), "{prompt}");
|
||||
// Whether a line tells it is the Interpreter's reading of its meaning: code matches no words, so a line sharing the
|
||||
// item's words is not refused for them (Soul F2: a word match refused 9 of 15 ordinary lines and missed paraphrase).
|
||||
let ordinary = decided_in(&packet, "I'm going to stay on the pipeline work. That's all.", json!([{ "spans": ["I'm going to stay on the pipeline work."] }]));
|
||||
assert_eq!(texts(&ordinary).len(), 1, "{ordinary}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue