Re: [q-lang-users] Compilation time
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2006-05-19 11:31:37
|
Hi Arnoldo, Arnoldo Muller wrote: > Well, yeah the rules are generated and they are actually term rewriting > rules. > checkAvailability (X,Y) could be written in q as X = Y. > However I don't really want to transform expressions, I want to find > patterns between pairs of expressions and make sure that the pattern I > find is in a database. The file I sent you is the database of "learned" > patterns Ok, I see. So what you actually need is a data structure to represent relations on arbitrary expressions. The easiest way to do this would be to store the pairs as keys in a hashed dictionary. Something like: learn T R = update T R true; available T R = member T R; Here, T is the table of learned rules (emptyhdict initially) and R the rule to be learned or checked. The associated value "true" could actually be anything, so you could also use it to store some more info with each learned rule. If you only need a simple global instance of the table, and you don't mind a little imperativeness, you can also do this with a global reference, as follows: def T = ref emptyhdict; learn R = put T (update (get T) R true); available R = member (get T) R; Then you could just do, e.g.: ==> learn (farrayRef (V0,fphi (fintConstant 1,V1)),farrayRef (V0,fphi (flocalRef BC0,V1))) ==> learn (fstaticInvoque (fmethodRef (AC0,AC1),V0),fphi (flocalRef BC0,V0)) ... That way, you don't have to keep track of the T parameter all the time. Of course, there are other ways to store such relations efficiently, but hdicts are probably the easiest way to go to solve your problem. If the rules don't get arbitrarily large then this implementation should certainly be fast enough. > What I've been doing > is to put all these learned patterns in a database as strings (in a hash > table), and learn a new pattern every time I want to match expressions > and search the hash table. No need to resort to strings there, with hdicts the keys can actually be arbitrary values. See http://q-lang.sf.net/qdoc/qdoc_11.html#SEC67. > Sorry for the huge delay, but japanese works like a charm in 7.0 > : ) Very good news, thanks for the report! And thanks for the nice real-world example of a pattern set which makes deterministic left-to-right matching explode. ;-) Cheers, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |