MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: help with DictionaryLookup[] and a type of regular

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109649] Re: help with DictionaryLookup[] and a type of regular
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Mon, 10 May 2010 06:38:23 -0400 (EDT)

Hi Michael,

I don't know how to do this using only regular expressions, but you can also
use Mathematica's string-matching syntax. Here is one way:

In[1]:= words = DictionaryLookup[{"English", "*"}];

In[2]:= Union@
 Flatten@StringCases[
   words, ("d" ~~
      LetterCharacter ~~ (x : LetterCharacter) ~~ (y :
        LetterCharacter) ~~ LetterCharacter ~~ "k") /; x === y]

Out[2]= {"dybbuk"}

You can find it faster to first do the regexp part and then filter the
resulting list of words:

In[3]:= wlist =
 DictionaryLookup[{"English", RegularExpression["d....k"]}]

Out[3]= {"damask", "debark", "debunk", "dybbuk"}

In[4]:= Select[wlist,
 StringTake[#, {3, 3}] === StringTake[#, {4, 4}] &]

Out[4]= {"dybbuk"}

Both solutions are admittedly more verbose than the one which would use only
regexps (assuming it exists) -  may be you'll get more elegant solutions
from others.

Regards,
Leonid

On Sun, May 9, 2010 at 4:51 AM, Michael Stern <nycstern at gmail.com> wrote:

> Is there an elegant way to do dictionary searches that match specified
> kinds of character repetition? For example, to search for six letter
> words that start with "d" and end with "k", where the third and fourth
> letter are the same?
>
> Finding six letter words that start with "d" and end with "k" is easy --
>
> DictionaryLookup[{"English", RegularExpression["d....k"]}]
>
> But how do we restrict the answer to words where the third and fourth
> letters are the same?
>
> Thanks,
>
> Michael=
>
>


  • Prev by Date: Re: Variables in Iterator limits?
  • Next by Date: Re: RuleDelayed for parsing XML with multiple children
  • Previous by thread: Re: Number of ways of permutations to form a certain pattern of
  • Next by thread: WeatherData times