Restrict to when a global variable has a particular value?

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
dfhtextpipe
Posts: 986
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

Restrict to when a global variable has a particular value?

Post by dfhtextpipe »

If one captures a pattern to a global variable, might it be feasible to subsequently use the captured value for a restrict filter?

Example: Suppose I capture this XML attribute early on in the file, then I'd know which "work" I'm dealing with.

Code: Select all

Comment...
|  Capture the value of osisWork
|
+--Restrict to between tags <work>...</work>
   |  [ ] Include text
   |  [X] Match case
   | Max size: 65536
   |
   +--Restrict to each line in turn
      |
      +--Perl pattern [osisWork="(.+)"] with []
         |  [X] Match case
         |  [ ] Whole words only
         |  [ ] Case sensitive replace
         |  [ ] Prompt on replace
         |  [ ] Skip prompt if identical
         |  [ ] First only
         |  [ ] Extract matches
         |  Maximum text buffer size 4096
         |  [X] Maximum match (greedy)
         |  [ ] Allow comments
         |  [ ] '.' matches newline
         |  [X] UTF-8 Support
         |
         +--Perl pattern ["(.+)"] with []
            |  [X] Match case
            |  [ ] Whole words only
            |  [ ] Case sensitive replace
            |  [ ] Prompt on replace
            |  [ ] Skip prompt if identical
            |  [ ] First only
            |  [ ] Extract matches
            |  Maximum text buffer size 4096
            |  [ ] Maximum match (greedy)
            |  [ ] Allow comments
            |  [ ] '.' matches newline
            |  [X] UTF-8 Support
            |
            +--Capture to variable @osisWork
                Reset: 1
                
Could I then have a subsequent subfilter that only takes certain actions depending on the value of the osisWork variable?

i.e. For a filter to be appled to several very similar works, but with some special cases applicable only to certain works.
Assume that all these works have the same set of input filenames.
David
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Restrict to when a global variable has a particular valu

Post by DataMystic Support »

Hi David,

Yes! You can actually use a Scripting filter to control its own subfilters, so you can perform any kind of conditional processing you like.

If you want to engage the subfilters of a Scripting filter for a small piece of text (say < 1 MB), then use:

Code: Select all

TextPipe.subFilterEntireText( inputText : string )
If you need the subfilters of a Scripting filter to process a huge set of data, then use

Code: Select all

initSubFilters()
subFilterChunk( inputString : string )
subFilterChunk( inputString : string )
...
flushSubfilters()
Here is a complete example from the help file:

Code: Select all

dim lineNumber

function processLine(line, EOL)

lineNumber = lineNumber + 1
if (lineNumber = 100) then
   'start the special processing on line 100
   TextPipe.initSubFilters
   TextPipe.subFilterChunk( line & EOL )
   processLine = ""
else if (lineNumber > 100) and (lineNumber < 200) then
   'special processing for lines 100..200
   TextPipe.subFilterChunk( line & EOL )
   processLine = ""
else if (lineNumber = 200) then
   'end special processing on line 200
   TextPipe.flushSubfilters
   processLine = line & EOL
else
   processLine = line & EOL
end if

end function

 
function endFile()
if (lineNumber = 100) then
   endFile = ""
else if (lineNumber > 100) and (lineNumber < 200) then
   TextPipe.flushSubfilters
   endFile = ""
else if (lineNumber = 200) then
   TextPipe.flushSubfilters
   endFile = ""
else
   endFile = ""
end if

end function


function startJob()
  lineNumber = 0
end function
Post Reply