File size: 1,002 Bytes
cfbb685
 
a966957
cfbb685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b0c22b
cfbb685
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
    }
};