1
$\begingroup$

I pretend to use DictionaryLookup[{"Language", complex_Pattern}] but can not achieve it finally to get it with like three layers ... Specially, I tried Except[c, p] ... but did not arrive to use it because did not produce de wished output

css_ss _s = 
 Select[Select[DictionaryLookup[{"Catalan", ___ ~~ "s" ~~ ___ }], 
   StringMatchQ[#, ___ ~~ "ss" ~~ ___] == False &], 
  StringMatchQ[#, ___ ~~ "s"] == False &]

But the output is what I pretended, the question is: Is there a less layered way to arrive at the same point?

$\endgroup$
5
  • $\begingroup$ Maybe try Cases[...,Except[...]] instead of using Select. $\endgroup$ – Daniel Lichtblau Feb 26 '20 at 18:48
  • 1
    $\begingroup$ I forgot to say I had tested Cases too, the problem is that using Except I am affraid I do not know how to use and the help does not make it clear, Tried Except[c,~~"ss"~~] and also ~~Except["ss"]~~ well like I told before I do not have strong knowledge on Patterns and Except and about Cases and Select I must recognize that I feel more confortable with Select... finally it worked in this onion-style way $\endgroup$ – Anxon Pués Feb 26 '20 at 19:06
  • 1
    $\begingroup$ Mathematica doesn't recognise the syntax css_ss _s =. Is this what you intended? $\endgroup$ – mikado Feb 26 '20 at 21:01
  • $\begingroup$ StringMatchQ[#, ___ ~~ "s"] == False & is equivalent to setting pattern in DictionaryLookup to ___~~"s"~~___~~Except["s"] $\endgroup$ – Wjx Feb 27 '20 at 2:57
  • $\begingroup$ @mikado - well this naming was not clever I detected the problem after and now use without underlines. $\endgroup$ – Anxon Pués Feb 27 '20 at 8:59
1
$\begingroup$

Here are a few different approaches.

dict = DictionaryLookup[{"Catalan", ___ ~~ "s" ~~ ___}, 140];

DeleteCases[dict, str_ /; StringMatchQ[str,
   Alternatives[___ ~~ "ss" ~~ ___  ,  ___ ~~ "s"]]]

Select[dict, Not@StringMatchQ[#,
    Alternatives[___ ~~ "ss" ~~ ___  ,  ___ ~~ "s"]] &]

Select[dict, (StringFreeQ[#, "ss"] && StringFreeQ[#, "s" ~~ EndOfString]) &]

(*  {"abalisa", "abalisà", "abalisada", "abalisam", "abalisant", "abalisar"}   *)

I could not get Except to work.

$\endgroup$
0
$\begingroup$

How about this?

nots = RegularExpression["[^s]"];
DictionaryLookup[{"Catalan", a___ ~~ "s" ~~ b__ /; StringEndsQ[a, nots] && StringStartsQ[b, nots] && StringEndsQ[b, nots]}]

where the substring a has a string length of $ \geq 0 $ and not ends with "s", and at the same time the substring b has a length of $ \geq 1 $ without "s" as its two ends.

And it seems that RegularExpression["[^s]"] can be replaced by Except["s"].

$\endgroup$
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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