From 526c6372a430942ee55213872728a9fe63c18679 Mon Sep 17 00:00:00 2001 From: Philipp Hahn Date: Fri, 10 Apr 2020 14:05:04 +0200 Subject: [PATCH] Enchant: Spell checking library for Enchant WIP - [ ] API-2 accepts Union[Text, bytes], see - [ ] API-3 provides new functions and is Pyhton-3-only --- third_party/2and3/enchant/__init__.pyi | 71 +++++++++++++++++++ .../2and3/enchant/checker/CmdLineChecker.pyi | 22 ++++++ .../enchant/checker/GtkSpellCheckerDialog.pyi | 17 +++++ .../2and3/enchant/checker/__init__.pyi | 29 ++++++++ .../enchant/checker/wxSpellCheckerDialog.pyi | 24 +++++++ third_party/2and3/enchant/errors.pyi | 4 ++ third_party/2and3/enchant/pypwl.pyi | 25 +++++++ .../2and3/enchant/tokenize/__init__.pyi | 49 +++++++++++++ third_party/2and3/enchant/tokenize/en.pyi | 6 ++ third_party/2and3/enchant/utils.pyi | 22 ++++++ 10 files changed, 269 insertions(+) create mode 100644 third_party/2and3/enchant/__init__.pyi create mode 100644 third_party/2and3/enchant/checker/CmdLineChecker.pyi create mode 100644 third_party/2and3/enchant/checker/GtkSpellCheckerDialog.pyi create mode 100644 third_party/2and3/enchant/checker/__init__.pyi create mode 100644 third_party/2and3/enchant/checker/wxSpellCheckerDialog.pyi create mode 100644 third_party/2and3/enchant/errors.pyi create mode 100644 third_party/2and3/enchant/pypwl.pyi create mode 100644 third_party/2and3/enchant/tokenize/__init__.pyi create mode 100644 third_party/2and3/enchant/tokenize/en.pyi create mode 100644 third_party/2and3/enchant/utils.pyi diff --git a/third_party/2and3/enchant/__init__.pyi b/third_party/2and3/enchant/__init__.pyi new file mode 100644 index 000000000000..4632803a3028 --- /dev/null +++ b/third_party/2and3/enchant/__init__.pyi @@ -0,0 +1,71 @@ +from enchant.errors import * +from enchant.pypwl import PyPWL as PyPWL +from enchant.utils import EnchantStr as EnchantStr, UTF16EnchantStr as UTF16EnchantStr, get_default_language as get_default_language +from typing import Any, List, Tuple + +class warnings: + def warn(self, *args: Any, **kwds: Any) -> None: ... + +class ProviderDesc: + name: str = ... + desc: str = ... + file: str = ... + def __init__(self, name: str, desc: str, file: str) -> None: ... + def __eq__(self, pd: Any) -> bool: ... + def __hash__(self) -> int: ... + +class _EnchantObject: + def __init__(self) -> None: ... + +class Broker(_EnchantObject): + def __init__(self) -> None: ... + def __del__(self) -> None: ... + def request_dict(self, tag: str = ...) -> Dict: ... + def request_pwl_dict(self, pwl: str) -> Dict: ... + def dict_exists(self, tag: str) -> bool: ... + def set_ordering(self, tag: str, ordering: str) -> None: ... + def describe(self) -> List[ProviderDesc]: ... + def list_dicts(self) -> List[Tuple[str, ProviderDesc]]: ... + def list_languages(self) -> List[str]: ... + def get_param(self, name: str) -> Any: ... + def set_param(self, name: str, value: Any) -> None: ... + +class Dict(_EnchantObject): + provider: ProviderDesc = ... + tag: str = ... + def __init__(self, tag: str = ..., broker: Broker = ...) -> None: ... + def __del__(self) -> None: ... + def check(self, word: str) -> bool: ... + def suggest(self, word: str) -> List[str]: ... + def add(self, word: str) -> None: ... + def remove(self, word: str) -> None: ... + def add_to_pwl(self, word: str) -> None: ... + def add_to_session(self, word: str) -> None: ... + def remove_from_session(self, word: str) -> None: ... + def is_added(self, word: str) -> bool: ... + def is_removed(self, word: str) -> bool: ... + def store_replacement(self, mis: str, cor: str) -> None: ... + +class DictWithPWL(Dict): + pwl: Dict = ... + pel: Dict = ... + def __init__(self, tag: str, pwl: str = ..., pel: str = ..., broker: Broker = ...) -> None: ... + def check(self, word: str) -> bool: ... + def suggest(self, word: str) -> List[str]: ... + def add(self, word: str) -> None: ... + def remove(self, word: str) -> None: ... + def add_to_pwl(self, word: str) -> None: ... + def is_added(self, word: str) -> bool: ... + def is_removed(self, word: str) -> bool: ... + +def request_dict(self, tag: str = ...) -> Dict: ... +def request_pwl_dict(self, pwl: str) -> Dict: ... +def dict_exists(tag: str) -> bool: ... +def list_dicts() -> List[Tuple[str, ProviderDesc]]: ... +def list_languages() -> List[str]: ... +def get_param(name: str) -> Any: ... +def set_param(name: str, value: Any) -> None: ... + +def get_enchant_version() -> str: ... +def set_prefix_dir(path: str) -> None: ... +def get_user_config_dir() -> str: ... diff --git a/third_party/2and3/enchant/checker/CmdLineChecker.pyi b/third_party/2and3/enchant/checker/CmdLineChecker.pyi new file mode 100644 index 000000000000..23ba02aa65b8 --- /dev/null +++ b/third_party/2and3/enchant/checker/CmdLineChecker.pyi @@ -0,0 +1,22 @@ +from enchant.checker import SpellChecker +from typing import Dict, Optional + +colors: Dict[str, str] + +def color(string: str, color: str = ..., prefix: str = ...): ... +def success(string: str): ... +def error(string: str): ... +def warning(string: str): ... +def info(string: str): ... + +class CmdLineChecker: + def __init__(self) -> None: ... + def set_checker(self, chkr: SpellChecker) -> None: ... + def get_checker(self, chkr: SpellChecker) -> SpellChecker: ... + # error: Any = ... + def run(self) -> None: ... + def print_error(self) -> None: ... + def print_suggestions(self) -> None: ... + def print_help(self) -> None: ... + def read_command(self) -> bool: ... + def run_on_file(self, infile: str, outfile: str = ..., enc: str = ...) -> None: ... diff --git a/third_party/2and3/enchant/checker/GtkSpellCheckerDialog.pyi b/third_party/2and3/enchant/checker/GtkSpellCheckerDialog.pyi new file mode 100644 index 000000000000..19921e036e5d --- /dev/null +++ b/third_party/2and3/enchant/checker/GtkSpellCheckerDialog.pyi @@ -0,0 +1,17 @@ +import gtk +from enchant.checker import SpellChecker +from typing import Any + +COLUMN_SUGGESTION: int + +# def create_list_view(col_label: Any): ... + +class GtkSpellCheckerDialog(gtk.Window): + # errors: Any = ... + # error_text: Any = ... + # replace_text: Any = ... + # suggestion_list_view: Any = ... + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def setSpellChecker(self, checker: SpellChecker) -> None: ... + def getSpellChecker(self, checker: SpellChecker): ... + def updateUI(self) -> None: ... diff --git a/third_party/2and3/enchant/checker/__init__.pyi b/third_party/2and3/enchant/checker/__init__.pyi new file mode 100644 index 000000000000..dbd107083d4e --- /dev/null +++ b/third_party/2and3/enchant/checker/__init__.pyi @@ -0,0 +1,29 @@ +from enchant.errors import * +from enchant.tokenize import get_tokenizer as get_tokenizer, tokenize, Chunker, Filter +from enchant.utils import get_default_language as get_default_language +from enchant import Dict +from typing import Iterator, List, Optional, Union, Type + +class SpellChecker: + lang: str = ... + dict: Dict = ... + word: Optional[str] = ... + wordpos: Optional[int] = ... + def __init__(self, lang: Union[Dict, str] = ..., text: str = ..., tokenize: Union[Type[tokenize], Filter] = ..., chunkers: List[Chunker] = ..., filters: List[Filter] = ...) -> None: ... + def __iter__(self) -> Iterator[SpellChecker]: ... + def set_text(self, text: str) -> None: ... + def get_text(self) -> str: ... + def wants_unicode(self) -> bool: ... + def coerce_string(self, text: str, enc: str = ...) -> str: ... + def __next__(self) -> SpellChecker: ... + def next(self) -> SpellChecker: ... + def replace(self, repl: str) -> None: ... + def replace_always(self, word: str, repl: str = ...) -> None: ... + def ignore_always(self, word: str = ...) -> None: ... + def add_to_personal(self, word: str = ...) -> None: ... + def add(self, word: str = ...) -> None: ... + def suggest(self, word: str = ...) -> List[str]: ... + def check(self, word: str) -> bool: ... + def set_offset(self, off: int, whence: int = ...) -> None: ... + def leading_context(self, chars: int) -> str: ... + def trailing_context(self, chars: int) -> str: ... diff --git a/third_party/2and3/enchant/checker/wxSpellCheckerDialog.pyi b/third_party/2and3/enchant/checker/wxSpellCheckerDialog.pyi new file mode 100644 index 000000000000..54fc3b9c5c68 --- /dev/null +++ b/third_party/2and3/enchant/checker/wxSpellCheckerDialog.pyi @@ -0,0 +1,24 @@ +import wx +from enchant.checker import SpellChecker +from typing import Any, Optional + +class wxSpellCheckerDialog(wx.Dialog): + # sz: Any = ... + # error_text: Any = ... + # replace_text: Any = ... + # replace_list: Any = ... + def __init__(self, parent: Optional[Any] = ..., id: int = ..., title: str = ...) -> None: ... + # buttons: Any = ... + def InitLayout(self) -> None: ... + def Advance(self) -> bool: ... + def EnableButtons(self, state: bool = ...) -> None: ... + def GetRepl(self) -> str: ... + def OnAdd(self, evt: Any) -> None: ... + def OnDone(self, evt: Any) -> None: ... + def OnIgnore(self, evt: Any) -> None: ... + def OnIgnoreAll(self, evt: Any) -> None: ... + def OnReplace(self, evt: Any) -> None: ... + def OnReplaceAll(self, evt: Any) -> None: ... + def OnReplSelect(self, evt: Any) -> None: ... + def GetSpellChecker(self) -> SpellChecker: ... + def SetSpellChecker(self, chkr: SpellChecker) -> bool: ... diff --git a/third_party/2and3/enchant/errors.pyi b/third_party/2and3/enchant/errors.pyi new file mode 100644 index 000000000000..e4410208edea --- /dev/null +++ b/third_party/2and3/enchant/errors.pyi @@ -0,0 +1,4 @@ +class Error(Exception): ... +class DictNotFoundError(Error): ... +class TokenizerNotFoundError(Error): ... +class DefaultLanguageNotFoundError(Error): ... diff --git a/third_party/2and3/enchant/pypwl.pyi b/third_party/2and3/enchant/pypwl.pyi new file mode 100644 index 000000000000..a49a2366fbc0 --- /dev/null +++ b/third_party/2and3/enchant/pypwl.pyi @@ -0,0 +1,25 @@ +from typing import Any, Iterable, Iterator, List, Optional + +class Trie: + def __init__(self, words: Iterable[str] = ...) -> None: ... + def insert(self, word: str) -> None: ... + def remove(self, word: str) -> None: ... + def search(self, word: str, nerrs: int = ...) -> List[str]: ... + def __getitem__(self, key: str) -> Trie: ... + def __setitem__(self, key: str, val: Trie) -> None: ... + def __iter__(self) -> Iterator[str]: ... + +class PyPWL: + provider: None = ... + pwl: Optional[str] = ... + tag: str = ... + def __init__(self, pwl: str = ...) -> None: ... + def check(self, word: str) -> bool: ... + def suggest(self, word: str) -> List[str]: ... + def add(self, word: str) -> None: ... + def add_to_pwl(self, word: str) -> None: ... + def remove(self, word: str) -> None: ... + def add_to_session(self, word: str) -> None: ... + def store_replacement(self, mis: str, cor: str) -> None: ... + def is_added(self, word: str) -> bool: ... + def is_removed(self, word: str) -> bool: ... diff --git a/third_party/2and3/enchant/tokenize/__init__.pyi b/third_party/2and3/enchant/tokenize/__init__.pyi new file mode 100644 index 000000000000..ed74e59c64fa --- /dev/null +++ b/third_party/2and3/enchant/tokenize/__init__.pyi @@ -0,0 +1,49 @@ +# from enchant.errors import * +from typing import Any, Callable, Iterable, Iterator, Optional, Tuple, Type, Union +from typing_extensions import Protocol +Token = Tuple[str, int] + +# Error = TokenizerNotFoundError + +class tokenize(Protocol): + def __init__(self, text: str) -> None: ... + def __next__(self) -> Token: ... + def next(self) -> Token: ... + def __iter__(self) -> Iterator[Token]: ... + def set_offset(self, offset: int, replaced: bool = ...) -> None: ... + offset: int = ... + +class empty_tokenize(tokenize): + def __init__(self) -> None: ... + +class unit_tokenize(tokenize): + def __init__(self, text: str) -> None: ... + +class basic_tokenize(tokenize): + strip_from_start: str = ... + strip_from_end: str = ... + +class Chunker(tokenize): ... + +_Filter = Union[Type[tokenize], Filter] + +class Filter(tokenize): + def __init__(self, tokenizer: _Filter) -> None: ... + def __call__(self, *args: Any, **kwds: Any) -> tokenize: ... + def _skip(self, word: str) -> bool: ... + def _split(self, word: str) -> tokenize: ... + class _TokenFilter(tokenize): + def __init__(self, tokenizer: _Filter, skip: Callable[[str], bool], split: Callable[[str], tokenize]) -> None: ... + +def wrap_tokenizer(tk1: _Filter, tk2: _Filter) -> Filter: ... + +class URLFilter(Filter): ... +class WikiWordFilter(Filter): ... +class EmailFilter(Filter): ... +class MentionFilter(Filter): ... +class HashtagFilter(Filter): ... + +class HTMLChunker(Chunker): + def next(self) -> Token: ... + +def get_tokenizer(tag: str = ..., chunkers: Iterable[Chunker] = ..., filters: Iterable[Filter] = ...) -> tokenize: ... diff --git a/third_party/2and3/enchant/tokenize/en.pyi b/third_party/2and3/enchant/tokenize/en.pyi new file mode 100644 index 000000000000..ad2aa34d2b80 --- /dev/null +++ b/third_party/2and3/enchant/tokenize/en.pyi @@ -0,0 +1,6 @@ +import enchant.tokenize +from typing import Container + +class tokenize(enchant.tokenize.tokenize): + def __init__(self, text: str, valid_chars: Container[str] = ...) -> None: ... + def next(self) -> enchant.tokenize.Token: ... diff --git a/third_party/2and3/enchant/utils.pyi b/third_party/2and3/enchant/utils.pyi new file mode 100644 index 000000000000..bca59fb1749f --- /dev/null +++ b/third_party/2and3/enchant/utils.pyi @@ -0,0 +1,22 @@ +from enchant.errors import * +from typing import Any, Callable, IO, Iterable, List, Optional, Text, Tuple + +def raw_unicode(raw: bytes) -> Text: ... +def raw_bytes(raw: Any) -> bytes: ... + +class EnchantStr(str): + def __new__(cls, value: Any): ... + def encode(self) -> bytes: ... # type: ignore + def decode(self, value: Any) -> Text: ... # type: ignore + +class UTF16EnchantStr(EnchantStr): + REPLACEMENT_CHAR: str = ... + def encode(self) -> bytes: ... # type: ignore + +def printf(values: Iterable[Any], sep: str = ..., end: str = ..., file: IO[str] = ...) -> None: ... + +def levenshtein(s1: str, s2: str) -> int: ... +def trim_suggestions(word: str, suggs: Iterable[str], maxlen: int, calcdist: Callable[[str, str], int] = ...) -> List[str]: ... +def get_default_language(default: str = ...) -> str: ... +def get_resource_filename(resname: str) -> str: ... +def win32_data_files() -> List[Tuple[str, List[str]]]: ...