fix(reader): preserve full context sentence with abbreviations (Mr., Mrs., etc.) and log bug fix
This commit is contained in:
1 parent
6a6b165c7a
commit
0ff4465d34
3 files changed
+40
-4
No files matched your search
@@ -1070,11 +1070,39 @@ export function renderInteractiveSpans(container, text, contextText, knownWordsM
|
||||
});
|
||||
}
|
||||
|
||||
const READER_HONORIFICS = [
|
||||
'Mr.', 'Mrs.', 'Ms.', 'Dr.', 'Prof.', 'St.', 'vs.', 'etc.', 'e.g.', 'i.e.', 'Jr.', 'Sr.',
|
||||
'Capt.', 'Col.', 'Gen.', 'Lt.', 'Sgt.', 'Rev.', 'Hon.'
|
||||
];
|
||||
|
||||
export function extractContextSentence(fullText, word) {
|
||||
if (!fullText) return '';
|
||||
const re = new RegExp(`([^.!?\\n]*?\\b${escapeRegex(word)}\\b[^.!?\\n]*[.!?]?)`, 'i');
|
||||
const m = fullText.match(re);
|
||||
if (m && m[1]) return m[1].trim();
|
||||
let protectedText = fullText;
|
||||
for (const h of READER_HONORIFICS) {
|
||||
if (protectedText.toLowerCase().includes(h.toLowerCase())) {
|
||||
const safe = h.replace(/\./g, '§DOT§');
|
||||
const reH = new RegExp(escapeRegex(h), 'gi');
|
||||
protectedText = protectedText.replace(reH, safe);
|
||||
}
|
||||
}
|
||||
// Protect decimal numbers (e.g. 3.14, 1.5)
|
||||
protectedText = protectedText.replace(/(\d+)\.(\d+)/g, '$1§DOT§$2');
|
||||
|
||||
// Split sentences on terminal punctuation (.!?) followed by optional quotes/brackets and whitespace
|
||||
const marked = protectedText.replace(/([.!?]['"”’»)]*)\s+/g, '$1§SEP§');
|
||||
const rawSentences = marked.split('§SEP§');
|
||||
|
||||
const cleanWord = (word || '').trim();
|
||||
if (cleanWord) {
|
||||
const escaped = escapeRegex(cleanWord);
|
||||
const wordRe = new RegExp(`(?:^|\\W)${escaped}(?:$|\\W)`, 'i');
|
||||
for (const s of rawSentences) {
|
||||
if (wordRe.test(s)) {
|
||||
return s.replace(/§DOT§/g, '.').trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fullText.slice(0, 160).trim();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Service Worker for Notes English PWA (Stage 2)
|
||||
// Strategy: Cache-first for static assets, Network-first for API calls.
|
||||
|
||||
const CACHE_NAME = 'notes-v5.5';
|
||||
const CACHE_NAME = 'notes-v5.6';
|
||||
const OFFLINE_URL = '/';
|
||||
|
||||
const PRECACHE_URLS = [
|
||||
|
||||
Reference in new issue
Block a user