找出由字母"HELLOWORLD"形成的全部单词 [英] Find out the total words formed with letters 'HELLOWORLD'

查看:119
本文介绍了找出由字母"HELLOWORLD"形成的全部单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个输入字符串"HELLOWORLD".我想使用javascript获得给定字符串由字母组成的所有可能单词.

像这样

输入字符串"Hello wolrd"

出弦:

你好
地狱
世界
红色
单词

...
..
..

请让我知道
在此先谢谢您..

Hi all,
I have an input string "HELLOWORLD". I want to get all the possible words formed by the letters the given string using javascript.

like way,

Input string "Hello wolrd"

out strings:

Hello
hell
world
red
word
low
...
..
..

Please let me know
thanks in advance..

推荐答案

同意您需要自己进行此操作,但是,由于最近我做了类似的事情,我会给您10块的起步价,使用VB.Net,但应可翻译为其他语言,例如您要求的JavaScript.毫无疑问,有更好的方法可以做到这一点,DAWG将是最有效的方法,但可能很难实施.

获取以下更多词典(无定义词典),SOWPODS(官方拼字游戏+官方拼字游戏词典),ENABLE(增强的北美基准LExicon)和TWL(比赛单词列表)中的一种.作为奖励研究这些Lexicons的历史.

创建一个类(或结构),将其称为Words,并使用以下字段,即Word为String,Length为Integer,alphWord为String.构造函数应使用单个单词(字符串)并计算长度及其按字母顺序组织的等效形式(alphWord).

创建一个单词列表,将其命名为MasterList.

循环浏览这些单词列表中的一个或多个,将每个不同的单词添加到列表中.

创建另一个列表(单词),将其命名为FilteredList.

使用List类的FindAll函数从MasterList加载FilteredList.您将需要提供FindAll所需的Predicate(Of T)函数,即自己编写.

为了帮助您使用FindAll函数遍历MasterList,将您编写的函数应用于List的每个成员,如果该函数返回True,它将将该成员添加到FilteredList,因此,当它完成遍历MasterList的循环时,FilteredList将仅在功能中包含与您的条件匹配的条件.

为了进一步帮助您使用Predicate(Of T)函数,Words类具有计算出的alphWord字段的原因. 为了通过此循环练习更快地运行(每个词典包含150k至250k个单词),这是Words类具有长度字段的原因.
我设法在大约2-5秒内浏览了所有3个列表,大约60万个单词.
另外,您可以通过在DataGridView中显示MasterList,从TextBox提供的任何单词并使用FilteredList填充另一个DataGridView的Form中实现它.

如何将其转换为JavaScript取决于您.

Mike
Agree that you need to do this yourself, however, since I have done something similar recently I''ll give you a starter for 10, using VB.Net but should be translatable to other languages, such as the JavaScript you requested. There are no doubt better ways to do this, a DAWG would be the most efficient but probably pretty challenging to implement.

Get get one of more of the following lexicons (dictionaries without definitions), SOWPODS (Official Scrabble Words + Offical Scrabble Players Dictionary), ENABLE (Enhanced North American Benchmark LExicon) and TWL (Tournament Word List). As a bonus research the history of these Lexicons.

Create a class (or structure), let''s call it Words, with these fields, Word as String, Length as Integer, alphWord as String. The constructor should take a single word (string) and calculate the length and it''s alphabetically organised equivalent (alphWord).

Create a List(Of Words), call it MasterList.

Loop through one or more of those word lists, adding each distinct word to the List.

Create another List(Of Words), call it FilteredList.

Use the FindAll function of the List class to load the FilteredList from the MasterList. You will need to supply the Predicate(Of T) function that FindAll requires, i.e. write it yourself.

To help you the FindAll function loops through the MasterList, applying the function you write to each member of the List and if the function returns True it adds that member to the FilteredList, so by the time it finishes looping through the MasterList the FilteredList will only contain those that match your criteria in the function.

To help you a little further with the Predicate(Of T) function, there''s a reason the Words class has a calculated alphWord field.
To make it operate faster through this looping exercise (those lexicons contain between 150k and 250k words each) there''s a reason the Words class has a length field.

I managed to run through all 3 lists, about 600k words, in about 2-5 seconds.
As a bonus you could implement it in a Form that displays the MasterList in a DataGridView, takes any word you supply from a TextBox and populates another DataGridView with the FilteredList.

How you translate that to JavaScript is up to you.

Mike


我们不做您的作业:它的设置是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.
自己尝试,您可能会发现它并不像您想的那么困难!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!


这篇关于找出由字母"HELLOWORLD"形成的全部单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆