您当前的位置:首页 > 学习 > 阅览室

牛B的Mathematica:寻找开头和结尾都是字母y的形容词

时间:12-04来源:作者:点击数:

只有想不到,没有做不到。还是在这里(http://blog.wolfram.com/2008/07/25/word-combinatorics/),我惊奇地发现Mathematica居然有DictionaryLookup和WordData这样的函数(我的6.0里就有,不知道5.x有没有)。于是,一连串牛B的Mathematica用法出现了:

包含ijk三个连续字母的单词:

In[1]:= DictionaryLookup["*" ~~ "ijk" ~~ "*"]
Out[1]= {"Dijkstra"}

连续三次出现重复字母的单词:

In[2]:= DictionaryLookup[RegularExpression[".*(.)1(.)2(.)3.*"]]
Out[2]= {"bookkeeper", "bookkeepers", "bookkeeping"}

首尾三个(及以上)的字母完全相同的单词:

In[3]:= DictionaryLookup[RegularExpression["([a-z]{3,})[a-z]*1"]]
Out[3]= {"abracadabra", "anticoagulant", "antidepressant",
"antioxidant", "antiperspirant", "bedaubed", "beriberi", "bonbon",
"cancan", "chichi", "couscous", "dumdum", "entailment",
"entanglement", "entertainment", "enthrallment", "enthronement",
"enticement", "entitlement", "entombment", "entrainment",
"entrancement", "entrapment", "entrenchment", "froufrou", "hotshot",
"hotshots", "ingesting", "ingoing", "ingraining", "ingratiating",
"ingrowing", "ionization", "mesdames", "microcosmic", "murmur",
"muumuu", "outshout", "outshouts", "physiography", "pompom",
"redelivered", "rediscovered", "respires", "restores",
"restructures", "tartar", "tessellates", "testates", "testes",
"tormentor", "tsetse", "underfund", "underground"}

最长的5个只用键盘最上面一排的字母就可以打出的单词:

In[4]:= Take[
Sort[DictionaryLookup[RegularExpression["[qwertyuiop]+"]],
  StringLength[#1] > StringLength[#2] &], 5]
Out[4]= {"typewriter", "repertoire", "proprietor", "perpetuity",
"typewrote"}

最大的10个“16进制单词”:

In[5]:= Take[
Sort[DictionaryLookup[RegularExpression["[a-f]+"]],
  FromDigits[#1, 16] > FromDigits[#2, 16] &], 10]
Out[5]= {"effaced", "defaced", "acceded", "faffed", "facade",
"efface", "deface", "deeded", "decaff", "decade"}

回文单词:

In[6]:= Select[DictionaryLookup["*"], # == StringReverse[#] &]
Out[6]= {"a", "aha", "aka", "bib", "bob", "boob", "bub", "CFC",
"civic", "dad", "deed", "deified", "did", "dud", "DVD", "eke", "ere",
"eve", "ewe", "eye", "gag", "gig", "huh", "I", "kayak", "kook",
"level", "ma'am", "madam", "mam", "MGM", "minim", "mom", "mum",
"nan", "non", "noon", "nun", "oho", "pap", "peep", "pep", "pip",
"poop", "pop", "pup", "radar", "redder", "refer", "repaper",
"reviver", "rotor", "sagas", "sees", "seres", "sexes", "shahs",
"sis", "solos", "SOS", "stats", "stets", "tat", "tenet", "TNT",
"toot", "tot", "tut", "wow", "WWW"}

最长的10个没有重复字母的单词:

In[7]:= Take[
Sort[Select[DictionaryLookup["*"],
   Count[Characters[#], First[Commonest[Characters[#]]]] == 1 &],
  StringLength[#1] > StringLength[#2] &], 10]
Out[7]= {"ambidextrously", "unproblematic", "unpredictably",
"sharp-tongued", "hydromagnetic", "draughtswomen", "copyrightable",
"upholstering", "unprofitably", "unprofitable"}

单词axiom是什么意思?

In[8]:= WordData["axiom", "Definitions"]
Out[8]= {{"axiom", "Noun", "Proposition"} ->
"(logic) a proposition that is not susceptible of proof or
   disproof; its truth is assumed to be self-evident",
{"axiom", "Noun", "Saying"} -> "a saying that is widely accepted on its own merits"}

开头和结尾都是字母y的形容词:

In[9]:= Select[DictionaryLookup["y" ~~ "*" ~~ "y"],
MemberQ[WordData[#, "PartsOfSpeech"], "Adjective"] &]
Out[9]= {"yearly", "yeasty", "yucky", "yummy"}

某个人体部位,以字母x结尾:

In[10]:= Select[WordData["body", "PartTerms", "List"],
StringMatchQ[#, "*" ~~ "x"] &]
Out[10]= {"cervix", "thorax"}

另类字符串输出:

In[11]:=
DictionaryLookup["c" ~~ "*" ~~ "n"][[3]] ~~
ToString[sd] ~~ "原创"
Out[11]= "cdsy原创"
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐