-
Notifications
You must be signed in to change notification settings - Fork 0
/
whatlang.pyi
126 lines (87 loc) · 2.72 KB
/
whatlang.pyi
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from typing import List, Optional
class Lang:
def __init__(self, lang: str) -> None: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
@property
def iso(self) -> str: ...
def to_iso(self) -> None: ...
class Info:
def __init__(self, lang: str, script: str, confidence: float) -> None: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def to_iso(self) -> None: ...
class Script:
'''
Script of the text
Attributes:
script: Script of the text
'''
def __init__(self, script: str) -> None: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def detect(text: str) -> Info:
'''
Detect language and script of the text
Args:
text: Text to detect
Returns:
Info object with detected language, script and confidence
Raises:
ValueError: If text is empty
Example:
>>> detect('This is English text')
Info(lang='en', script='Latin', confidence=0.96)
>>> detect('Это русский текст')
Info(lang='ru', script='Cyrillic', confidence=0.69)
'''
...
def detect_lang(text: str) -> Lang:
'''
Detect language of the text
Args:
text: Text to detect
Returns:
Lang object with detected language
Raises:
ValueError: If text is empty
Example:
>>> detect_lang('This is English text')
Lang(lang='en')
>>> detect_lang('Это русский текст')
Lang(lang='ru')
'''
...
def detect_script(text: str) -> Script:
'''
Detect script of the text
Args:
text: Text to detect
Returns:
Script object with detected script
Raises:
ValueError: If text is empty
Example:
>>> detect_script('This is English text')
Script(script='Latin')
>>> detect_script('Это русский текст')
Script(script='Cyrillic')
>>> detect_script('これは日本語のテキストです')
Script(script='Han')
'''
...
def batch_detect(texts: List[str], n_jobs: Optional[int] = -1) -> List[Info]:
'''
Detect language and script of the texts
Args:
texts: List of texts to detect
n_jobs: Number of parallel jobs to run. -1 means using all processors
Returns:
List of Info objects with detected language, script and confidence
Raises:
ValueError: If texts is empty
Example:
>>> batch_detect(['This is English text', 'Это русский текст'])
[Info(lang='en', script='Latin', confidence=0.96), Info(lang='ru', script='Cyrillic', confidence=0.69)]
'''
...