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

abydos.distance._ident.Ident.sim()   A

Complexity

Conditions 2

Size

Total Lines 28
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nop 3
dl 0
loc 28
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
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.distance._ident.
20
21
Identity similarity & distance
22
"""
23
24 1
from __future__ import (
25
    absolute_import,
26
    division,
27
    print_function,
28
    unicode_literals,
29
)
30
31 1
from ._distance import _Distance
32
33 1
__all__ = ['Ident', 'dist_ident', 'sim_ident']
34
35
36 1
class Ident(_Distance):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
37
    """Identity distance and similarity."""
38
39 1
    def sim(self, src, tar):
0 ignored issues
show
Bug introduced by
Parameters differ from overridden 'sim' method
Loading history...
40
        """Return the identity similarity of two strings.
41
42
        Identity similarity is 1.0 if the two strings are identical,
43
        otherwise 0.0
44
45
        Parameters
46
        ----------
47
        src : str
48
            Source string for comparison
49
        tar : str
50
            Target string for comparison
51
52
        Returns
53
        -------
54
        float
55
            Identity similarity
56
57
        Examples
58
        --------
59
        >>> cmp = Ident()
60
        >>> cmp.sim('cat', 'hat')
61
        0.0
62
        >>> cmp.sim('cat', 'cat')
63
        1.0
64
65
        """
66 1
        return 1.0 if src == tar else 0.0
67
68
69 1
def sim_ident(src, tar):
70
    """Return the identity similarity of two strings.
71
72
    This is a wrapper for :py:meth:`Ident.sim`.
73
74
    Parameters
75
    ----------
76
    src : str
77
        Source string for comparison
78
    tar : str
79
        Target string for comparison
80
81
    Returns
82
    -------
83
    float
84
        Identity similarity
85
86
87
    Examples
88
    --------
89
    >>> sim_ident('cat', 'hat')
90
    0.0
91
    >>> sim_ident('cat', 'cat')
92
    1.0
93
94
    """
95 1
    return Ident().sim(src, tar)
96
97
98 1
def dist_ident(src, tar):
99
    """Return the identity distance between two strings.
100
101
    This is a wrapper for :py:meth:`Ident.dist`.
102
103
    Parameters
104
    ----------
105
    src : str
106
        Source string for comparison
107
    tar : str
108
        Target string for comparison
109
110
    Returns
111
    -------
112
    float
113
        Identity distance
114
115
    Examples
116
    --------
117
    >>> dist_ident('cat', 'hat')
118
    1.0
119
    >>> dist_ident('cat', 'cat')
120
    0.0
121
122
    """
123 1
    return Ident().dist(src, tar)
124
125
126
if __name__ == '__main__':
127
    import doctest
128
129
    doctest.testmod()
130