牛B的Mathematica:寻找开头和结尾都是字母y的形容词
icon2 Program Impossible | icon4 2008-07-30 0:08| icon311 Comments | 本文内容遵从CC版权协议 转载请注明出自matrix67.com

    只有想不到,没有做不到。还是在这里,我惊奇地发现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["m" ~~ "*" ~~ "x"][[3]] ~~
ToString[23*3 - 2] ~~ "原创"
Out[11]= "matrix67原创"

11 条回复

  • 楼层: 沙发 | | welco 说:

    正则么

  • 楼层: 板凳 | | yuye_Abc 说:

    没有sofa

  • 楼层: 地毯 | | Wandsea 说:

    可以的= =
    试试

  • 楼层: 地板 | | hzxswyg 说:

    中文维基 解封了

  • 楼层: 地下室 | | BenMQ 说:

    Hannah这种人名不知道算不算哦

  • 楼层: 地基 | | 叉烧妖 说:

    才看到 太有意思了~

  • 楼层: 地壳 | | 北极冰仔 说:

    这不就是正则表达式吗

  • 楼层: 地幔 | | JooPoo 说:

    acm中用java做正则表达式很有优势。

  • 楼层: 地核 | | iceberg 说:

    不知Mathematica词汇量如何……

  • 楼层: 10楼 | | Kayden 说:

    SdK1k8Bt9VCRr

  • 楼层: 11楼 | | enwikt 说:

    http://en.wiktionary.org/wiki/aibohphobia

您也随便说几句吧:

您可以在 Gravatar 设置您的头像。