Add developer tools page and secure guest scans
This commit is contained in:
@@ -29,6 +29,17 @@ const GERMAN_COMMON_NAME_HINTS = [
|
||||
'glueckskastanie',
|
||||
];
|
||||
|
||||
// Most of the catalog's German common names are compound nouns ending in one
|
||||
// of these — a hardcoded name list alone (GERMAN_COMMON_NAME_HINTS) only
|
||||
// catches names we've already seen slip through, so this suffix check acts
|
||||
// as a general-purpose backstop for names we haven't hardcoded.
|
||||
const GERMAN_NAME_SUFFIXES = [
|
||||
'blume', 'blueten', 'bluten', 'baum', 'strauch', 'kraut', 'wurz', 'wurzel',
|
||||
'farn', 'palme', 'pflanze', 'hanf', 'tute', 'veilchen', 'dorn', 'kaktus',
|
||||
'lilie', 'birke', 'weide', 'ranke', 'stern', 'kette', 'schwanz', 'ohren',
|
||||
'feige', 'moos', 'zwiebel', 'knolle', 'rohr', 'kirsche',
|
||||
];
|
||||
|
||||
const isLikelyGermanCommonName = (value) => {
|
||||
const raw = String(value || '').trim();
|
||||
if (!raw) return false;
|
||||
@@ -36,11 +47,27 @@ const isLikelyGermanCommonName = (value) => {
|
||||
|
||||
const normalized = normalizeText(raw).replace(/[^a-z0-9 ]+/g, ' ');
|
||||
if (!normalized) return false;
|
||||
if (/\b(der|die|das|ein|eine)\b/.test(normalized)) return true;
|
||||
if (/\b(der|die|das|ein|eine|und|mit|fuer)\b/.test(normalized)) return true;
|
||||
|
||||
const compact = normalized.replace(/\s+/g, '');
|
||||
if (GERMAN_NAME_SUFFIXES.some((suffix) => compact.endsWith(suffix))) return true;
|
||||
|
||||
return GERMAN_COMMON_NAME_HINTS.some((hint) => normalized.includes(hint));
|
||||
};
|
||||
|
||||
// Last-resort safety net applied to the FINAL result regardless of whether
|
||||
// it went through catalog grounding — the AI is instructed to never return a
|
||||
// German name when English was requested, but doesn't always comply, so this
|
||||
// catches the ones that slip through and falls back to the botanical name
|
||||
// (which is language-neutral) rather than showing a mismatched German name
|
||||
// alongside English description/care text.
|
||||
const enforceEnglishName = (result, language) => {
|
||||
if (!result || language !== 'en') return result;
|
||||
if (!isLikelyGermanCommonName(result.name)) return result;
|
||||
if (!result.botanicalName) return result;
|
||||
return { ...result, name: result.botanicalName };
|
||||
};
|
||||
|
||||
const isLikelyBotanicalName = (value, botanicalName) => {
|
||||
const raw = String(value || '').trim();
|
||||
const botanicalRaw = String(botanicalName || '').trim();
|
||||
@@ -124,6 +151,7 @@ const applyCatalogGrounding = (aiResult, catalogEntries, language = 'en') => {
|
||||
|
||||
module.exports = {
|
||||
applyCatalogGrounding,
|
||||
enforceEnglishName,
|
||||
findCatalogMatch,
|
||||
isLikelyGermanCommonName,
|
||||
normalizeText,
|
||||
|
||||
Reference in New Issue
Block a user