File size: 1,058 Bytes
4fa0613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
import os

class SignGenerationService:
    def __init__(self, assets_dir=None):
        if assets_dir is None:
            base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
            assets_dir = os.path.join(base_dir, "assets")
        self.assets_dir = assets_dir
        self.assets_map = self._build_assets_map()

    def _build_assets_map(self):
        assets_map = {}
        if not os.path.exists(self.assets_dir):
            return assets_map
            
        for filename in os.listdir(self.assets_dir):
            name = os.path.splitext(filename)[0].lower()
            assets_map[name] = filename
        return assets_map

    def get_sign_sequence(self, text):
        if not text:
            return []
            
        words = text.lower().strip().split()
        sequence = []
        for word in words:
            if word in self.assets_map:
                sequence.append({
                    "word": word,
                    "asset": self.assets_map[word]
                })
        return sequence