Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^15: partial match between 2 files

by Athanasius (Chancellor)
on Jan 10, 2013 at 16:30 UTC ( #1012697=note: print w/replies, xml ) Need Help??

in reply to Re^14: partial match between 2 files
in thread partial match between 2 files

Hello lakssreedhar,

As I understand it, you’re writing a script which accepts as input a word (which I will call the target) and the name of a dictionary file. The purpose of the script is to identify the best match for the target (if any) among the entries in the dictionary. Well, there would seem to be four possible ways in which a dictionary entry can match the target word:

  1. They are identical
  2. The target is a substring of the dictionary entry
  3. The dictionary entry is a substring of the target
  4. They share a common substring.

I suppose it’s obvious that if (1) is satisfied, this is the best match. And from earlier posts in this thread, it appears that if none of (1), (2), or (3) is true, then (4) looks for the the longest common substring (i.e., the “best” match is the one with the longest substring in common). But now things get murky. What if both (2) and (3) are satisfied? For example, the target is reread and the dictionary contains both read and rereading? And this is only one example of the sort of edge cases that need to be considered.

suppose my dictionary has words crick, cricketer and testing input is cricking,the match should be to crick

OK, but why? What are the rules for a “best match”? These rules need to be specified very precisely (and of course only you can do this, since only you know what your script is intended to do).

Here is how I would approach the problem:

  • Think through the above considerations, and come up with a precise set of rules describing exactly what is the “best match” in all possible cases.
  • Illustrate each of these rules with sample input (target word and dictionary contents) together with the desired output.
  • Use this sample input to create a simple test harness that will test your script. (For example, see Test::Tutorial and What are some good testing references?.)
  • Design an algorithm to apply the rules for matching, drawing on the advice and techniques given in other posts in this thread.
  • Implement the algorithm and test it by running the test harness.

Hope that gives you some help,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^16: partial match between 2 files
by lakssreedhar (Acolyte) on Jan 12, 2013 at 04:46 UTC

    ok let me try it out this ways.Thanks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012697]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2018-06-20 04:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.