| 1 | package Lingua::DE::TypoGenerator; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use constant LDT_VCHARSETS => ( 'ISO-8859-1' ); #, 'ISO-8859-15', 'UTF-8' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use constant LDT_DEFCHARSET => 'ISO-8859-1'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use constant LDT_KEYBOARDLAY => ( '1234567890', 'qwertzuiopü', 'asdfghjklöä', 'yxcvbnm' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | require 5.8.0; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | $VERSION = '0.2'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | @EXPORT = qw(typos); | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 22 | 0 | my %opt = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | my $self = { | ||||||||||||||||||||||||||||
| 25 | 0 | charset => $opt{'charset'}, | |||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Check charset | ||||||||||||||||||||||||||||
| 29 | 0 | my $v_charset = 0; | |||||||||||||||||||||||||||
| 30 | 0 | foreach my $ccharset (LDT_VCHARSETS) { | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($self->{'charset'} and $self->{'charset'} eq $ccharset) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"charset"} and $self->{"charset"} eq $ccharset
MC/DC0%0/2
$self->{"charset"} and $self->{"charset"} eq $ccharset
$self->{"charset"}
$self->{"charset"} eq $ccharset
Truth table0%0/3
A and B
A= $self->{"charset"}B= $self->{"charset"} eq $ccharset
| |||||||||||||||||||||||||||||
| 32 | 0 | $v_charset = 1; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if (!$v_charset) { $self->{'charset'} = LDT_DEFCHARSET; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Bless and return | ||||||||||||||||||||||||||||
| 38 | 0 | return bless $self, $class; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub typos { | ||||||||||||||||||||||||||
|
Subroutine
typos: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 0 | my $self; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $self = shift; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 0 | my $word = shift; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # Self init if required | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if (!$self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | $self = new('Lingua::DE::TypoGenerator'); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my @typos = (); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # Forget characters | ||||||||||||||||||||||||||||
| 56 | 0 | @typos = (@typos, $self->_typo_forgetchar($word)); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # Double characters | ||||||||||||||||||||||||||||
| 59 | 0 | @typos = (@typos, $self->_typo_doublechar($word)); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # Twist characters | ||||||||||||||||||||||||||||
| 62 | 0 | @typos = (@typos, $self->_typo_twistchars($word)); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # Miss keys | ||||||||||||||||||||||||||||
| 65 | 0 | @typos = (@typos, $self->_typo_misskeys($word)); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Sort unique | ||||||||||||||||||||||||||||
| 68 | 0 | @typos = $self->_unique_array(@typos); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | return @typos; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub _typo_forgetchar { | ||||||||||||||||||||||||||
|
Subroutine
_typo_forgetchar: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | 0 | my $word = shift; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my @typos = (); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | for (my $i = 0; $i < length($word); $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | push @typos, substr($word, 0, $i).substr($word, $i + 1); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | return @typos; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub _typo_doublechar { | ||||||||||||||||||||||||||
|
Subroutine
_typo_doublechar: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 88 | 0 | my $word = shift; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | my @typos = (); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | for (my $i = 0; $i < length($word); $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | push @typos, substr($word, 0, $i).substr($word, $i, 1).substr($word, $i); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | return @typos; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub _typo_twistchars { | ||||||||||||||||||||||||||
|
Subroutine
_typo_twistchars: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 100 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 101 | 0 | my $word = shift; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my @typos = (); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | for (my $i = 0; $i < length($word) - 1; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | my @c = split //, $word; | |||||||||||||||||||||||||||
| 107 | 0 | my $b = $c[$i]; | |||||||||||||||||||||||||||
| 108 | 0 | $c[$i] = $c[$i + 1]; | |||||||||||||||||||||||||||
| 109 | 0 | $c[$i + 1] = $b; | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | push @typos, join('', @c) unless $#c < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | return @typos; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub _typo_misskeys { | ||||||||||||||||||||||||||
|
Subroutine
_typo_misskeys: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 117 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 118 | 0 | my $word = shift; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | my @typos = (); | |||||||||||||||||||||||||||
| 121 | 0 | my @kblay = LDT_KEYBOARDLAY; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | for (my $i = 0; $i < length($word); $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | my $c = substr($word, $i, 1); | |||||||||||||||||||||||||||
| 125 | 0 | my $kl = -1; | |||||||||||||||||||||||||||
| 126 | 0 | my $ki = -1; | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | KBLAYIT: for (my $j = 0; $j < scalar(@kblay); $j++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | $ki = index($kblay[$j], $c); | |||||||||||||||||||||||||||
| 129 | 0 | ▶ | if ($ki > -1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | $kl = $j; | |||||||||||||||||||||||||||
| 131 | 0 | last KBLAYIT; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | last if $kl == -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | last if $ki == -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | for (my $line = $kl - 1; $line <= $kl + 1; $line++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | next if $line < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | next if $line > $#kblay; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | for (my $col = $ki - 1; $col <= $ki + 1; $col+=2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | next if $col < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | next if $ki > length($kblay[$line]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | push @typos, substr($word, 0, $i).substr($kblay[$line], $ki, 1).substr($word, $i + 1); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | return @typos; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub _unique_array { | ||||||||||||||||||||||||||
|
Subroutine
_unique_array: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | 0 | my @in = @_; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | my %uq = (); | |||||||||||||||||||||||||||
| 157 | 0 | foreach my $e (@in) { | |||||||||||||||||||||||||||
| 158 | 0 | $uq{$e} = 1; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | return sort keys %uq; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | # Satisfy require | ||||||||||||||||||||||||||||
| 165 | 1 | 1; | |||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||