Completed
Pull Request — master (#149)
by Chris
11:34
created

abydos.stemmer._clef_german   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 125
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B CLEFGerman.stem() 0 43 7

1 Function

Rating   Name   Duplication   Size   Complexity  
A clef_german() 0 26 1
1
# -*- coding: utf-8 -*-
2
3
# Copyright 2014-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._clef_german.
20
21
CLEF German stemmer
22
"""
23
24 1
from __future__ import (
25
    absolute_import,
26
    division,
27
    print_function,
28
    unicode_literals,
29
)
30
31 1
from unicodedata import normalize
32
33 1
from six import text_type
34
35 1
from ._stemmer import _Stemmer
36
37 1
__all__ = ['CLEFGerman', 'clef_german']
38
39
40 1
class CLEFGerman(_Stemmer):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
41
    """CLEF German stemmer.
42
43
    The CLEF German stemmer is defined at :cite:`Savoy:2005`.
44
    """
45
46 1
    _umlauts = dict(zip((ord(_) for _ in 'äöü'), 'aou'))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable _ does not seem to be defined.
Loading history...
47
48 1
    def stem(self, word):
0 ignored issues
show
Bug introduced by
Parameters differ from overridden 'stem' method
Loading history...
49
        """Return CLEF German stem.
50
51
        Parameters
52
        ----------
53
        word : str
54
            The word to stem
55
56
        Returns
57
        -------
58
        str
59
            Word stem
60
61
        Examples
62
        --------
63
        >>> stmr = CLEFGerman()
64
        >>> stmr.stem('lesen')
65
        'lese'
66
        >>> stmr.stem('graues')
67
        'grau'
68
        >>> stmr.stem('buchstabieren')
69
        'buchstabier'
70
71
        """
72
        # lowercase, normalize, and compose
73 1
        word = normalize('NFC', text_type(word.lower()))
74
75
        # remove umlauts
76 1
        word = word.translate(self._umlauts)
77
78
        # remove plurals
79 1
        wlen = len(word) - 1
80
81 1
        if wlen > 3:
82 1
            if wlen > 5:
83 1
                if word[-3:] == 'nen':
84 1
                    return word[:-3]
85 1
            if wlen > 4:
86 1
                if word[-2:] in {'en', 'se', 'es', 'er'}:
87 1
                    return word[:-2]
88 1
            if word[-1] in {'e', 'n', 'r', 's'}:
89 1
                return word[:-1]
90 1
        return word
91
92
93 1
def clef_german(word):
94
    """Return CLEF German stem.
95
96
    This is a wrapper for :py:meth:`CLEFGerman.stem`.
97
98
    Parameters
99
    ----------
100
    word : str
101
        The word to stem
102
103
    Returns
104
    -------
105
    str
106
        Word stem
107
108
    Examples
109
    --------
110
    >>> clef_german('lesen')
111
    'lese'
112
    >>> clef_german('graues')
113
    'grau'
114
    >>> clef_german('buchstabieren')
115
    'buchstabier'
116
117
    """
118 1
    return CLEFGerman().stem(word)
119
120
121
if __name__ == '__main__':
122
    import doctest
123
124
    doctest.testmod()
125