2 changed files with 32 additions and 20 deletions
Showing only changes of commit d532254bc6 - Show all commits
+27 -20
View File
@@ -319,10 +319,11 @@ func drop(q SideQuest, regulars regularNames, known *harness.Deduper, kept []Sid
// Chili-inspired" and "Beef Chili's" mention "Beef Chili" while "Beef // Chili-inspired" and "Beef Chili's" mention "Beef Chili" while "Beef
// Chilis" does not, nor does "Cafe" with a combining accent after it // Chilis" does not, nor does "Cafe" with a combining accent after it
// mention "Cafe". Punctuation at either end of the name, with any spacing // mention "Cafe". Punctuation at either end of the name, with any spacing
// beside it, is optional, and a mention takes it in only where text spells // beside it, is optional, and a mention takes in as much of it as text
// it, spaced in any way, and the border still holds after it: "Easy Beef // spells, spaced in any way, with the border still holding after it: "Easy
// Chili!" is mentioned by "Easy Beef Chili." too, by "Easy Beef Chili !" // Beef Chili!" is mentioned by "Easy Beef Chili." too, by "Easy Beef Chili
// with its "!", and by "Easy Beef Chili!x" without its "!". A // !" with its "!", and by "Easy Beef Chili!x" without its "!", and "Beef
// Chili!!" by "Beef Chili!" with one "!". A
// combining mark is part of its letter, never punctuation. A mention names // combining mark is part of its letter, never punctuation. A mention names
// its Regular unless a mention of a different Regular covers the same text // its Regular unless a mention of a different Regular covers the same text
// or more, so "Your Easy Beef Chili." names "Easy Beef Chili" and not "Beef // or more, so "Your Easy Beef Chili." names "Easy Beef Chili" and not "Beef
@@ -357,12 +358,8 @@ func (r regularNames) named(text string) []string {
if !bordered(start, end) { if !bordered(start, end) {
continue continue
} }
if s := spelledBefore(text, start, lead); s >= 0 && bordered(s, end) { start = spelledBefore(text, start, lead, func(s int) bool { return bordered(s, end) })
start = s end = spelledAfter(text, end, trail, func(e int) bool { return bordered(start, e) })
}
if e := spelledAfter(text, end, trail); e >= 0 && bordered(start, e) {
end = e
}
mentions = append(mentions, mention{name, start, end}) mentions = append(mentions, mention{name, start, end})
} }
} }
@@ -378,31 +375,41 @@ func (r regularNames) named(text string) []string {
return names return names
} }
// spelledAfter returns where outer ends when text spells it from at, // spelledAfter returns where the longest start of outer that text spells
// ignoring spacing, or -1 when text does not. // from at ends, ignoring spacing, among those after which bordered holds,
func spelledAfter(text string, at int, outer string) int { // or at when there are none.
func spelledAfter(text string, at int, outer string, bordered func(int) bool) int {
end := at
for _, c := range strings.Join(strings.Fields(outer), "") { for _, c := range strings.Join(strings.Fields(outer), "") {
at = len(text) - len(strings.TrimLeftFunc(text[at:], unicode.IsSpace)) at = len(text) - len(strings.TrimLeftFunc(text[at:], unicode.IsSpace))
if !strings.HasPrefix(text[at:], string(c)) { if !strings.HasPrefix(text[at:], string(c)) {
return -1 break
} }
at += utf8.RuneLen(c) at += utf8.RuneLen(c)
if bordered(at) {
end = at
} }
return at }
return end
} }
// spelledBefore returns where outer starts when text spells it up to at, // spelledBefore returns where the longest end of outer that text spells up
// ignoring spacing, or -1 when text does not. // to at starts, ignoring spacing, among those before which bordered holds,
func spelledBefore(text string, at int, outer string) int { // or at when there are none.
func spelledBefore(text string, at int, outer string, bordered func(int) bool) int {
start := at
punct := []rune(strings.Join(strings.Fields(outer), "")) punct := []rune(strings.Join(strings.Fields(outer), ""))
for i := len(punct) - 1; i >= 0; i-- { for i := len(punct) - 1; i >= 0; i-- {
at = len(strings.TrimRightFunc(text[:at], unicode.IsSpace)) at = len(strings.TrimRightFunc(text[:at], unicode.IsSpace))
if !strings.HasSuffix(text[:at], string(punct[i])) { if !strings.HasSuffix(text[:at], string(punct[i])) {
return -1 break
} }
at -= utf8.RuneLen(punct[i]) at -= utf8.RuneLen(punct[i])
if bordered(at) {
start = at
} }
return at }
return start
} }
// isWord reports whether c is a letter, a mark on one or a digit. // isWord reports whether c is a letter, a mark on one or a digit.
@@ -258,6 +258,11 @@ func TestSuggestSideQuestsReasonMentionRule(t *testing.T) {
"spacing after punctuation": {[]string{"¡Beef Chili"}, "Your ¡ Beef Chili is our inspiration.", "¡Beef Chili", ""}, "spacing after punctuation": {[]string{"¡Beef Chili"}, "Your ¡ Beef Chili is our inspiration.", "¡Beef Chili", ""},
"stored spacing left off": {[]string{"Beef Chili !", "Chili!"}, "Like your Beef Chili!", "Beef Chili !", ""}, "stored spacing left off": {[]string{"Beef Chili !", "Chili!"}, "Like your Beef Chili!", "Beef Chili !", ""},
"inside unspaced punctuation": {[]string{"Beef Chili !", "Chili!"}, "Like your Beef Chili!", "Chili!", none}, "inside unspaced punctuation": {[]string{"Beef Chili !", "Chili!"}, "Like your Beef Chili!", "Chili!", none},
"stored punctuation partly": {[]string{"Beef Chili!!", "Chili!"}, "Like your Beef Chili!", "Beef Chili!!", ""},
"inside partial punctuation": {[]string{"Beef Chili!!", "Chili!"}, "Like your Beef Chili!", "Chili!", none},
"partly then a letter": {[]string{"Beef Chili!!", "Chili!"}, "Your Beef Chili!!X is our inspiration.", "Chili!", none},
"leading punctuation partly": {[]string{"¡¡Beef Chili", "¡Beef"}, "Like your ¡Beef Chili.", "¡¡Beef Chili", ""},
"inside partial leading": {[]string{"¡¡Beef Chili", "¡Beef"}, "Like your ¡Beef Chili.", "¡Beef", none},
"stored symbol left off": {[]string{"Green Chili 🌶"}, "Like your Green Chili, gone green.", "Green Chili 🌶", none}, "stored symbol left off": {[]string{"Green Chili 🌶"}, "Like your Green Chili, gone green.", "Green Chili 🌶", none},
"stored accent left off": {[]string{"Chicken Cafe\u0301"}, "Like your Chicken Cafe, gone green.", "Chicken Cafe\u0301", none}, "stored accent left off": {[]string{"Chicken Cafe\u0301"}, "Like your Chicken Cafe, gone green.", "Chicken Cafe\u0301", none},
"accent written after name": {[]string{"Chicken Cafe"}, "Like your Chicken Cafe\u0301, gone green.", "Chicken Cafe", none}, "accent written after name": {[]string{"Chicken Cafe"}, "Like your Chicken Cafe\u0301, gone green.", "Chicken Cafe", none},