Completed
Pull Request — master (#141)
by Chris
11:04
created

abydos.phonetic._phonetic   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 92
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Phonetic.encode_alpha() 0 11 1
A Phonetic.encode() 0 8 1
A Phonetic._delete_consecutive_repeats() 0 21 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.phonetic._phonetic.
20
21
The phonetic._phonetic module implements abstract class Phonetic.
22
"""
23
24 1
from __future__ import (
25
    absolute_import,
26
    division,
27
    print_function,
28
    unicode_literals,
29
)
30
31 1
from itertools import groupby
32
33
34 1
class Phonetic(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
35
    """Abstract Phonetic class."""
36
37 1
    _uc_set = set('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
38 1
    _lc_set = set('abcdefghijklmnopqrstuvwxyz')
39 1
    _uc_v_set = set('AEIOU')
40 1
    _lc_v_set = set('aeiou')
41 1
    _uc_vy_set = set('AEIOUY')
42 1
    _lc_vy_set = set('aeiouy')
43
44 1
    def _delete_consecutive_repeats(self, word):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
45
        """Delete consecutive repeated characters in a word.
46
47
        Args:
48
            word (str): The word to transform
49
50
        Returns:
51
            str: Word with consecutive repeating characters collapsed to a
52
                single instance
53
54
        Examples:
55
            >>> pe = Phonetic()
56
            >>> pe._delete_consecutive_repeats('REDDEE')
57
            'REDE'
58
            >>> pe._delete_consecutive_repeats('AEIOU')
59
            'AEIOU'
60
            >>> pe._delete_consecutive_repeats('AAACCCTTTGGG')
61
            'ACTG'
62
63
        """
64 1
        return ''.join(char for char, _ in groupby(word))
65
66 1
    def encode(self, word):
67
        """Encode phonetically.
68
69
        Args:
70
            word (str): The word to transform
71
72
        """
73
        pass
74
75 1
    def encode_alpha(self, word):
76
        """Encode phonetically using alphabetic characters.
77
78
        Args:
79
            word (str): The word to transform
80
81
        Returns:
82
            str: The word transformed
83
84
        """
85
        return self.encode(word)
86
87
88
if __name__ == '__main__':
89
    import doctest
90
91
    doctest.testmod()
92