Harden item occurrence grounding
This commit is contained in:
@@ -10,8 +10,7 @@ import (
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -51,17 +50,7 @@ func NormalizeDisplay(value string) string {
|
||||
|
||||
// ComparisonKey returns the stable key used for location identity comparisons.
|
||||
func ComparisonKey(value string) string {
|
||||
value = norm.NFKC.String(value)
|
||||
value = strings.Map(func(r rune) rune {
|
||||
switch r {
|
||||
case '\u2018', '\u2019', '\u02bc':
|
||||
return '\''
|
||||
default:
|
||||
return r
|
||||
}
|
||||
}, value)
|
||||
value = strings.Join(strings.Fields(value), " ")
|
||||
return cases.Fold().String(value)
|
||||
return shared.ComparisonKey(value)
|
||||
}
|
||||
|
||||
// DeriveID derives a location ID from name and the earliest canonical evidence
|
||||
|
||||
@@ -15,17 +15,6 @@ func TestNormalizeDisplayOnlyChangesWhitespace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestComparisonKeyNormalizesUnicodeWhitespaceAndApostrophes(t *testing.T) {
|
||||
for _, pair := range [][2]string{
|
||||
{" Caf\u00e9\u2003d\u2019Or ", "cafe\u0301 d'Or"},
|
||||
{"\uff34\uff48\uff45\u00a0\uff34\uff41\uff56\uff45\uff52\uff4e", "the tavern"},
|
||||
} {
|
||||
if left, right := ComparisonKey(pair[0]), ComparisonKey(pair[1]); left != right {
|
||||
t.Fatalf("ComparisonKey(%q) = %q, want value equal to %q", pair[0], left, pair[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeriveIDUsesDocumentedCompactJSONInput(t *testing.T) {
|
||||
refs := []source.SourceRef{
|
||||
{SourceID: "session-alpha", StartUnitID: 9, EndUnitID: 9},
|
||||
|
||||
Reference in New Issue
Block a user