1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
# Copyright 2019 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.fingerprint._lacss. |
20
|
|
|
|
21
|
|
|
L.A. County Sheriff's System fingerprint |
22
|
|
|
""" |
23
|
|
|
|
24
|
1 |
|
from __future__ import ( |
25
|
|
|
absolute_import, |
26
|
|
|
division, |
27
|
|
|
print_function, |
28
|
|
|
unicode_literals, |
29
|
|
|
) |
30
|
|
|
|
31
|
1 |
|
from ._fingerprint import _Fingerprint |
32
|
|
|
|
33
|
1 |
|
__all__ = ['LACSS'] |
34
|
|
|
|
35
|
|
|
|
36
|
1 |
|
class LACSS(_Fingerprint): |
37
|
|
|
"""L.A. County Sheriff's System fingerprint. |
38
|
|
|
|
39
|
|
|
Based on the description from :cite:`Taft:1970`. |
40
|
|
|
|
41
|
|
|
.. versionadded:: 0.4.1 |
42
|
|
|
""" |
43
|
|
|
|
44
|
1 |
|
_vowels = set('AEIOUYWH') |
45
|
|
|
|
46
|
1 |
|
_t1 = {_[0]: _[1] for _ in zip('RNLTSCMDKAGBPFVZXJQ', range(1, 20))} |
47
|
1 |
|
_t1.update({_: 0 for _ in _vowels}) |
48
|
|
|
|
49
|
1 |
|
_t2 = {_[0]: _[1] for _ in zip('ABCDEFGHIJKLMNOPQRSTUVWXYZ', range(1, 27))} |
50
|
|
|
|
51
|
1 |
|
def fingerprint(self, word): |
52
|
|
|
"""Return the LACSS coding. |
53
|
|
|
|
54
|
|
|
Parameters |
55
|
|
|
---------- |
56
|
|
|
word : str |
57
|
|
|
The word to fingerprint |
58
|
|
|
|
59
|
|
|
Returns |
60
|
|
|
------- |
61
|
|
|
int |
62
|
|
|
The L.A. County Sheriff's System fingerprint |
63
|
|
|
|
64
|
|
|
Examples |
65
|
|
|
-------- |
66
|
|
|
>>> cf = LACSS() |
67
|
|
|
>>> cf.fingerprint('hat') |
68
|
|
|
'4911211' |
69
|
|
|
>>> cf.fingerprint('niall') |
70
|
|
|
'6488374' |
71
|
|
|
>>> cf.fingerprint('colin') |
72
|
|
|
'3015957' |
73
|
|
|
>>> cf.fingerprint('atcg') |
74
|
|
|
'1772371' |
75
|
|
|
>>> cf.fingerprint('entreatment') |
76
|
|
|
'3882324' |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
.. versionadded:: 0.4.1 |
80
|
|
|
|
81
|
|
|
""" |
82
|
|
|
# uppercase |
83
|
1 |
|
word = word.upper() |
84
|
|
|
|
85
|
|
|
# remove vowels |
86
|
1 |
|
word = word[:1] + ''.join(_ for _ in word[1:] if _ not in 'AEIOUWHY') |
87
|
1 |
|
word += (12 - len(word)) * 'A' |
88
|
|
|
|
89
|
|
|
# step 1 |
90
|
1 |
|
code = self._t2[word[:1]] * 10 |
91
|
|
|
|
92
|
1 |
|
for letter in word[1:12]: |
93
|
1 |
|
code *= 10 |
94
|
1 |
|
code += self._t1[letter] |
95
|
|
|
|
96
|
1 |
|
code *= 3 |
97
|
1 |
|
code = str(int(code ** 0.5)) |
98
|
|
|
|
99
|
1 |
|
return code |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
if __name__ == '__main__': |
103
|
|
|
import doctest |
104
|
|
|
|
105
|
|
|
doctest.testmod() |
106
|
|
|
|