in reply to Re: fill diacritic into text
in thread fill diacritic into text
im sure there are many beginners mistakes but it works :) now i would need to compare "output" with "correct". "correct" is a file with diacritic and i need to know how many words were replaced good. is there some way to do this in perl? thank you$times = time; $filei = "cetnosti"; $filer = "input"; $filew = "output"; $filec = "correct"; open( INFO, $filei ) or die "cetnosti: $!"; $lineno = 1; while ((defined ($_ = <INFO>)) && ($lineno < 500000)) { ( $word, $freq ) = split; $ascii_word = $word; $ascii_word =~ tr/ľščťžýáíéäúňô& +#283;řŕĺůó*ȍŽÝÁÍ +ÉÄÚŇÔĚŘŔĹŮÓĎ/lsctzyaieaunoerrluodL +SCTZYAIEAUNOERRLUOD/; $lineno++; if ( exists( $respell{$ascii_word} )) { next; } $respell{$ascii_word} = $word; } close INFO; open( INPUT, $filer ) or die "input: $!"; open( OUTPUT, "> $filew" ) or die "respelled: $!"; while (<INPUT>) { $outstr = ''; for $tkn ( split /([\s\p{P}]+)/ ) { if ( exists( $respell{$tkn} )) { $tkn = $respell{$tkn}; } $outstr .= $tkn; } print OUTPUT $outstr; } close INPUT; close OUTPUT; $timee = time; $timer = $timee - $times; print "execution time: $timer seconds\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: fill diacritic into text
by graff (Chancellor) on May 31, 2007 at 12:56 UTC |