|
| 1 | +# Copyright (c) 2024 Zhendong Peng (pzd17@tsinghua.org.cn) |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from pynini import string_file |
| 16 | +from pynini.lib.pynutil import insert |
| 17 | + |
| 18 | +from tn.processor import Processor |
| 19 | +from tn.utils import get_abs_path |
| 20 | + |
| 21 | + |
| 22 | +class TrainNumber(Processor): |
| 23 | + |
| 24 | + def __init__(self): |
| 25 | + super().__init__(name="trainnumber") |
| 26 | + self.build_tagger() |
| 27 | + self.build_verbalizer() |
| 28 | + |
| 29 | + def build_tagger(self): |
| 30 | + digit = string_file(get_abs_path("../itn/chinese/data/number/digit.tsv")) |
| 31 | + zero = string_file(get_abs_path("../itn/chinese/data/number/zero.tsv")) |
| 32 | + digits = zero | digit |
| 33 | + prefix = string_file(get_abs_path("../itn/chinese/data/train_number/prefix.tsv")) |
| 34 | + number = digits + digits + (digits + digits.ques).ques |
| 35 | + tagger = insert('value: "') + prefix + number + insert('"') |
| 36 | + self.tagger = self.add_tokens(tagger) |
0 commit comments