Persona anchors: across the whole segment, and a link by whose it is
Soul's R9 item 3. - The anchor is looked for across the whole current segment of her prose, not only the sentence the Interpreter's quote stands in, so "I'll start with #86. The saga code will say..." anchors #86. The sentence finder goes. - A link is anchored by its address, its host, or the possessive of the person who posted it ("Deru's link") when that person posted exactly one link in view. - A word that only refers ("the PR", "that page") still needs exactly one candidate in view and the read to be it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
84fbc0de30
commit
1f3a3d1312
2 changed files with 49 additions and 16 deletions
|
|
@ -760,7 +760,18 @@ fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake
|
|||
// least `SPAN_MIN_WORDS` of its words found there (Soul's R5), and only where the sentence it stands in names what is
|
||||
// read: its repo, pull request, domain item, address or recall words, or a direct reference to it. A common run alone
|
||||
// ("I want to") anchors nothing (Soul's R6). When nothing locates, the read is refused, reported, and never told to her.
|
||||
let names = target_words(&request);
|
||||
let mut names = target_words(&request);
|
||||
// A link is named too by the possessive of the one who posted it ("Deru's link"), when that person posted exactly
|
||||
// one link in front of her (Soul's R9).
|
||||
if let ReadRequest::Web(url) = &request {
|
||||
let links = |line: &crate::projection::select::Quotable| line.text.split_whitespace().filter(|word| word.starts_with("http://") || word.starts_with("https://")).map(str::to_owned).collect::<BTreeSet<_>>();
|
||||
for line in packet.quotable.iter().filter(|line| links(line).contains(url)) {
|
||||
let theirs: BTreeSet<String> = packet.quotable.iter().filter(|other| other.sender == line.sender).flat_map(links).collect();
|
||||
if let (1, Some(first)) = (theirs.len(), line.who.split([',', ' ']).next().filter(|first| !first.is_empty())) {
|
||||
names.extend([format!("{}'s", first.to_lowercase()), format!("{}\u{2019}s", first.to_lowercase())]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// A word that only refers ("the page", "that diff") anchors a read only when one thing of its kind is in front of her
|
||||
// and that thing is what is read (Soul's R7, R8): with two pages there, "the page" names neither, and with one domain
|
||||
// line there it names that line's own target and nothing else.
|
||||
|
|
@ -787,7 +798,9 @@ fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake
|
|||
let start = start.max(wake.from);
|
||||
SourceSpan::locate(&prose[start..end], text)
|
||||
.map(|span| (start + span.start_byte(), start + span.end_byte()))
|
||||
.filter(|(at, to)| anchors(sentence_around(prose, *at, *to)))
|
||||
// The anchor is looked for across the whole segment, not only the sentence the quote stands in (Soul's
|
||||
// R9): "I'll start with #86. The saga code will say…" names #86.
|
||||
.filter(|_| anchors(&prose[wake.from.min(prose.len())..]))
|
||||
.map(|(at, to)| prose[at..to].to_owned())
|
||||
})
|
||||
};
|
||||
|
|
@ -817,15 +830,6 @@ fn target_words(request: &ReadRequest) -> Vec<String> {
|
|||
}
|
||||
}
|
||||
|
||||
/// The sentence of `prose` that holds the span `at..to`: back to the last sentence end or line break before it, on to the
|
||||
/// next after it.
|
||||
fn sentence_around(prose: &str, at: usize, to: usize) -> &str {
|
||||
let ends = |c: char| matches!(c, '.' | '!' | '?' | '\n');
|
||||
let start = prose[..at].rfind(ends).map_or(0, |end| end + 1);
|
||||
let stop = prose[to..].find(ends).map_or(prose.len(), |end| to + end + 1);
|
||||
&prose[start..stop]
|
||||
}
|
||||
|
||||
/// The things of a read's kind in front of her, by normal form: web addresses in her prose and what reached her, for a
|
||||
/// web read; her domain's lines' targets and the GameCult repo targets named in her prose and what reached her, for a
|
||||
/// repo or campaign read; none for a recall.
|
||||
|
|
|
|||
|
|
@ -972,13 +972,16 @@ fn r7_recall_and_search_words_are_her_own_whole_words() {
|
|||
/// Soul's R7: a word that only refers ("that page") anchors a read only when one thing of its kind is in front of her.
|
||||
#[test]
|
||||
fn r7_a_generic_word_anchors_a_read_only_when_one_target_of_its_kind_is_in_view() {
|
||||
let reading = reading_packet();
|
||||
// The addresses reached her; her prose only refers ("that page"), so the generic word must do the naming.
|
||||
let quote = "I want to open that page and read it";
|
||||
let one = "There is http://a.example/x here. I want to open that page and read it all.";
|
||||
let read = asked(&reading, one, json!({ "kind": "web", "target": "http://a.example/x", "quote": quote }));
|
||||
let prose = "I want to open that page and read it all.";
|
||||
let mut one = reading_packet();
|
||||
one.bodies = vec!["There is http://a.example/x here.".into()];
|
||||
let read = asked(&one, prose, json!({ "kind": "web", "target": "http://a.example/x", "quote": quote }));
|
||||
assert_eq!(read["read"]["request"], json!({ "kind": "web", "target": "http://a.example/x" }), "{read}");
|
||||
let two = "There is http://a.example/x and http://b.example/y here. I want to open that page and read it all.";
|
||||
let either = asked(&reading, two, json!({ "kind": "web", "target": "http://a.example/x", "quote": quote }));
|
||||
let mut two = reading_packet();
|
||||
two.bodies = vec!["There is http://a.example/x and http://b.example/y here.".into()];
|
||||
let either = asked(&two, prose, json!({ "kind": "web", "target": "http://a.example/x", "quote": quote }));
|
||||
assert_eq!(either["read_refused"][0]["why"], "quote_not_located", "{either}");
|
||||
}
|
||||
|
||||
|
|
@ -1043,3 +1046,29 @@ fn r9_the_read_a_cap_stopped_is_made_the_next_wake() {
|
|||
let read = asked(&next, prose, json!({ "kind": "repo", "target": "GameCult/Bifrost#85", "quote": "I'll open GameCult/Bifrost#85 and read" }));
|
||||
assert_eq!(read["read"]["request"], json!({ "kind": "repo", "target": "GameCult/Bifrost#85" }), "{read}");
|
||||
}
|
||||
|
||||
/// Soul's R9: the anchor is looked for across the whole segment, so a number named a sentence before the quote anchors it;
|
||||
/// a link is named by the possessive of the one who posted it when that person posted exactly one link in view; "the PR"
|
||||
/// still needs exactly one candidate.
|
||||
#[test]
|
||||
fn r9_the_segment_anchors_and_a_link_is_named_by_whose_it_is() {
|
||||
let reading = reading_packet();
|
||||
let prose = "I'll start with #86. The saga code will say what the undo really does.";
|
||||
let read = asked(&reading, prose, json!({ "kind": "repo", "target": "GameCult/Bifrost#86", "quote": "The saga code will say what" }));
|
||||
assert_eq!(read["read"]["request"], json!({ "kind": "repo", "target": "GameCult/Bifrost#86" }), "{read}");
|
||||
let mut linked = reading_packet();
|
||||
let line = |id: &str, who: &str, sender: &str, text: &str| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: "#minds:gamecult.org".into(), who: who.into(), sender: sender.into(), at_ms: 1, text: text.into() };
|
||||
linked.quotable = vec![line("q1", "Deru", "@deru:gamecult.org", "here, http://notes.example/waveguides"), line("q2", "Kiko", "@kiko:gamecult.org", "and http://kiko.example/a")];
|
||||
linked.bodies = linked.quotable.iter().map(|line| line.text.clone()).collect();
|
||||
let prose = "Deru's link is the one I want. I'll read it before I answer him.";
|
||||
let deru = asked(&linked, prose, json!({ "kind": "web", "target": "http://notes.example/waveguides", "quote": "I'll read it before I answer" }));
|
||||
assert_eq!(deru["read"]["request"], json!({ "kind": "web", "target": "http://notes.example/waveguides" }), "{deru}");
|
||||
linked.quotable[0].text.push_str(" and http://notes.example/plosives");
|
||||
linked.bodies = linked.quotable.iter().map(|line| line.text.clone()).collect();
|
||||
let two = asked(&linked, prose, json!({ "kind": "web", "target": "http://notes.example/waveguides", "quote": "I'll read it before I answer" }));
|
||||
assert_eq!(two["read_refused"][0]["why"], "quote_not_located", "two links of Deru's: {two}");
|
||||
let mut prs = reading_packet();
|
||||
prs.domain.push(crate::projection::select::DomainLine { id: "d2".into(), line: "- GameCult/Bifrost: merged \"Merge pages and notices\", opened by heimdall".into(), about: crate::projection::domain::About::Repo("GameCult/Bifrost".into()) });
|
||||
let either = asked(&prs, "I want to open the PR and read it through.", json!({ "kind": "domain", "target": "d2", "quote": "I want to open the PR" }));
|
||||
assert_eq!(either["read_refused"][0]["why"], "quote_not_located", "{either}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue