检查数组中的内容是否为单词
下面是我的数组中的内容...
myArray = {"about","name","dsafasdf","fix"};
我想找到这个数组中的英文单词是什么。
下面应该输出:
Words found are as below
about
name
fix
提前感谢!!!
任何示例或链接都可以!
实际上我想实现TextTwist Game。我找到了可能的单词,但是我想检查找到的字符串是否为 WORD/语法...
更新 1
请不要建议我创建一个文件并将单词放入其中,然后然后在这个文件中搜索单词...这将是最糟糕的程序...
Below is what I have in my Array...
myArray = {"about","name","dsafasdf","fix"};
I want to find what are English words in this array.
Below should be output:
Words found are as below
about
name
fix
Thanks in advance!!!
Any example or link would work!!!
Actually I want to implement TextTwist Game. I have found possible words, however I would like to check whether the String found is WORD/ Grammar or not...
Update 1
Please don't advice me to create a file and put words in it and then search word in this file... It will be the WORSTEN program....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
你需要一个包含所有英文单词的图书馆。而且你必须检查每一个字。
这是一个类似的问题。如果您不想使用 java 库,您应该找到一个包含所有单词或类似内容的文本文件,并编写自己的方法来查找单词。请注意,您的文本文件应该进行排序,以便您可以使用分而治之算法查找单词。否则搜索将花费很长时间。
编辑:
而且你还必须记住,名字不是@amit 所说的“英语单词”。他们可以在文字中随处相遇。您应该检查单词是否以大写字母开头并且不在句子的开头。
You need a library with all english words. And you have to check every word.
And this is a similar question. And if you don't want to use a java library you should find a text file containing all words or something like that and write your own method to find a word. Note that your text file should be sorted so you could find word with divide and conquer algorithm. Otherwise searching will take very long time.
EDIT:
And you also have to remember that names are not "English words" as says @amit. An they can meet everywhere in text. You should check if word starts with upper case letter and isn't on the start of sentence.
您需要阅读英语图书馆文件并进行核对。此类文件的示例可以在此处找到:http://wordlist.sourceforge.net/
You will need to read in an English Library file and check against that. An example of such a file can be found here: http://wordlist.sourceforge.net/
我不会像其他答案中建议的那样使用静态的单词集合,而是使用更动态的东西 - 网络。
一个好的启发式可能是 - 搜索您要查找的单词是否出现在维基百科中的文章标题中,如果出现则接受它!
请注意,优点是动态增长的单词“列表”,而不需要将它们存储在字典中。
缺点:IO速度慢[持续的互联网使用],并且列表尚未完整[某些术语没有出现,即使在维基百科中]。它还要求用户在线才能使用此方法。
查看 wikipedia API 了解如何操作。
您可以使用的另一个在线信息源是 Bing Search API [它是免费的!虽然最近遇到了一些问题...]
Instead of working with a static collection of words as suggested in other answers, I would use something much more dynamic - the web.
A good heuristic could be - search if the word you are seeking appears in a title of an article in wikipedia, and accept it if it does!
Note that the advantage is a dynamic growing "list" of words, without the need to store them in a dictionary.
Disadvantages: slow IO [constant internet usage], and the list is yet not full [some terms do not appear, even in wikipedia]. It also requires the user to be on-line to use this approach.
Have a look at wikipedia API to understand how to do it.
Another on-line source of information you can use is Bing Search API [which is free! though has some problems lately...]
第一:定义你的英语单词词典。
然后:将所有这些世界放入
集合
中。最后:对于数组中的每个单词,检查它是否在英语单词集合中。
这不是太高效,但它应该可以完成工作:
First: Define your dictionary of english words.
Then: Put all those worlds in a
Collection
.Finally: For each word in your array, check whether it is in the collection of english words.
This is not excessively performant, but it should do the job:
您可以在字典中查找,也可以使用特定的库:看看 如何用Python检查一个单词是否是英语单词?
You could lookup in a dictionary, or you can use specific libraries for that: have a look at How to check if a word is an English word with Python?
我自己在 java 中实现了 TextTwist 的一个版本,并且我发现从字典文本文件读入一组字符串的效果非常好。
这是我的代码,一个 Java Eclipse 项目,如果您感兴趣的话。请注意,我在实现它时考虑了多人游戏功能,因此代码在客户端/服务器之间分开。 https://github.com/fangsterr/Multiplayer-Text-Twist
I've implemented a version of TextTwist in java myself, and I've found that reading in from a dictionary text file into a Set of String's works great.
Here's my code, a Java Eclipse project, in case you're interested. Note that I implemented it with multiplayer functionality in mind so the code is split between client/server. https://github.com/fangsterr/Multiplayer-Text-Twist