| import { prisma } from './prisma'; | |
| import { logger } from '../logger'; | |
| import { redisForBullMQ as connection } from '../lib/redis'; | |
| const CACHE_KEY = 'normalization:rules:wolof'; | |
| export const normalizationService = { | |
| /** | |
| * Get all normalization rules for a language | |
| */ | |
| async getRules(language: string = 'WOLOF'): Promise<Record<string, string>> { | |
| const cacheKey = `${CACHE_KEY}:${language}`; | |
| try { | |
| const cached = await connection.get(cacheKey); | |
| if (cached) return JSON.parse(cached); | |
| } catch (err) { | |
| logger.error({ err }, '[NORMALIZATION] Redis get error'); | |
| } | |
| const rules = await prisma.normalizationRule.findMany({ | |
| where: { language } | |
| }); | |
| const ruleMap: Record<string, string> = {}; | |
| rules.forEach((r: { original: string; replacement: string }) => { | |
| ruleMap[r.original.toLowerCase()] = r.replacement; | |
| }); | |
| return ruleMap; | |
| } | |
| }; | |