2
$\begingroup$

I would like to find all Italian words that have a specific pattern of letter repetitions.

Actually I'm looking for 6-letters words that have 1 letter repeated 3 times, a second letter repeated two times and another letter repeated 1 time.

I see that I should use:

DictionaryLookup[{"Italian", pattern}]

but I'm not much familiar with patterns and I don't know how to tell Mathematica to choose the words with above letters multiplicity specification.

[BTW, one of these words should be "Pioppo" (italian word for the tree "Poplar")]

I'm rather sure there must be some very simple solutions.

Any help?

$\endgroup$
0

2 Answers 2

2
$\begingroup$

For the given pattern the following solution is about twice as fast as kguler's StringCount/DeleteDuplicates method (however it does scale worse than kguler's):

DictionaryLookup[{"Italian", #}] & /@ 
   Permutations[StringExpression[a_, b_, b_, c_, c_, c_]] // Flatten

{"banana", "cavava", "datata", "lavava", "patata", "scocco", "stette", "cimici", "cinici", "civici", "dividi", "madama", "minimi", "rimiri", "ritiri", "tarata", "temete", "tenete", "vagava", "varava", "popolo", "amammo", "acceca", "errare", "errore", "errerà", "errerò", "orrore", "orrori", "gregge", "pioppo", "scassa", "scosso", "smesse", "smosso", "spesse", "stesse", "tratta", "trotto", "adatta", "avalla", "elegge", "elette", "emette", "eresse", "erette", "estese", "pioppi", "abbaia", "accada", "accasa", "affama", "allaga", "ammala", "annata", "appaga", "appaia", "ebbene", "eccede", "essere", "irrisi", "irriti", "vivevi", "acacia", "ananas", "caccia", "bibbia", "bibbie"}

Originally I came up with the more elegant

DictionaryLookup[{"Italian", 
  Permutations[StringExpression[a_, b_, b_, c_, c_, c_]]}] // Flatten

but it seems that DictionaryLookup doesn't handle string patterns with alternatives correctly.

$\endgroup$
4
$\begingroup$

6-letters words that have 1 letter repeated 3 times, a second letter repeated two times and another letter repeated 1 time

condF = With[{pat = #}, StringLength[pat] == 6 && 
           (Sort[StringCount[pat, #] & /@ DeleteDuplicates[Characters[pat]]] == {1, 2, 3})] &;

DictionaryLookup[{"Italian", pat : (__) /; (condF@pat)}]
(* {"abbaia","acacia","accada","accasa","acceca","adatta","affama",
"allaga","amammo","ammala","ananas","annata","appaga","appaia",
"avalla","banana","bibbia","bibbie","caccia","cavava","cimici",
"cinici","civici","datata","dividi","ebbene","eccede","elegge",
"elette","emette","eresse","erette","errare","errerà","errerò",
"errore","essere","estese","gregge","irrisi","irriti","lavava",
"madama","minimi","orrore","orrori","patata","pioppi","pioppo",
"popolo","rimiri","ritiri","scassa","scocco","scosso","smesse",
"smosso","spesse","stesse","stette","tarata","temete","tenete",
"tratta","trotto","vagava","varava","vivevi"}*)

The ones starting with "p":

DictionaryLookup[{"Italian", pat : ("p" ~~ __) /; (condF@pat)}]
(* {"patata","pioppi","pioppo","popolo"} *)
$\endgroup$
6
  • $\begingroup$ condF = With[{pat = #}, StringLength[pat] == 6 && Sort[Tally[Characters[pat]][[All, 2]]] == {1, 2, 3}] &; is about 25% faster $\endgroup$ Commented Dec 7, 2014 at 15:45
  • $\begingroup$ @Sjoerd, shorter / more elegant too. Perhaps that should also be posted as an answer? (I am hoping that someone will also post an answer that uses a regex pattern.) $\endgroup$
    – kglr
    Commented Dec 7, 2014 at 16:22
  • $\begingroup$ @kguler wonderful! Thanks! And what If I would find, between these words, the ones that have the maximum number of meaningful anagrams? $\endgroup$
    – Luca M
    Commented Dec 7, 2014 at 16:34
  • $\begingroup$ @SjoerdC.deVries even better! Thanks! $\endgroup$
    – Luca M
    Commented Dec 7, 2014 at 16:35
  • $\begingroup$ @LucaM, i suggest you wait for a few days before you accept an answer. Questions with accepted answers tend to get less attention, and, in particular, questions related to string patterns tend to get answers over several days. $\endgroup$
    – kglr
    Commented Dec 7, 2014 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.