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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.