Skip to content

Commit

Permalink
removed _to_alpha functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislit committed Jan 12, 2020
1 parent f8bc9f1 commit 3ce8dc2
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 98 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Abydos
:target: #
:alt: pydocstyle Errors

.. |sloccount| image:: https://img.shields.io/badge/SLOCCount-38,326-blue.svg
.. |sloccount| image:: https://img.shields.io/badge/SLOCCount-38,320-blue.svg
:target: #
:alt: SLOCCount

Expand Down
35 changes: 2 additions & 33 deletions abydos/phonetic/_koelner.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,38 +191,6 @@ def _before(word, pos, letters):

return sdx

def _to_alpha(self, num):
"""Convert a Kölner Phonetik code from numeric to alphabetic.
Parameters
----------
num : str or int
A numeric Kölner Phonetik representation
Returns
-------
str
An alphabetic representation of the same word
Examples
--------
>>> pe = Koelner()
>>> pe._to_alpha('862')
'SNT'
>>> pe._to_alpha('657')
'NLR'
>>> pe._to_alpha('86766')
'SNRNN'
.. versionadded:: 0.1.0
.. versionchanged:: 0.3.6
Encapsulated in class
"""
num = ''.join(c for c in num if c in self._num_set)
return num.translate(self._num_trans)

def encode_alpha(self, word):
"""Return the Kölner Phonetik (alphabetic output) code for a word.
Expand Down Expand Up @@ -254,7 +222,8 @@ def encode_alpha(self, word):
Encapsulated in class
"""
return self._to_alpha(self.encode(word))
num = ''.join(c for c in self.encode(word) if c in self._num_set)
return num.translate(self._num_trans)


if __name__ == '__main__':
Expand Down
42 changes: 3 additions & 39 deletions abydos/phonetic/_russell_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,43 +98,6 @@ def encode(self, word):
# return as an int
return int(sdx) if sdx else float('NaN')

def _to_alpha(self, num):
"""Convert the Russell Index integer to an alphabetic string.
This follows Robert C. Russell's Index algorithm, as described in
:cite:`Russell:1917`.
Parameters
----------
num : int
A Russell Index integer value
Returns
-------
str
The Russell Index as an alphabetic string
Examples
--------
>>> pe = RussellIndex()
>>> pe._to_alpha(3813428)
'CRACDBR'
>>> pe._to_alpha(715)
'NAL'
>>> pe._to_alpha(3614)
'CMAD'
.. versionadded:: 0.1.0
.. versionchanged:: 0.3.6
Encapsulated in class
"""
num = ''.join(c for c in str(num) if c in self._num_set)
if num:
return num.translate(self._num_trans)
return ''

def encode_alpha(self, word):
"""Return the Russell Index (alphabetic output) for the word.
Expand Down Expand Up @@ -169,8 +132,9 @@ def encode_alpha(self, word):
Encapsulated in class
"""
if word:
return self._to_alpha(self.encode(word))
num = ''.join(c for c in str(self.encode(word)) if c in self._num_set)
if num:
return num.translate(self._num_trans)
return ''


Expand Down
6 changes: 0 additions & 6 deletions tests/fuzz/fuzz_test_phonetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@
'henry_early': HenryEarly().encode,
'henry_early_ml8': HenryEarly(max_length=8).encode,
'koelner_phonetik': koelner.encode,
'koelner_phonetik_num_to_alpha': (
lambda _: koelner._to_alpha(koelner.encode(_)) # noqa: SF01
),
'koelner_phonetik_alpha': koelner.encode_alpha,
'lein': LEIN().encode,
'lein_nopad_ml8': LEIN(max_length=8, zero_pad=False).encode,
Expand Down Expand Up @@ -160,9 +157,6 @@
'roger_root': RogerRoot().encode,
'roger_root_nopad_ml8': RogerRoot(max_length=8, zero_pad=False).encode,
'russell_index': russell.encode,
'russell_index_num_to_alpha': (
lambda _: russell._to_alpha(russell.encode(_)) # noqa: SF01
),
'russell_index_alpha': russell.encode_alpha,
'sfinxbis': lambda _: ', '.join(sfinxbis.encode(_)),
'sfinxbis_ml6': lambda _: ', '.join(sfinxbis_6.encode(_)),
Expand Down
6 changes: 0 additions & 6 deletions tests/phonetic/test_phonetic_koelner.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ def test_koelner_phonetik(self):
self.assertEqual(self.pa.encode('Acre'), '087')
self.assertEqual(self.pa.encode('H'), '')

def test_koelner_phonetik_n2a(self):
"""Test abydos.phonetic.Koelner._to_alpha."""
self.assertEqual(
self.pa._to_alpha('0123456789'), 'APTFKLNRS' # noqa: SF01
)

def test_koelner_phonetik_alpha(self):
"""Test abydos.phonetic.Koelner.encode_alpha."""
self.assertEqual(
Expand Down
12 changes: 0 additions & 12 deletions tests/phonetic/test_phonetic_russell_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ def test_russel_index(self):
self.assertEqual(self.pa.encode('Mack'), 613)
self.assertEqual(self.pa.encode('Knack'), 3713)

def test_russel_index_n2a(self):
"""Test abydos.phonetic.RussellIndex._to_alpha."""
self.assertEqual(self.pa._to_alpha(0), '') # noqa: SF01
self.assertEqual(self.pa._to_alpha(''), '') # noqa: SF01
self.assertEqual(self.pa._to_alpha(float('NaN')), '') # noqa: SF01
self.assertEqual(
self.pa._to_alpha(123456789), 'ABCDLMNR' # noqa: SF01
)
self.assertEqual(
self.pa._to_alpha('0123456789'), 'ABCDLMNR' # noqa: SF01
)

def test_russel_index_alpha(self):
"""Test abydos.phonetic.RussellIndex.encode_alpha."""
self.assertEqual(self.pa.encode_alpha(''), '')
Expand Down

0 comments on commit 3ce8dc2

Please sign in to comment.