Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit b07107caa3ee5a6b8d822cbe6078a190a19506a7 0 parents
@tadzik authored
Showing with 50 additions and 0 deletions.
  1. +2 −0  README
  2. +37 −0 lib/Text/T9.pm
  3. +11 −0 t/basic.t
2  README
@@ -0,0 +1,2 @@
+An implementation of T9 word guesser.
+See tests or SYNOPSIS for example usage.
37 lib/Text/T9.pm
@@ -0,0 +1,37 @@
+#= Guess words basing on a T9 key sequence
+module Text::T9;
+
+=begin pod
+=head1 SYNOPSIS
+
+ my @words = <this is a simple kiss test lips here how>;
+ .say for t9_find_words(5477, @words);
+
+ my %additional-keys = ź => 9, ń => 6;
+ @words.push: 'jaźń';
+ t9_find_words(5296, @words, %additional-keys);
+
+=end pod
+
+my %default-keys;
+%default-keys{$_} = 2 for <a b c>;
+%default-keys{$_} = 3 for <d e f>;
+%default-keys{$_} = 4 for <g h i>;
+%default-keys{$_} = 5 for <j k l>;
+%default-keys{$_} = 6 for <m n o>;
+%default-keys{$_} = 7 for <p q r s>;
+%default-keys{$_} = 8 for <t u v>;
+%default-keys{$_} = 9 for <w x y z>;
+
+#= get a list of matching words
+sub t9_find_words(Int $input as Str, @words, %optkeys?) is export {
+ my %keys = %default-keys, %optkeys;
+ gather for @words -> $candidate {
+ next unless $input.chars == $candidate.chars;
+ if $candidate.comb.map({%keys{$_}}).join eq $input {
+ take $candidate;
+ }
+ }
+}
+
+
11 t/basic.t
@@ -0,0 +1,11 @@
+use Text::T9;
+use Test;
+
+my @words = <this is just a simple kiss test lips here how>;
+
+is t9_find_words(5477, @words).join('|'), 'kiss|lips', 'basic case';
+
+is t9_find_words(5296, ['jaźń'], { ź => 9, ń => 6 })[0], 'jaźń',
+ 'with optional keys';
+
+done;
Please sign in to comment.
Something went wrong with that request. Please try again.