forked from mozillazg/python-pinyin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mozillazg#110 from mozillazg/typing
增加类型注解
- Loading branch information
Showing
34 changed files
with
470 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include README.rst LICENSE.txt CHANGELOG.rst | ||
recursive-include pypinyin *.pyi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Any | ||
|
||
from . import compat | ||
from . import constants | ||
from . import core | ||
|
||
__title__ = ... # type: Any | ||
__version__ = ... # type: Any | ||
__author__ = ... # type: Any | ||
__license__ = ... # type: Any | ||
__copyright__ = ... # type: Any | ||
__all__ = ... # type: Any | ||
|
||
PY2 = compat.PY2 | ||
|
||
Style = constants.Style | ||
STYLE_NORMAL = constants.STYLE_NORMAL | ||
NORMAL = constants.NORMAL | ||
STYLE_TONE = constants.STYLE_TONE | ||
TONE = constants.TONE | ||
STYLE_TONE2 = constants.STYLE_TONE2 | ||
TONE2 = constants.TONE2 | ||
STYLE_TONE3 = constants.STYLE_TONE3 | ||
TONE3 = constants.TONE3 | ||
STYLE_INITIALS = constants.STYLE_INITIALS | ||
INITIALS = constants.INITIALS | ||
STYLE_FIRST_LETTER = constants.STYLE_FIRST_LETTER | ||
FIRST_LETTER = constants.FIRST_LETTER | ||
STYLE_FINALS = constants.STYLE_FINALS | ||
FINALS = constants.FINALS | ||
STYLE_FINALS_TONE = constants.STYLE_FINALS_TONE | ||
FINALS_TONE = constants.FINALS_TONE | ||
STYLE_FINALS_TONE2 = constants.STYLE_FINALS_TONE2 | ||
FINALS_TONE2 = constants.FINALS_TONE2 | ||
STYLE_FINALS_TONE3 = constants.STYLE_FINALS_TONE3 | ||
FINALS_TONE3 = constants.FINALS_TONE3 | ||
STYLE_BOPOMOFO = constants.STYLE_BOPOMOFO | ||
BOPOMOFO = constants.BOPOMOFO | ||
STYLE_BOPOMOFO_FIRST = constants.STYLE_BOPOMOFO_FIRST | ||
BOPOMOFO_FIRST = constants.BOPOMOFO_FIRST | ||
STYLE_CYRILLIC = constants.STYLE_CYRILLIC | ||
CYRILLIC = constants.CYRILLIC | ||
STYLE_CYRILLIC_FIRST = constants.STYLE_CYRILLIC_FIRST | ||
CYRILLIC_FIRST = constants.CYRILLIC_FIRST | ||
|
||
pinyin = core.pinyin | ||
lazy_pinyin = core.lazy_pinyin | ||
slug = core.slug | ||
load_single_dict = core.load_single_dict | ||
load_phrases_dict = core.load_phrases_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import sys | ||
|
||
from pypinyin.runner import main | ||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from enum import IntEnum, unique | ||
from typing import Dict, List, Any, Text | ||
|
||
PHRASES_DICT = ... # type: Dict[Text, List[List[Text]]] | ||
|
||
PINYIN_DICT = ... # type: Dict[int, Text] | ||
|
||
RE_TONE2 = ... # type: Any | ||
|
||
RE_HANS = ... # type: Any | ||
|
||
|
||
@unique | ||
class Style(IntEnum): | ||
|
||
NORMAL = ... | ||
|
||
TONE = ... | ||
|
||
TONE2 = ... | ||
|
||
TONE3 = ... | ||
|
||
INITIALS = ... | ||
|
||
FIRST_LETTER = ... | ||
|
||
FINALS = ... | ||
|
||
FINALS_TONE = ... | ||
|
||
FINALS_TONE2 = ... | ||
|
||
FINALS_TONE3 = ... | ||
|
||
BOPOMOFO = ... | ||
|
||
BOPOMOFO_FIRST = ... | ||
|
||
CYRILLIC = ... | ||
|
||
CYRILLIC_FIRST = ... | ||
|
||
|
||
NORMAL = ... # type: Style | ||
STYLE_NORMAL = ... # type: Style | ||
TONE = ... # type: Style | ||
STYLE_TONE = ... # type: Style | ||
TONE2 = ... # type: Style | ||
STYLE_TONE2 = ... # type: Style | ||
TONE3 = ... # type: Style | ||
STYLE_TONE3 = ... # type: Style | ||
INITIALS = ... # type: Style | ||
STYLE_INITIALS = ... # type: Style | ||
FIRST_LETTER = ... # type: Style | ||
STYLE_FIRST_LETTER = ... # type: Style | ||
FINALS = ... # type: Style | ||
STYLE_FINALS = ... # type: Style | ||
FINALS_TONE = ... # type: Style | ||
STYLE_FINALS_TONE = ... # type: Style | ||
FINALS_TONE2 = ... # type: Style | ||
STYLE_FINALS_TONE2 = ... # type: Style | ||
FINALS_TONE3 = ... # type: Style | ||
STYLE_FINALS_TONE3 = ... # type: Style | ||
BOPOMOFO = ... # type: Style | ||
STYLE_BOPOMOFO = ... # type: Style | ||
BOPOMOFO_FIRST = ... # type: Style | ||
STYLE_BOPOMOFO_FIRST = ... # type: Style | ||
CYRILLIC = ... # type: Style | ||
STYLE_CYRILLIC = ... # type: Style | ||
CYRILLIC_FIRST = ... # type: Style | ||
STYLE_CYRILLIC_FIRST = ... # type: Style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Iterator | ||
from typing import Text | ||
|
||
|
||
class Seg(object): | ||
"""最大正向匹配分词 | ||
:type prefix_set: PrefixSet | ||
""" | ||
def __init__(self, prefix_set: PrefixSet) -> None: ... | ||
|
||
def cut(self, text: Text) -> Iterator[Text]: ... | ||
|
||
def train(self, words: Iterator[Text]) -> None: ... | ||
|
||
|
||
class PrefixSet(object): | ||
def __init__(self): ... | ||
|
||
def train(self, word_s: Iterator[Text]) -> None: ... | ||
|
||
def __contains__(self, key: Text) -> bool: ... | ||
|
||
|
||
p_set = ... # type: PrefixSet | ||
seg = ... # type: Seg | ||
|
||
|
||
def retrain(seg_instance: Seg) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from typing import List | ||
from typing import Dict | ||
from typing import Union | ||
from typing import Callable | ||
from typing import Optional | ||
from typing import Text | ||
|
||
from pypinyin.constants import Style | ||
|
||
|
||
TStyle = Style | ||
TErrors = Union[Callable[[Text], Text], Text] | ||
TPinyinResult = List[List[Text]] | ||
|
||
|
||
def seg(hans: Text) -> List[Text]: ... | ||
|
||
|
||
def load_single_dict(pinyin_dict: Dict[int, Text], | ||
style: str = ...) -> None: ... | ||
|
||
|
||
def load_phrases_dict(phrases_dict: Dict[Text, List[List[Text]]], | ||
style: str = ... | ||
) -> None: ... | ||
|
||
|
||
def to_fixed(pinyin: Text, style: TStyle, | ||
strict: bool = ...) -> Text: ... | ||
|
||
|
||
def _handle_nopinyin_char(chars: Text, errors: TErrors = ... | ||
) -> Optional[Text]: ... | ||
|
||
|
||
def handle_nopinyin(chars: Text, errors: TErrors = ... | ||
) -> List[Text]: ... | ||
|
||
|
||
def single_pinyin(han: Text, style: TStyle, heteronym: bool, | ||
errors: TErrors = ..., | ||
strict: bool = ... | ||
) -> List[Text]: ... | ||
|
||
|
||
def phrase_pinyin(phrase: Text, | ||
style: TStyle, | ||
heteronym: bool, | ||
errors: TErrors = ..., | ||
strict: bool = ... | ||
) -> List[List[Text]]: ... | ||
|
||
|
||
def _pinyin(words: Text, | ||
style: TStyle, | ||
heteronym: bool, | ||
errors: TErrors, | ||
strict: bool = ... | ||
) -> List[List[Text]]:... | ||
|
||
|
||
def pinyin(hans: Union[List[Text], Text], | ||
style: TStyle = ..., | ||
heteronym: bool = ..., | ||
errors: TErrors = ..., | ||
strict: bool = ... | ||
) -> List[List[Text]]: ... | ||
|
||
|
||
def slug(hans: Union[List[Text], Text], | ||
style: TStyle = ..., | ||
heteronym: bool = ..., | ||
separator: Text = ..., | ||
errors: TErrors = ..., | ||
strict: bool = ... | ||
) -> Text: ... | ||
|
||
|
||
def lazy_pinyin(hans: Union[List[Text], Text], | ||
style: TStyle = ..., | ||
errors: TErrors = ..., | ||
strict: bool = ... | ||
) -> List[Text]: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from typing import Dict, Text | ||
|
||
|
||
phonetic_symbol = ... # type: Dict[Text, Text] | ||
phonetic_symbol_reverse = ... # type: Dict[Text, Text] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from typing import Dict, List, Text | ||
|
||
phrases_dict = ... # type: Dict[Text, List[List[Text]]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from typing import Dict, Text | ||
|
||
pinyin_dict = ... # type: Dict[int, Text] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from argparse import ArgumentParser | ||
from typing import Union, Text, ByteString | ||
|
||
|
||
class NullWriter(object): | ||
def write(self, string: Union[Text, ByteString]) -> None: ... | ||
|
||
|
||
def get_parser() -> ArgumentParser: ... | ||
|
||
|
||
def main() -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Text | ||
|
||
def convert_zero_consonant(pinyin: Text) -> Text: ... | ||
|
||
|
||
def convert_uv(pinyin: Text) -> Text: ... | ||
|
||
|
||
def convert_iou(pinyin: Text) -> Text: ... | ||
|
||
|
||
def convert_uei(pinyin: Text) -> Text: ... | ||
|
||
|
||
def convert_uen(pinyin: Text) -> Text: ... | ||
|
||
|
||
def convert_finals(pinyin: Text) -> Text: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
from typing import Any, Optional, Callable, Dict, Text, Union | ||
|
||
from pypinyin.constants import Style | ||
|
||
TStyle = Style | ||
TRegisterFunc = Optional[Callable[[Text, Dict[Any, Any]], Optional[Text]]] | ||
TWrapperFunc = Optional[Callable[[Text, Dict[Any, Any]], Optional[Text]]] | ||
|
||
_registry = {} # type: Dict[Union[TStyle, int, str, Any], TRegisterFunc] | ||
|
||
|
||
def convert(pinyin: Text, style: TStyle, strict: bool, | ||
default: Optional[Text] = ..., **kwargs: Any) -> Any: ... | ||
|
||
|
||
def register(style: Union[TStyle, int, str, Any], | ||
func: TRegisterFunc = ...) -> TWrapperFunc: ... | ||
|
||
def auto_discover() -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from typing import Any, List, Dict, Text | ||
|
||
|
||
_INITIALS = ... # type: List[Text] | ||
|
||
_INITIALS_NOT_STRICT = ... # type: List[Text] | ||
|
||
|
||
PHONETIC_SYMBOL_DICT = ... # type: Dict[Text, Text] | ||
|
||
RE_PHONETIC_SYMBOL = ... # type : Any | ||
|
||
|
||
RE_TONE2 = ... # type : Any | ||
|
||
RE_TONE3 = ... # type : Any | ||
|
||
|
||
RE_NUMBER = ... # type: Any |
Oops, something went wrong.