diff --git a/stubs/flashtext/METADATA.toml b/stubs/flashtext/METADATA.toml new file mode 100644 index 000000000000..1b35132a370c --- /dev/null +++ b/stubs/flashtext/METADATA.toml @@ -0,0 +1,2 @@ +version = "2.7.*" +upstream-repository = "https://github.com/vi3k6i5/flashtext" diff --git a/stubs/flashtext/flashtext/__init__.pyi b/stubs/flashtext/flashtext/__init__.pyi new file mode 100644 index 000000000000..0a8884c855f3 --- /dev/null +++ b/stubs/flashtext/flashtext/__init__.pyi @@ -0,0 +1 @@ +from .keyword import KeywordProcessor as KeywordProcessor diff --git a/stubs/flashtext/flashtext/keyword.pyi b/stubs/flashtext/flashtext/keyword.pyi new file mode 100644 index 000000000000..2b30bb4402bd --- /dev/null +++ b/stubs/flashtext/flashtext/keyword.pyi @@ -0,0 +1,36 @@ +from _typeshed import Incomplete +from collections.abc import Iterable, Iterator, Mapping +from typing import Literal, overload + +class KeywordProcessor: + case_sensitive: bool + non_word_boundaries: set[str] + keyword_trie_dict: dict[str, Incomplete] + + def __init__(self, case_sensitive: bool = False) -> None: ... + def __len__(self) -> int: ... + def __contains__(self, word: str) -> bool: ... + def __getitem__(self, word: str) -> str | None: ... + def __setitem__(self, keyword: str, clean_name: str | None = None) -> bool: ... + def __delitem__(self, keyword: str) -> bool: ... + def __iter__(self) -> Iterator[str]: ... + def set_non_word_boundaries(self, non_word_boundaries: Iterable[str]) -> None: ... + def add_non_word_boundary(self, character: str) -> None: ... + def add_keyword(self, keyword: str, clean_name: str | None = None) -> bool: ... + def remove_keyword(self, keyword: str) -> bool: ... + def get_keyword(self, word: str) -> str | None: ... + def add_keyword_from_file(self, keyword_file: str, encoding: str = "utf-8") -> None: ... + def add_keywords_from_dict(self, keyword_dict: Mapping[str, Iterable[str]]) -> None: ... + def remove_keywords_from_dict(self, keyword_dict: Mapping[str, Iterable[str]]) -> None: ... + def add_keywords_from_list(self, keyword_list: Iterable[str]) -> None: ... + def remove_keywords_from_list(self, keyword_list: Iterable[str]) -> None: ... + def get_all_keywords(self, term_so_far: str = "", current_dict: dict[str, Incomplete] | None = None) -> dict[str, str]: ... + + @overload + def extract_keywords(self, sentence: str, span_info: Literal[False] = False, max_cost: int = 0) -> list[str]: ... + @overload + def extract_keywords(self, sentence: str, span_info: Literal[True], max_cost: int = 0) -> list[tuple[str, int, int]]: ... + + def replace_keywords(self, sentence: str, max_cost: int = 0) -> str: ... + def get_next_word(self, sentence: str) -> str: ... + def levensthein(self, word: str, max_cost: int = 2, start_node: dict[str, Incomplete] | None = None) -> set[Incomplete]: ...