从朋友的群里看到这个图片,
突发奇想暴力找出图片所有单词的组合,然后检验每个单词组合是否合法
{% asset_img word.jpg %}
就可以找出图中所有单词了~~(就是闲着没事干(●´∀`●)~~
重点是检验单词合法性,Python有一个现成的库可以拿来用:NLTK
安装
pip3 install nltk
配置
$python3
>>>import nltk
>>>nltk.download('wordnet')
使用
from nltk.corpus import wordnet
if wordnet.synsets(w):
print("w字符串是单词")
else:
print("w字符串不是单词")
搞定了单词检验问题,剩下的就好办了
验证程序源码
from nltk.corpus import wordnet
word = [
"xcualoveykbwsng",
"duawkcbeautyrjv",
"youthfsmgnezlpr",
"mhjreywdkzlustj",
"fsuccessdhealth",
"enmqsptimelmsaq",
"vexperienceghbw",
"humouiliomoneyz",
"syzpopularitynay",
"amkefunbixhuzyix",
"cwihysihappiness",
"honestycifriends",
"kpyjaetwpowerqc"
]
count = 1
for i in word:
print("\n第%d行:" % count, end=" ")
count += 1
for index in range(len(i)):
for end in range(index+2, len(i)):
if wordnet.synsets(i[index:end]):
print(i[index:end], end=" ")
运行结果:
第1行: love
第2行: be beau beaut beauty
第3行: youth out
第4行: lust us
第5行: success cess he heal
第6行: time
第7行: experience peri erie
第8行: hum money
第9行: pop popular popularity arity
第10行: fun
第11行: ha pi pin pine pines
第12行: hone hones honest honesty on one ones onest nest est sty friend end
第13行: pow power owe