I tried Linda's function:

  textfile3
Start of event 1 crlftb
Some text crlftb
Some more text crlftb
param1    =  12345 crlftb
param2    =   NONE crlftb
some comments crlftb
param3   =   hello world crlftb
more comments crlftb
param4  =  120.45 crlftb
param6 = Test y crlftb
End of stuff crlftb
Start of event 2 crlftb
Some text crlftb
Some different text crlftb
param1  = 34567 crlftb
param3  = hello bob crlftb
param4  = 32.89 crlftb
comments and more comments crlftb
param5   - zero one crlftb
param 6  = Test z crlftb
Second end crlftb
Start of event 3 crlftb
param5 = two three crlftb
Start of event 4 crlftb
stuff crlftb
param1 = 6789 crlftb
param2 = SOME crlftb
end crlftb

   tags1
┌──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┐
│param1│crlftb│param2│crlftb│param3│crlftb│param5│crlftb│
└──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┘
  txt6 =:   textfile3 getTagsContents tags1
|stack error: locs
|   data=._2{:\(    (/:~;locs)I.i.#txt)</.txt

So something is wrong.

The correct answer is:

 NB.  param1          param2           param3            param5
+---------------------------------------------------------------+
¦    =  12345  ¦    =   NONE ¦   =   hello world ¦              ¦
+--------------+-------------+-------------------+--------------¦
¦  = 34567     ¦             ¦   = hello bob     ¦ - zero one   ¦
+--------------+-------------+-------------------+--------------¦
¦              ¦             ¦                   ¦ = two three  ¦
+--------------+-------------+-------------------+--------------¦
¦ = 6789       ¦ = SOME      ¦                   ¦              ¦
+---------------------------------------------------------------+

Skip

On Sat, Nov 19, 2011 at 9:50 AM, Linda Alvord <[email protected]>wrote:

> getTagsContents=: 4 :0
> 'n m'=. $tags=. > _2 <\ y
> locs=.  tags [email protected]:0 }.
> txt=.(' ',;tags),x,;tags
> locs=. (-@#@[ {. I. {./. ])&.>/\"1 locs
> NB. assert. -:&/:&;/ |:locs  NB. tags must be balanced
> data=. _2 {:\  ((/:~ ; locs) I. i.#txt) </.  txt
> expand=. ;(#~ 1&e.S:0) <@|./. |.> (e.L:0~ /:~@;) {."1 locs
> )
>
> To get the function to run at all, I chopped it up and tags should have an
> argument as it is defined as a dyadic function.  I haven't tried to
> understand the problem yet.  However could you check the code again. Maybe
> I put line breaks in the wrong places.
>
> Linda
>
> -----Original Message-----
> From: [email protected] [mailto:
> [email protected]] On Behalf Of Skip Cave
> Sent: Saturday, November 19, 2011 1:16 AM
> To: Programming forum
> Subject: Re: [Jprogramming] Finding multiple sequential strings
>
> OK, here;s Raul's function:
>
> getTagsContents=: 4 :0
>  'n m'=. $tags=. > _2 <\ y
>  locs=.  tags [email protected]:0 }. txt=.(' ',;tags),x,;tags
>  locs=. (-@#@[ {. I. {./. ])&.>/\"1 locs
>  NB. assert. -:&/:&;/ |:locs  NB. tags must be balanced
>  data=. _2 {:\  ((/:~ ; locs) I. i.#txt) </.  txt
>  expand=. ;(#~ 1&e.S:0) <@|./. |.> (e.L:0~ /:~@;) {."1 locs
>
> Here's my data:
>
>  textfile3=: 0 : 0
> Start of event 1 crlftb
> Some text crlftb
> Some more text crlftb
> param1    =  12345 crlftb
> param2    =   NONE crlftb
> some comments crlftb
> param3   =   hello world crlftb
> more comments crlftb
> param4  =  120.45 crlftb
> param6 = Test y crlftb
> End of stuff crlftb
> Start of event 2 crlftb
> Some text crlftb
> Some different text crlftb
> param1  = 34567 crlftb
> param3  = hello bob crlftb
> param4  = 32.89 crlftb
> comments and more comments crlftb
> param5   - zero one crlftb
> param 6  = Test z crlftb
> Second end crlftb
> Start of event 3 crlftb
> param5 = two three crlftb
> Start of event 4 crlftb
> stuff crlftb
> param1 = 6789 crlftb
> param2 = SOME crlftb
> end crlftb
> )
>
>   $ textfile3
> 642
>
> I put the crlftb text on the end of each line, to show the equivalent of
> the invisible characters that are actually in the real data.
>
> Here is the string of tag pairs:
>
> tags1 =: ('param1'; 'crlftb' ; 'param2'; 'crlftb' ; 'param3' ; 'crlftb' ;
> 'param5' ; 'crlftb' )
>   tags1
> ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┐
> │param1│crlftb│param2│crlftb│param3│crlftb│param5│crlftb│
> └──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┘
>
>  so now we try Raul's function:
>
>  txt5 =:  tags1 getTagsContents   textfile3
> |domain error: getTagsContents
> |   locs=.tags [email protected]:0}.txt=.(' ',;tags),x    ,;tags
>
> Nope. What we should get is:
>
> ┌─────┬────┬───────────┬─────────┐
> │12345│NONE│hello world│         │
> ├─────┼────┼───────────┼─────────┤
> │34567│    │hello bob  │zero one │
> ├─────┼────┼───────────┼─────────┤
> │     │    │           │two three│
> ├─────┼────┼───────────┼─────────┤
> │6789 │SOME│           │         │
> └─────┴────┴───────────┴─────────┘
>
>  I should get a 4 x 4 boxed array with 12345, NONE, hello world, and an
> empty box in the first row of boxes
> The second row will have boxes containing 34567, empty box, hello bob, zero
> one
> The third row will have three empty boxes, and the fourth box will have
> 'two three' in it
> The fourth row will have a box with 6789, a box with SOME, and two empty
> boxes.
>
> Skip
>
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to