Completed
Push — master ( f43547...71985b )
by Chris
12:00 queued 10s
created

abydos.stemmer._s_stemmer   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 116
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B SStemmer.stem() 0 36 8

1 Function

Rating   Name   Duplication   Size   Complexity  
A s_stemmer() 0 30 1
1
# -*- coding: utf-8 -*-
2
3
# Copyright 2018 by Christopher C. Little.
4
# This file is part of Abydos.
5
#
6
# Abydos is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Abydos is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Abydos. If not, see <http://www.gnu.org/licenses/>.
18
19 1
"""abydos.stemmer._s_stemmer.
20
21
S-stemmer.
22
"""
23
24 1
from __future__ import (
25
    absolute_import,
26
    division,
27
    print_function,
28
    unicode_literals,
29
)
30
31 1
from ._stemmer import _Stemmer
32
33 1
__all__ = ['SStemmer', 's_stemmer']
34
35
36 1
class SStemmer(_Stemmer):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
37
    """S-stemmer.
38
39
    The S stemmer is defined in :cite:`Harman:1991`.
40
    """
41
42 1
    def stem(self, word):
0 ignored issues
show
Bug introduced by
Parameters differ from overridden 'stem' method
Loading history...
43
        """Return the S-stemmed form of a word.
44
45
        Parameters
46
        ----------
47
        word : str
48
            The word to stem
49
50
        Returns
51
        -------
52
        str
53
            Word stem
54
55
        Examples
56
        --------
57
        >>> stmr = SStemmer()
58
        >>> stmr.stem('summaries')
59
        'summary'
60
        >>> stmr.stem('summary')
61
        'summary'
62
        >>> stmr.stem('towers')
63
        'tower'
64
        >>> stmr.stem('reading')
65
        'reading'
66
        >>> stmr.stem('census')
67
        'census'
68
69
        """
70 1
        lowered = word.lower()
71 1
        if lowered[-3:] == 'ies' and lowered[-4:-3] not in {'e', 'a'}:
72 1
            return word[:-3] + ('Y' if word[-1:].isupper() else 'y')
73 1
        if lowered[-2:] == 'es' and lowered[-3:-2] not in {'a', 'e', 'o'}:
74 1
            return word[:-1]
75 1
        if lowered[-1:] == 's' and lowered[-2:-1] not in {'u', 's'}:
76 1
            return word[:-1]
77 1
        return word
78
79
80 1
def s_stemmer(word):
81
    """Return the S-stemmed form of a word.
82
83
    This is a wrapper for :py:meth:`SStemmer.stem`.
84
85
    Parameters
86
    ----------
87
    word : str
88
        The word to stem
89
90
    Returns
91
    -------
92
    str
93
        Word stem
94
95
    Examples
96
    --------
97
    >>> s_stemmer('summaries')
98
    'summary'
99
    >>> s_stemmer('summary')
100
    'summary'
101
    >>> s_stemmer('towers')
102
    'tower'
103
    >>> s_stemmer('reading')
104
    'reading'
105
    >>> s_stemmer('census')
106
    'census'
107
108
    """
109 1
    return SStemmer().stem(word)
110
111
112
if __name__ == '__main__':
113
    import doctest
114
115
    doctest.testmod()
116