Author Topic: Wildcard matching without wildcards  (Read 8202 times)

0 Members and 1 Guest are viewing this topic.

SMadsen

  • Guest
Wildcard matching without wildcards
« on: June 18, 2004, 09:51:37 AM »
I'm trying to update my SYSVARDLG.LSP (just updated all sysvars to at least R2004 and soon for R2005) and want to provide a search technique like in ET's SYSVDLG where it can list all sysvars beginning with some letter. For example, "C*" will list all system variables that start with "C".

But, I want to provide wildcard matching without the user having to type wildcards explicitly. The catch is that padding a search string with wildcards automatically does not give an option of finding words by beginning. So I thought that if the user starts a search word in capital then a wildcard won't be added to the left. If search word is started in lowercase then it means the search critera could be anywhere within the word. If the search word is ended in uppercase then it means "match words ending with this criteria" - i.e. no wildcard to the right.

Of course, if the user types wildcards, they will be respected.

Does the search scheme sound confusing?? Any comments welcome.

Here's the search routine:

Code: [Select]
(defun svsearch (alist astr / hitlist flag)
  (and (= (strlen astr) 1)(/= astr "*")(setq astr (strcat astr "*")))
  (and (not (= (substr astr 1 1)(strcase (substr astr 1 1))))
       (setq astr (strcat "*" astr)))
  (and (not (= (substr astr (strlen astr) 1)(strcase (substr astr (strlen astr) 1))))
       (setq astr (strcat astr "*")))
  (foreach n alist
    (mapcar '(lambda (x)
               (if (= (type x) 'STR)
                 (cond ((or (wcmatch x astr)
                            (wcmatch x (strcase astr nil))
                            (wcmatch x (strcase astr T))
                        )
                        (if (not (member (car n) hitlist))
                          (setq hitlist (cons (car n) hitlist))
                        )
                       )
                       (T nil)
                 )
               )
             )
            n
    )
  )
  hitlist
)


And some results (the routine returns CAR element of a sublist if a match is made on any member(s) in the sublist):

(setq alist '(("XYZ" "zxy")("abc" "BCD")("no way" "yes way")))
(("XYZ" "zxy") ("abc" "BCD") ("no way" "yes way"))

(svsearch alist "Y")
("no way")
-> "Y" becomes "Y*" and "y*" and only matches "yes way"

(svsearch alist "y")
("no way" "XYZ")
-> "Y" becomes "*y*" and "*Y*" and matches "XYZ", "xyz", "no way" and "yes way"

(svsearch alist "c")
("abc")
-> "c" becomes "*c*" and "*C*" and matches both "abc" and "BCD"

(svsearch alist "C")
nil
-> "C" becomes "C*" and "c*" and matches nothing because nothing begins with "c"

(svsearch alist "*C*")
("abc")
-> wildcards are respected and matches the same as just "c" (above)

(svsearch alist "*C")
("abc")
-> wildcard is respected, no wildcard is added to the right because C is uppercase
-> matches only "abc" which ends with "c"

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Wildcard matching without wildcards
« Reply #1 on: June 18, 2004, 10:06:00 AM »
>Does the search scheme sound confusing?? Any comments welcome.
No not at all. I'm just wondering about the *'s do you really need them..... let  me test it some before I say anymore. :D
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Wildcard matching without wildcards
« Reply #2 on: June 18, 2004, 10:43:50 AM »
Thanks, Mark.

Quote from: Mark Thomas
I'm just wondering about the *'s do you really need them...

You mean in the tests in the start of the routine? It could perhaps be condensed but I think all conditions need to be present (I actually forgot one that checks for standalone wildcards other than "*")

It runs through some 4-5,000 items in the MAPCAR each time one search is made so it's not the conditions that will slow it down but the WCMATCH'es.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Wildcard matching without wildcards
« Reply #3 on: June 18, 2004, 11:02:02 AM »
>You mean in the tests in the start of the routine?
No I meant from a users perspective. But after using the function I think I now see what you are after. Pretty cool stuff indeed. The upper/lower case idea is a good one too.
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Wildcard matching without wildcards
« Reply #4 on: June 18, 2004, 11:28:20 AM »
Looks like a good idea to me.
I'm wondering if the User enters an astrix that the Uppercase feature
should override any lower case?  *y -> *Y

Code: [Select]
(defun c:test ()
  (setq alist '(("ONE" "zxy") ("TWO" "zyx") ("THREE" "yzx")))
  (print (svsearch alist "*Y*"))
  (print (svsearch alist "*y*"))
  (print (svsearch alist "y"))
  (print (svsearch alist "Y"))
  (print (svsearch alist "Y*"))
  (print (svsearch alist "*Y"))
  (print (svsearch alist "*y"))
  (print (svsearch alist "y*"))
  (princ)
)

("THREE" "TWO" "ONE")
("THREE" "TWO" "ONE")
("THREE" "TWO" "ONE")
("THREE")
("THREE")
("ONE")
("THREE" "TWO" "ONE")
("THREE" "TWO" "ONE")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
Wildcard matching without wildcards
« Reply #5 on: June 18, 2004, 11:49:48 AM »
Let me wrap my head arround this concept for a second. Ive ran the code, I havent looked at it yet cause im sure its fine, but i wanted to maybe toss out a few ideas i get.

I just wanted to let cha know that Im thinking about this.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
Wildcard matching without wildcards
« Reply #6 on: June 18, 2004, 11:57:56 AM »
Thanks Mark. Although CAB brings up a good question.

CAB, I see what you mean. Tough choice. Gotta chew on it for a while. Thanks.

SMadsen

  • Guest
Wildcard matching without wildcards
« Reply #7 on: June 18, 2004, 12:13:58 PM »
CAB, so in your list above, "*y" would mean that the user expects to find all words ending in "y", right? It should override the wildcard padding?

(svsearch alist "*y") -> ("ONE")

(svsearch alist "y*") -> ("THREE")

(svsearch alist "Y") -> ("THREE")

(svsearch alist "y") -> ("THREE" "TWO" "ONE")

(svsearch alist "yX") -> ("TWO")

Hmm, you may be right.

Code: [Select]
(defun svsearch (alist astr / hitlist flag)
  (cond ((not (wcmatch astr "*`**"))
         (and (= (strlen astr) 1)(/= astr "*")(setq astr (strcat astr "*")))
         (and (not (= (substr astr 1 1) (strcase (substr astr 1 1))))
              (setq astr (strcat "*" astr))
         )
         (and (not (= (substr astr (strlen astr) 1)
                      (strcase (substr astr (strlen astr) 1))))
              (setq astr (strcat astr "*"))
         )
        )
  )
  (foreach n alist
    (mapcar '(lambda (x)
               (if (= (type x) 'STR)
                 (cond ((or (wcmatch x astr)
                            (wcmatch x (strcase astr nil))
                            (wcmatch x (strcase astr T))
                        )
                        (if (not (member (car n) hitlist))
                          (setq hitlist (cons (car n) hitlist))
                        )
                       )
                       (T nil)
                 )
               )
             )
            n
    )
  )
  hitlist
)

SMadsen

  • Guest
Wildcard matching without wildcards
« Reply #8 on: June 18, 2004, 12:21:04 PM »
.. or rather (cond ((not (wcmatch astr "*[`*@?#.]*") ... to exclude most wildcards

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
Wildcard matching without wildcards
« Reply #9 on: June 18, 2004, 12:37:53 PM »
Im getting lost.

What about uppercase 'y' returns all entries with a 'y' in it and a lowercase 'y' with all the entries that start with 'y' and a '*y' to get all the enties that end with 'y'?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Wildcard matching without wildcards
« Reply #10 on: June 18, 2004, 12:40:50 PM »
Works for me.
 :)

ooops  Se7en snuck in there.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
Wildcard matching without wildcards
« Reply #11 on: June 18, 2004, 01:17:11 PM »
Quote from: Se7en
Im getting lost.

No comments  :lol:

j/k .. thanks for the feedback, John

Quote from: Se7en
What about uppercase 'y' returns all entries with a 'y' in it and a lowercase 'y' with all the entries that start with 'y' and a '*y' to get all the enties that end with 'y'?

Because I want normal entry (lazy entry with no shiftkey or much consideration alltogether) to produce the broadest result. So that you can simply type the string you remember best, get the sysvar to pop up and get on with it.

Say you want to check if LOCALROOTPREFIX has the same value as ROAMABLEROOTPREFIX you just type in "roo" or "root" and bam, both pop up. No wildcard considerations.
But, I also want the functionality that SYSVDLG has, to list all vars that start with the same letter. Applying the no-wildcard scheme to that situation was what I was/am unsure of.

SMadsen

  • Guest
Wildcard matching without wildcards
« Reply #12 on: June 18, 2004, 01:22:29 PM »
Quote from: CAB
Works for me.

Excellent! On with the revisions :)

Do any of you want a link to the updated SYSVARDLG.LSP when done?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Wildcard matching without wildcards
« Reply #13 on: June 18, 2004, 01:39:30 PM »
I do.. I do
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Wildcard matching without wildcards
« Reply #14 on: June 18, 2004, 01:50:41 PM »
>Do any of you want a link to the updated SYSVARDLG.LSP when done?

Yes please.........
TheSwamp.org  (serving the CAD community since 2003)