techiaith-speech-normalizer 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- techiaith/speech_normalizer/__init__.py +9 -0
- techiaith/speech_normalizer/tokenization.py +33 -0
- techiaith/speech_normalizer/welsh_data.py +769 -0
- techiaith/speech_normalizer/welsh_normalizer.py +673 -0
- techiaith/speech_normalizer/welsh_number_normalizer.py +587 -0
- techiaith_speech_normalizer-0.2.0.dist-info/METADATA +372 -0
- techiaith_speech_normalizer-0.2.0.dist-info/RECORD +10 -0
- techiaith_speech_normalizer-0.2.0.dist-info/WHEEL +4 -0
- techiaith_speech_normalizer-0.2.0.dist-info/entry_points.txt +2 -0
- techiaith_speech_normalizer-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Welsh Speech Normalizer.
|
|
2
|
+
|
|
3
|
+
Normalizes Welsh speech transcriptions into standard written Welsh.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from .welsh_normalizer import WelshNormalizer
|
|
7
|
+
from .welsh_number_normalizer import WelshNumberNormalizer
|
|
8
|
+
|
|
9
|
+
__all__ = ["WelshNormalizer", "WelshNumberNormalizer"]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import List, Tuple
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def tokenize_with_punctuation(text: str) -> List[Tuple[str, str]]:
|
|
6
|
+
tokens = []
|
|
7
|
+
|
|
8
|
+
# Pattern: word characters with apostrophes as part of words, whitespace, or single punctuation
|
|
9
|
+
pattern = re.compile(r"(\w+(?:'\w*)*|\s+|\S)")
|
|
10
|
+
|
|
11
|
+
for match in pattern.finditer(text):
|
|
12
|
+
token = match.group(0)
|
|
13
|
+
if token.isspace():
|
|
14
|
+
tokens.append((token, 'space'))
|
|
15
|
+
elif re.match(r'\w', token):
|
|
16
|
+
tokens.append((token, 'word'))
|
|
17
|
+
else:
|
|
18
|
+
# Only treat as punctuation if it's not an apostrophe
|
|
19
|
+
if token == "'":
|
|
20
|
+
# Standalone apostrophe - could be word or punct depending on context
|
|
21
|
+
# Treat as punct for now
|
|
22
|
+
tokens.append((token, 'punct'))
|
|
23
|
+
else:
|
|
24
|
+
tokens.append((token, 'punct'))
|
|
25
|
+
|
|
26
|
+
return tokens
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def detokenize(tokens: List[Tuple[str, str]]) -> str:
|
|
30
|
+
"""
|
|
31
|
+
Reconstruct text from tokenized list, preserving spaces and punctuation.
|
|
32
|
+
"""
|
|
33
|
+
return ''.join(token for token, _ in tokens)
|