Legend
2024-12-15 5e7a8d1ccae80e54f2e2ecfffdf8e4294800b5c3
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
import pynini
from fun_text_processing.text_normalization.zh.graph_utils import (
    FUN_NOT_QUOTE,
    GraphFst,
    delete_space,
)
from pynini.lib import pynutil
 
 
class Money(GraphFst):
    """
    tokens { money { integer_part: "一点五" fractional_part: "元" } } ->  一点五元
    """
 
    def __init__(self, deterministic: bool = True, lm: bool = False):
        super().__init__(name="money", kind="verbalize", deterministic=deterministic)
 
        cur = (
            pynutil.delete('fractional_part: "')
            + pynini.closure(FUN_NOT_QUOTE)
            + pynutil.delete('"')
        )
        num = (
            pynutil.delete('integer_part: "')
            + pynini.closure(FUN_NOT_QUOTE)
            + pynutil.delete('"')
            + delete_space
        )
        graph = num + cur
 
        self.fst = self.delete_tokens(graph).optimize()