The eccoMAGIC Forums
http://forums.eccoMAGIC.com/forum/YaBB.pl
the SLANG EXTENSION and Guest Programming >> Slang Rules Scripts, Functions, Examples and HOW TO >> Dictionary Lookup ;)
http://forums.eccoMAGIC.com/forum/YaBB.pl?num=1195222863

Message started by Admin on 11/16/07 at 08:21:03

Title: Dictionary Lookup ;)
Post by Admin on 11/16/07 at 08:21:03






In response to a    *very* helpful file posted by Albert,


Quote:
--- In ecco_pro@yahoogroups.com, ecco_pro@yahoogroups.com wrote:
>
>
> Hello,
>
> This email message is a notification to let you know that
> a file has been uploaded to the Files area of the ecco_pro
> group.
>
>   File        : /Examples & Templates for Slang Rule/books.eco
>   Uploaded by : albertschepers <as@...>
>   Description : A File to catalogue documents and auto launch them
>



note:  there is a LOT going on in that file, and the RULE explanations there are super helpful.  THANKS!



Might want to experiment with [untested & might need tweek for syntax],  a different approach for list selection.   Ie.  instead of nested iff's  (which works),  there is a (?) simpler way to same result:


imatch("pdf=Adobe,xls=Spread,wpd=WordPer,", gfv("File Name") + "=(.+?),")


the first string is our choice list.  It can be as long as want,  will work with hundreds of choices.   MAKE SURE TO END IT WITH A ","! *or*, a "blank"  such as "wpd=WordPer,*end*".

the gfv(...) just gets the value you want,  THIS COULD BE AN IMATCH ITSELF... ie. to take what is matched OUT of a larger context.

the + combines it with what follows,

=  looks for an equals sign,

(.+?) matches up to the next ","



[apologize for not having time to test,  this may need correction, etc.,  please test/correct as necessary.   Hopefully the idea is helpful.  ]





Title: Re: Dictionary Lookup ;)
Post by albertschepers on 11/21/07 at 12:26:51

I have tested the proposed alternate but it does not seem to work.  :( Tried variations on the theme but, perhaps my lack of knowledge in regex, I cannot seem to get it to work though I like the concept as it simplifies the programming.  Probably faster as well.

Title: Re: Dictionary Lookup ;)
Post by Admin on 11/21/07 at 17:01:14


albertschepers wrote:
I have tested the proposed alternate but it does not seem to work.



Code:
imatch("pdf=Adobe,xls=Spread,wpd=WordPer,", gfv("File Name") + "=(.+?),")


works just as is...   needs only a Folder called "File Name" that contains either pdf, xls, or wpd as the text.


if you want to make it based on *actual* file names,  just change the "gfv" function to another imatch:


imatch([File Name], "\.\w\w\w\s*$")


or to pull file name extension out of longer text,

imatch([folderName],"\.(wpd|pdf|xls|doc|etc)\b)")  <-- note need to make the \b  a  \B for bug in current extension built.



note for index that is numeric use:


Code:
imatch("pdf=Adobe,xls=Spread,wpd=WordPer,", "" + gfv("File Name") + "=(.+?),")


and to use result as numeric:


Code:
0 + imatch("pdf=1,xls=2,wpd=3,", gfv("File Name") + "=(.+?),")





Title: Re: Dictionary Lookup ;)
Post by albertschepers on 12/28/07 at 10:08:44

Got back to testing ths again and I still have poblems.  I am able now to interpret the expression evaluator so perhaps the error mesage that it gives will be of some use.

First I tried the expression as written:

imatch("pdf=Adobe,xls=Spread,wpd=WordPer,", gfv("File Name") + "=(.+?),")


The error I get is:

attempt to call a global 'gfv' (a nil value) ( this is bogus as I just realized I was using the LUA Script section.  I get no results when I run properly)


I then tried:

imatch([File Name], "\.\w\w\w\s*$")


this worked


so I tried:

imatch(gfv("File Name"), "\.\w\w\w\s*$")


and this worked.


Albert

Title: Re: Dictionary Lookup ;)
Post by albertschepers on 12/28/07 at 13:39:35

Okay, I have tried again and am getting some results, this time I am using the proper pat of the evaluator not like the last message.  I used:

imatch("pdf=Adobe,xls=Spread,wpd=WordPer,*end*", imatch([File Name], "\w\w\w\s*$"))

in the evaluator and in the folder "File Name" I put 'test.pdf' (I did change the last three characters to wpd and xls as well to see what would happen).  The result was

pdf  (only the last three characters, It was not replaced with Adobe or Spread or Wordper either for the other tests)


So I am closer but still no banana as they say.


Albert

Title: Re: Dictionary Lookup ;)
Post by Admin on 12/29/07 at 12:00:56


albertschepers wrote:
Okay, I have tried again and am getting some results, this time I am using the proper pat of the evaluator not like the last message.  I used:

imatch("pdf=Adobe,xls=Spread,wpd=WordPer,*end*", imatch([File Name], "\w\w\w\s*$"))

in the evaluator and in the folder "File Name" I put 'test.pdf' (I did change the last three characters to wpd and xls as well to see what would happen).  The result was

pdf  (only the last three characters, It was not replaced with Adobe or Spread or Wordper either for the other tests)


So I am closer but still no banana as they say.


Albert




try your second imatch() with
Code:
+ "=(.+?),")




in other words,  your right on taking the last 3 characters (also works by "\w{3}\s*$")... but you forgot to add the code to trap the equivelance..   which can also be "=([^,]+)"




hope helps!

Title: Re: Dictionary Lookup ;)
Post by albertschepers on 12/31/07 at 10:24:07

That did the trick, I needed to 'extract' the equivalence side of the relations.  The final rule is

++:FI!+-:imatch("pdf=Adobe,
xls=Spread Sheet,
doc=Word,
htm=HTML,
wpd=WordPerfect,
php=Program,
com=HTML,
ppt=Presentation,",
imatch([File Name], "\w{3}\s*$")+"=(.+?),"):
[Location]="Web" or [Location]="Server"

note that I put each line separate as it reads easier.


One last question; is it possible to put a wild card on the right side so that anything that does not match would have a default name for instance

???=None

where ??? would be any characteres that are not previously matched?

I will post this to the Wiki for reference as it now works!


Albert

Title: Re: Dictionary Lookup ;)
Post by Admin on 01/01/08 at 12:43:27


"(?:" + imatchxxx() + "|*default*")+"=(.+?),"

might do the trick  (need *default*=xxx,  at *END* of your list)


untestested  ;)


hope it makes sense... (if not let me know)

The eccoMAGIC Forums » Powered by YaBB 2.1!
YaBB © 2000-2005. All Rights Reserved.