You said the rules should be additive. If you're applying two rules, say XINDEX == -2, and XSIZE == 2, do you want to select defect 1 once or twice ? If twice, then I you're stuck with N * R work, where N is the number of records and R is the number of rules. If once, then one trick would be to run easy and/or most likely to match rules first.

If the rules weren't additive, I'd suggest looking for ways to quickly exclude defects which definitely would not match any rule -- the idea being that you may be able to quickly hack away at the search space.

So, as others have said, the problem is how to take your rules and render them into something that Perl can execute as quickly as possible. Here I think the basic trick is something along these lines:

use strict ; use warnings ; my @DefectRecordSpec = qw(DEFECTID XREL YREL XINDEX YINDEX XSIZE YSIZE + DEFECTAREA DSIZE CLASSNUMBER TEST CLUSTERNUMBER ROUGHBINNUMBE +R FINEBINNUMBER REVIEWSAMPLE IMAGECOUNT IMAGELIST) ; my @DefectList = ( '1 466.458 4741.229 -2 24 2.000 1.725 3.451440 2.000 0 1 0 0 0 0 0 0 +', '2 5329.992 4264.499 -2 24 1.500 0.862 1.294290 1.500 0 1 0 0 0 0 0 0 +', '3 1469.965 4591.523 -1 24 0.500 0.431 0.215715 0.500 0 1 0 0 0 0 0 0 +', '4 7082.505 4283.913 -1 24 2.000 1.725 3.451440 2.000 0 1 0 0 0 0 0 0 +', '5 777.809 2623.219 -2 24 1.000 0.862 0.862860 1.000 0 1 0 0 0 0 0 0 +', '6 376.807 3904.135 -1 24 1.500 0.862 1.294290 1.500 0 1 0 0 0 0 0 0 +', '7 5345.841 3877.818 0 24 0.500 0.431 0.215715 0.500 0 1 0 0 0 0 0 0 +', ) ; my @rules = ( '$XINDEX == -2', '($XSIZE > 1.75) && ($XSIZE <= 2.15)', ) ; my $fields = '$'. join(', $', @DefectRecordSpec) ; my $rules = join("\n || ", map "($_)", @rules) ; my $sub = join("\n", 'sub {', ' my ($line) = @_ ;', ' $line =~ s/^\s+// ;', # Trim leading spaces, so split is not foo +led # NB: the split will discard trailing spac +es and newline ' my ('. $fields .') = split(/\s+/, $line) ;', ' return '. $rules .' ;', '} ;' ) ; my $test = eval $sub ; print $sub, "\n" ; foreach my $d (@DefectList) { print "$d\n" if $test->($d) ; } ;
where your rules are each small Perl expressions, so can be arbitrarily complicated.


In reply to Re^3: Algorithm To Select Lines Based On Attributes by gone2015
in thread Algorithm To Select Lines Based On Attributes by ~~David~~

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.