Skip to content

Commit ab2217f

Browse files
committed
cleanup
1 parent 20b9570 commit ab2217f

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

docs/ext/autoclassmembersdiagram.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class MagicTraits(object):
3939
"__getattr__": "attributes",
4040
"__getattribute__": "attributes",
4141
"__len__": "len",
42+
"__hash__": "hashable",
4243
"__subclasshook__": False,
4344
"__repr__": False,
4445
"__str__": False,

src/benchmarkstt/diff/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ def get_error_rate(self):
7070

7171

7272
class Differ(DifferInterface, metaclass=ABCMeta):
73+
"""
74+
Provides pre-made (probably sub-optimal) implementations of
75+
get_opcode_counts() and get_error_rate()
76+
"""
77+
7378
def get_opcode_counts(self):
7479
return get_opcode_counts(self.get_opcodes())
7580

src/benchmarkstt/metrics/core.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from benchmarkstt.schema import Schema, Item
1+
from benchmarkstt.schema import Schema
22
import logging
3-
from benchmarkstt.diff import Differ, factory as differ_factory
4-
from benchmarkstt.diff.core import RatcliffObershelp
3+
from collections import namedtuple
4+
from typing import Union
5+
from benchmarkstt.diff import DifferInterface, factory as differ_factory
6+
from benchmarkstt.diff.core import RatcliffObershelp, Levenshtein
57
from benchmarkstt.diff.formatter import format_diff
68
from benchmarkstt.metrics import Metric
79
from collections import namedtuple
@@ -13,6 +15,7 @@
1315
('equal', 'replace', 'insert', 'delete'))
1416

1517
type_schema = Union[Schema, list]
18+
type_differ = DifferInterface
1619

1720

1821
def traversible(schema, key=None):
@@ -21,7 +24,7 @@ def traversible(schema, key=None):
2124
return [item if type(item) is str else item[key] for item in schema]
2225

2326

24-
def get_differ(a, b, differ_class: Differ):
27+
def get_differ(a, b, differ_class: type_differ):
2528
if differ_class is None or differ_class == '':
2629
differ_class = RatcliffObershelp
2730
elif type(differ_class) is str:
@@ -33,13 +36,13 @@ class WordDiffs(Metric):
3336
"""
3437
Present differences on a per-word basis
3538
36-
:param differ_class: see :py:mod:`benchmarkstt.Differ.core`
39+
:param differ_class: see :py:mod:`benchmarkstt.diff.core`
3740
:param dialect: Presentation format. Default is 'ansi'.
3841
:example differ_class: 'levenshtein'
3942
:example dialect: 'html'
4043
"""
4144

42-
def __init__(self, differ_class: Differ = None, dialect: str = None):
45+
def __init__(self, differ_class: type_differ = None, dialect: str = None):
4346
self._differ_class = differ_class
4447
self._dialect = dialect
4548

@@ -73,7 +76,7 @@ class WER(Metric):
7376
See https://docs.python.org/3/library/difflib.html
7477
7578
:param mode: 'strict' (default), 'hunt' or 'levenshtein'.
76-
:param differ_class: see :py:mod:`benchmarkstt.Differ.core`
79+
:param differ_class: see :py:mod:`benchmarkstt.diff.core`
7780
"""
7881

7982
# WER modes
@@ -84,7 +87,7 @@ class WER(Metric):
8487
INS_PENALTY = 1
8588
SUB_PENALTY = 1
8689

87-
def __init__(self, mode=None, differ_class: Union[str, Differ, None] = None):
90+
def __init__(self, mode=None, differ_class: Union[str, type_differ, None] = None):
8891
self._mode = mode
8992

9093
if differ_class is None:
@@ -136,10 +139,10 @@ class CER(Metric):
136139
will first be split into words, ['aa','bb','cc'], and
137140
then merged into a final string for evaluation: 'aabbcc'.
138141
139-
:param differ_class: see :py:mod:`benchmarkstt.Differ.core`
142+
:param differ_class: see :py:mod:`benchmarkstt.diff.core`
140143
"""
141144

142-
def __init__(self, differ_class: Union[str, Differ, None] = None):
145+
def __init__(self, differ_class: Union[str, type_differ, None] = None):
143146
self._differ_class = Levenshtein if differ_class is None else differ_class
144147

145148
def compare(self, ref: type_schema, hyp: type_schema):
@@ -157,10 +160,10 @@ class DiffCounts(Metric):
157160
"""
158161
Get the amount of differences between reference and hypothesis
159162
160-
:param differ_class: see :py:mod:`benchmarkstt.Differ.core`
163+
:param differ_class: see :py:mod:`benchmarkstt.diff.core`
161164
"""
162165

163-
def __init__(self, differ_class: Union[str, Differ, None] = None):
166+
def __init__(self, differ_class: Union[str, type_differ, None] = None):
164167
self._differ_class = differ_class
165168

166169
def compare(self, ref: type_schema, hyp: type_schema) -> OpcodeCounts:

0 commit comments

Comments
 (0)