Changeset 3429


Ignore:
Timestamp:
Aug 13, 2013, 12:52:16 AM (5 years ago)
Author:
ksherdy
Message:

Added an option to invert the matches.

Location:
proto/RE/demo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/RE/demo/grep_demo.py

    r3428 r3429  
    11#
    2 # grep -        A very simple example to demonstrate grep with parallel bit streams.
     2# grep -        A very simple example to demonstrate grep with parall_matchedel bit streams.
    33#
    44#                                       This prototypes demonstrates a compilable prototype with
     
    2626# Observations:
    2727#
    28 # 1) Both sequential and bit parallel computations are performed.
     28# 1) Both sequential and bit parall_matchedel computations are performed.
    2929#   
    3030#    Examples include:
    3131#       
    3232#          a) sequential iteration over the matches and line feed streams in the 'Match' routine
    33 #          b) sequential and/or parallel output of marked lines in the 'CompressLines' / 'WriteLines' routine   
     33#          b) sequential and/or parall_matchedel output of marked lines in the 'CompressLines' / 'WriteLines' routine   
    3434#
    3535# 2) Creation of spans are problematic at the start of an input data stream.
     
    4141#    2^k with zero value items.
    4242#
    43 #    i.e. leverage denotational semenatics to define what parallel bit stream programs do.
     43#    i.e. leverage denotational semenatics to define what parall_matchedel bit stream programs do.
    4444#
    4545#    b) define the 'line starts' stream as line_starts = ~Adv~(0) | Advance(lines_end_marks)
     
    5151# 4) Support of pipes and filter type applications requires subgraph composition but only a single transposition step.
    5252#    As in SPL a composite program structure could support UNIX-style pipe and filters archicture for
    53 #    parallel bit stream apps, e.g. composite { graph { /* program flow */ } }
     53#    parall_matchedel bit stream apps, e.g. composite { graph { /* program flow */ } }
    5454#
    5555import sys
     
    7676       
    7777class Matches():
    78         all_matches = 0
     78        all_matched = 0
    7979
    8080class Lines():
    81         all_lines = 0
     81        all_matched = 0
    8282
    8383class Output():
     
    117117        m3 = pablo.Advance(m2) & lex.l
    118118        m4 = pablo.Advance(m3) & lex.e
    119         matches.all_matches = m4
     119        matches.all_matched = m4
    120120
    121121# not compilable - requires pablo.First()
     
    124124
    125125        last_start = pablo.First()
    126         LF_or_match = lex.LF | matches.all_matches
     126        LF_or_match = lex.LF | matches.all_matched
    127127        cursor = pablo.ScanToFirst(LF_or_match)
    128128
    129129        while(pablo.inFile(cursor)):
    130                 if(cursor & matches.all_matches):
     130                if(cursor & matches.all_matched):
    131131                        next_end = pablo.AdvanceThenScanTo(cursor, lex.LF)
    132                         lines.all_lines |= pablo.InclusiveSpan(last_start, next_end) | next_end
     132                        lines.all_matched |= pablo.InclusiveSpan(last_start, next_end) | next_end
    133133                        cursor = next_end
    134134                if(cursor & lex.LF):
     
    142142        last_start = 0
    143143        last_start = pablo.Advance(~last_start) ^ ~last_start
    144         LF_or_match = lex.LF | matches.all_matches
     144        LF_or_match = lex.LF | matches.all_matched
    145145        cursor = pablo.ScanToFirst(LF_or_match)
    146146
    147147        while(pablo.inFile(cursor)):
    148                 if(cursor & matches.all_matches):
     148                if(cursor & matches.all_matched):
    149149                        next_end = pablo.AdvanceThenScanTo(cursor, lex.LF)
    150                         lines.all_lines |= pablo.InclusiveSpan(last_start, next_end) | next_end
     150                        lines.all_matched |= pablo.InclusiveSpan(last_start, next_end) | next_end
    151151                        cursor = next_end
    152152                if(cursor & lex.LF):
     
    155155                               
    156156def FilterMatchLines(data, output):
    157         output.lines = pablo.filter_bytes(data, ~lines.all_lines)
    158        
     157        output.lines = pablo.filter_bytes(data, ~lines.all_matched)
     158
     159def CountLines(lex, lines):
     160        return pablo.PopCount(pablo.MatchStar(lines, ~lex.LF) & lex.LF)
     161
    159162basis_bits      = Basis()
    160163lex           = Lex()
     
    190193
    191194  # WriteStreamOutput(Output)
     195 
     196        if(options.invertMatch):
     197          lines.all_matched =~ lines.all_matched
     198
    192199        if(options.count):
    193                 print str(pablo.PopCount(pablo.MatchStar(matches.all_matches, ~lex.LF) & lex.LF))
     200          print str(CountLines(lex, lines.all_matched))
    194201        else:
    195202          lgth = len(data)
     
    202209          print "lex.e                    " + pablo.bitstream2string(lex.e, lgth)
    203210          print "lex.LF                   " + pablo.bitstream2string(lex.LF, lgth)
    204           print "matches.all_matches      " + pablo.bitstream2string(matches.all_matches, lgth)
    205           print "lines.all_lines          " + pablo.bitstream2string(lines.all_lines, lgth)
     211          print "matches.all_matched      " + pablo.bitstream2string(matches.all_matched, lgth)
     212          print "lines.all_matched        " + pablo.bitstream2string(lines.all_matched, lgth)
    206213          print "---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------"
    207214          print "Raw Output:" + output.lines
  • proto/RE/demo/grep_demo_config.py

    r3422 r3429  
    99       
    1010        # Option definitions
     11        parser.add_option('-v', '--invert-match',
     12                          dest='invertMatch',
     13                          action='store_true',
     14                          default=False,
     15                          help='Invert match.',
     16                          )
     17
    1118        parser.add_option('-c', '--count',
    1219                          dest='count',
Note: See TracChangeset for help on using the changeset viewer.