kopia lustrzana https://github.com/ag1le/morse-wip
Added levenshtein.py to calculate error metrics
rodzic
3ea8052a4b
commit
c8b8bdd212
|
@ -15,7 +15,7 @@ if {[catch $runcmd res]} {
|
|||
|
||||
set VER [exec src/bmorse -ver]
|
||||
|
||||
set wav_files [glob test/rand*.wav]
|
||||
set wav_files [glob test/cw*.wav]
|
||||
|
||||
# TEST DECODING WITH WPM SPEED 20 ... 80
|
||||
foreach spd {20 30 40 50 60 70 80} {
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from optparse import OptionParser
|
||||
|
||||
parser = OptionParser(usage="%prog [OPTIONS] file1 file2")
|
||||
|
||||
parser.add_option("-v", "--verbose",
|
||||
action="store_true",
|
||||
dest="verbose",
|
||||
default=False,
|
||||
help="Prints details about errors and calls.")
|
||||
|
||||
|
||||
def levenshtein(s1, s2):
|
||||
if len(s1) < len(s2):
|
||||
return levenshtein(s2, s1)
|
||||
|
||||
# len(s1) >= len(s2)
|
||||
if len(s2) == 0:
|
||||
return len(s1)
|
||||
|
||||
previous_row = range(len(s2) + 1)
|
||||
for i, c1 in enumerate(s1):
|
||||
current_row = [i + 1]
|
||||
for j, c2 in enumerate(s2):
|
||||
insertions = previous_row[j + 1] + 1 # j+1 instead of j since previous_row and current_row are one character longer
|
||||
deletions = current_row[j] + 1 # than s2
|
||||
substitutions = previous_row[j] + (c1 != c2)
|
||||
current_row.append(min(insertions, deletions, substitutions))
|
||||
previous_row = current_row
|
||||
|
||||
return previous_row[-1]
|
||||
|
||||
def main(*args, **kwargs):
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
verbosity = 0
|
||||
if options.verbose:
|
||||
verbosity = 1
|
||||
|
||||
|
||||
if len(args) is 0:
|
||||
print 'no input file provided!'
|
||||
exit(1)
|
||||
elif len(args) == 2:
|
||||
fid1 = open(args[0]);
|
||||
fid2 = open(args[1]);
|
||||
|
||||
s1 = file.read(fid1);
|
||||
s2 = file.read(fid2);
|
||||
ltest = levenshtein(s1, s2)
|
||||
print ltest
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -111,7 +111,7 @@ n9 = [Dah;ssp;Dah;ssp;Dah;ssp;Dah;ssp;Dit];
|
|||
n0 = [Dah;ssp;Dah;ssp;Dah;ssp;Dah;ssp;Dah];
|
||||
text = upper(text);
|
||||
vars ={'period','comma','question','slash_'};
|
||||
morsecode=[];
|
||||
morsecode=[ssp;ssp;ssp;ssp;ssp;ssp;ssp];
|
||||
for i=1:length(text)
|
||||
if isvarname(text(i))
|
||||
morsecode = [morsecode;eval(text(i))];
|
||||
|
|
Ładowanie…
Reference in New Issue