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

abydos.distance._distance   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _Distance.sim() 0 21 1
A _Distance.dist() 0 21 1
A _Distance.dist_abs() 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.distance._distance.
20
21
The distance._distance module implements abstract class _Distance.
22
"""
23
24 1
from __future__ import (
25
    absolute_import,
26
    division,
27
    print_function,
28
    unicode_literals,
29
)
30
31
32 1
class _Distance(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
33
    """Abstract Distance class."""
34
35 1
    def sim(self, src, tar, *args, **kwargs):
36
        """Return similarity.
37
38
        Parameters
39
        ----------
40
        src : str
41
            Source string for comparison
42
        tar : str
43
            Target string for comparison
44
        *args
45
            Variable length argument list.
46
        **kwargs
47
            Arbitrary keyword arguments.
48
49
        Returns
50
        -------
51
        float
52
            Similarity
53
54
        """
55 1
        return 1.0 - self.dist(src, tar, *args, **kwargs)
56
57 1
    def dist(self, src, tar, *args, **kwargs):
58
        """Return distance.
59
60
        Parameters
61
        ----------
62
        src : str
63
            Source string for comparison
64
        tar : str
65
            Target string for comparison
66
        *args
67
            Variable length argument list.
68
        **kwargs
69
            Arbitrary keyword arguments.
70
71
        Returns
72
        -------
73
        float
74
            Distance
75
76
        """
77 1
        return 1.0 - self.sim(src, tar, *args, **kwargs)
78
79 1
    def dist_abs(self, src, tar, *args, **kwargs):
80
        """Return absolute distance.
81
82
        Parameters
83
        ----------
84
        src : str
85
            Source string for comparison
86
        tar : str
87
            Target string for comparison
88
        *args
89
            Variable length argument list.
90
        **kwargs
91
            Arbitrary keyword arguments.
92
93
        Returns
94
        -------
95
        int
96
            Absolute distance
97
98
        """
99 1
        return self.dist(src, tar, *args, **kwargs)
100
101
102
if __name__ == '__main__':
103
    import doctest
104
105
    doctest.testmod()
106