We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents f03a3bb + 4e4add4 commit 4d0b04cCopy full SHA for 4d0b04c
4 files changed
VERSION
@@ -1 +1 @@
1
-1.0rc4
+1.0rc5
src/benchmarkstt/metrics/core.py
@@ -28,15 +28,16 @@ def get_opcode_counts(opcodes):
28
elif tag == 'delete':
29
counts[tag] += ahi - alo
30
elif tag == 'replace':
31
- counts[tag] += ahi - alo
32
- if ahi - alo < bhi - blo:
33
- c = bhi - blo - ahi + alo
34
- counts['insert'] += c
35
- counts[tag] -= c
36
- elif ahi - alo > bhi - blo:
37
- c = ahi - alo - bhi + blo
38
- counts['delete'] += c
39
+ ca = ahi - alo
+ cb = bhi - blo
+ if ca < cb:
+ counts['insert'] += cb - ca
+ counts['replace'] += ca
+ elif ca > cb:
+ counts['delete'] += ca - cb
+ counts['replace'] += cb
+ else:
40
+ counts[tag] += ahi - alo
41
return OpcodeCounts(counts['equal'], counts['replace'], counts['insert'], counts['delete'])
42
43
tests/benchmarkstt/test_diff.py
@@ -14,6 +14,15 @@ def test_one_insert(differ):
14
assert list(sm.get_opcodes()) == [('equal', 0, 50, 0, 50),
15
('insert', 50, 50, 50, 51),
16
('equal', 50, 100, 51, 101)]
17
+ ref = "a b c d e f"
18
+ hyp = "a b d e kfmod fgdjn idf giudfg diuf dufg idgiudgd"
19
+ sm = differ(ref, hyp)
20
+ assert list(sm.get_opcodes()) == [('equal', 0, 3, 0, 3),
21
+ ('delete', 3, 5, 3, 3),
22
+ ('equal', 5, 10, 3, 8),
23
+ ('insert', 10, 10, 8, 9),
24
+ ('equal', 10, 11, 9, 10),
25
+ ('insert', 11, 11, 10, 49)]
26
27
@differs_decorator
tests/benchmarkstt/test_metrics_core.py
@@ -15,6 +15,8 @@
['changes 1 word', 'changes one word', (2, 1, 0, 0)],
['0 1 2 3 4', '0 1 22 2 3 4', (5, 0, 1, 0)],
['0 1 2 3 4', '0 1 2 3 4', (5, 0, 0, 0)],
+ ['a b c d e f', 'a b d e kfmod fgdjn idf giudfg diuf dufg idgiudgd', (4, 1, 6, 1)],
+ ['HELLO CRUEL WORLD OF MINE', 'GOODBYE WORLD OF MINE', (3, 1, 0, 1)],
])
def test_diffcounts(a, b, exp):
assert DiffCounts().compare(PlainText(a), PlainText(b)) == OpcodeCounts(*exp)
@@ -27,7 +29,8 @@ def test_diffcounts(a, b, exp):
['aa bb cc dd', 'aa aa bb cc dd dd', (.5, .25)],
['aa bb cc dd', '', (1, 0.5)],
['', 'aa bb cc', (1, 1)],
- ['aa', 'bb aa cc', (2, 1)]
+ ['aa', 'bb aa cc', (2, 1)],
+ ['a b c d e f', 'a b d e kfmod fgdjn idf giudfg diuf dufg idgiudgd', (8/6, 3/4)],
def test_wer(a, b, exp):
wer_strict, wer_hunt = exp
0 commit comments