Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
274 additions
and
234 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
"""Word stemming utilities for Sphinx.""" | ||
|
||
import snowballstemmer | ||
|
||
from sphinx.util.stemmer.porter import PorterStemmer | ||
|
||
try: | ||
from Stemmer import Stemmer as _PyStemmer | ||
PYSTEMMER = True | ||
except ImportError: | ||
PYSTEMMER = False | ||
|
||
|
||
class BaseStemmer: | ||
def stem(self, word: str) -> str: | ||
raise NotImplementedError | ||
raise NotImplementedError() | ||
|
||
|
||
def get_stemmer() -> BaseStemmer: | ||
stemmer = snowballstemmer.stemmer('english') | ||
class PyStemmer(BaseStemmer): | ||
def __init__(self) -> None: | ||
self.stemmer = _PyStemmer('porter') | ||
|
||
def stem(self, word: str) -> str: | ||
return self.stemmer.stemWord(word) | ||
|
||
|
||
class StandardStemmer(PorterStemmer, BaseStemmer): | ||
"""All those porter stemmer implementations look hideous; | ||
make at least the stem method nicer. | ||
""" | ||
def stem(self, word: str) -> str: # type: ignore | ||
return super().stem(word, 0, len(word) - 1) | ||
|
||
|
||
def get_stemmer() -> BaseStemmer: | ||
if PYSTEMMER: | ||
return PyStemmer() | ||
else: | ||
return StandardStemmer() |
Oops, something went wrong.