fix: api
Browse files- font_dataset/text.py +11 -8
font_dataset/text.py
CHANGED
@@ -3,10 +3,7 @@ import requests
|
|
3 |
from .font import DSFont
|
4 |
from .helper import char_in_font
|
5 |
|
6 |
-
__all__ = [
|
7 |
-
"random_char",
|
8 |
-
"CorpusGenerationConfig",
|
9 |
-
]
|
10 |
|
11 |
# https://zh.wikipedia.org/zh-hans/%E5%B9%B3%E5%81%87%E5%90%8D
|
12 |
hiragana = (
|
@@ -194,12 +191,18 @@ class CorpusGeneratorManager:
|
|
194 |
"ko": KoreanRandomCorpusGeneratorWithEnglish(),
|
195 |
}
|
196 |
|
197 |
-
def
|
|
|
|
|
|
|
|
|
198 |
for k, v in self.generators.items():
|
199 |
-
if
|
200 |
return v
|
201 |
|
202 |
raise Exception(f"no generator for {font.language}")
|
203 |
|
204 |
-
def generate(
|
205 |
-
|
|
|
|
|
|
3 |
from .font import DSFont
|
4 |
from .helper import char_in_font
|
5 |
|
6 |
+
__all__ = ["random_char", "CorpusGenerationConfig", "CorpusGeneratorManager"]
|
|
|
|
|
|
|
7 |
|
8 |
# https://zh.wikipedia.org/zh-hans/%E5%B9%B3%E5%81%87%E5%90%8D
|
9 |
hiragana = (
|
|
|
191 |
"ko": KoreanRandomCorpusGeneratorWithEnglish(),
|
192 |
}
|
193 |
|
194 |
+
def _get_generator(
|
195 |
+
self, font: DSFont, CJK_language: str = None
|
196 |
+
) -> CommonCorpusGenerator:
|
197 |
+
langauge = CJK_language if CJK_language is not None else font.language
|
198 |
+
|
199 |
for k, v in self.generators.items():
|
200 |
+
if langauge.startswith(k):
|
201 |
return v
|
202 |
|
203 |
raise Exception(f"no generator for {font.language}")
|
204 |
|
205 |
+
def generate(
|
206 |
+
self, config: CorpusGenerationConfig, font: DSFont, CJK_language: str = None
|
207 |
+
) -> str:
|
208 |
+
return self._get_generator(font, CJK_language).generate(config, font)
|