I have the following problem, I am splitting words into pairs of letters. and try to match it up with another word.
elaboration:
current word is zezl which should give ze - ez - zl
and the word that should get matched to is zezezl which will give the following gram to get matches: ze-ez-ze-ez-zl
the problem here that my expression gets match the first ze twice and the ez twice as it appears in the word twice per pair. ALTHOUGH what should happen that every pair should get matched only once....
I believe that there are some arguments that can make the expression match every pair only once, I tried the \1 to eat up the matched expression but the problem is that if the word has 2 pairs that are the same like ze-ez-ze it will count {ze} only once..
Here is the code:
I really really appreciate any of you help.. I've ran out of ideas and really need your help
BETTER ELABORATION
I will try to elaborate:
keyword:zezlze -->
ze ez zl lz
ze
dicWord:zezezd -->
ze ez ze ez zd
so the score of this part should be 3 as the ze appears twice and each one is matched with the corresponding and the ez is matched once ONLY as second ez the dictionary word hasn't found another match in the keyword
I hope that I explained well, if not, Please let me know.
UPDATED COMPILING CODE:
use strict;
use warnings;
use re 'eval';
print "Enter word: ";
#chomp(my $word = <STDIN>);
my $word = "zek";
#read the string and trip it into 2 characters NB: /g to repeat operat
+ion at same string
my @pairs = $word =~ /(?=(..))/g;
print(" \"@pairs\" \n");
#qr to make an expression \1 at the end eats matched!
#consider grep perl
#my $matcher = qr/(?=(?s-i)(@{[join "|", @pairs]}))/;
#my $matcher = qr/(?=(@{[join "|", @pairs]}))/;
local $" = q{|};
my $matcher = qr{(?=(@pairs))};
print(" \"$matcher\" \n");
my %coef;
open (my $dict, "dictionary.txt") || die "cant open dictionary.txt\n";
my $dictword = "zezezl";
my $matches = () = $dictword =~ /$matcher/g;
(print"$_")yes-pattern/g;
my $totalz = "$matches $dictword \n";
print $totalz;
my $coef = 2 * $matches / (@pairs + length($dictword)-1);
print ("coeffesion score is $coef");
Thank you guys