<commit_before>#= 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;
        }
    }
}

<commit_msg>Give t9_find_words a nicer documentation<commit_after>#= 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 words from @words matching $input
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;
        }
    }
}
{'fraction_non_alphanumeric': 0.16765285996055226, 'fraction_numerical': 0.024161735700197237, 'mean_word_length': 3.090725806451613, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1918482', 'n_tokens_mistral': 819, 'n_tokens_neox': 784, 'n_words': 263}