首页 \ 问答 \ 确定单词是否可以是英语的算法?(Algorithm to determine if a word could be English?)

确定单词是否可以是英语的算法?(Algorithm to determine if a word could be English?)

我有一个字符串列表,我需要检查英语词典。 但是我不想开始检查列表中的每一个乱码。 首先,我想检查字符串是否是英文单词。

有没有人知道这样做的算法,或者至少我需要应用于验证单词的规则?

例如:

没有说出的单词可以从超过3个辅音开始,如果一个单词中有3个初始辅音,则第一个必须是“s”。


I have a list of strings that I need to check against an English dictionary. However I don't want to start checking every piece of gibberish in the list. First, I want to check if the string could be an English word.

Does anyone know of an algorithm that does this or at least the rules that I need to apply to verify a word?

For example:

No spoken word can start with more than 3 consonants, and if there are are 3 initial consonants in a word, the first one must be "s".


原文:https://stackoverflow.com/questions/6775975
更新时间:2023-10-13 18:10

最满意答案

您可能需要创建自定义控件并自行实现该行为。 我不知道“开箱即用”的解决方案。


Actually since the expander header height never varies (I can set it to a fixed height) and i can get the grid.row "actualheight" AND i needed for all other expanders to be collapsed when one is open I did this in the code behind:

    private void Expander_Expanded(object sender, RoutedEventArgs e)
    {

        var exp = sender as Expander;
        if (exp != null)
        {
            exp.MaxHeight = ListViewGridRowDefinition.ActualHeight -  (ContainerListView.Items.Count*31) + 28;
        }
    }


    private void Expander_Collapsed(object sender, RoutedEventArgs e)
    {
        var exp = sender as Expander;
        if (exp != null)
        {
            exp.MaxHeight = 31;
        }
    }

And this in the xaml:

<Expander Height="Auto" IsExpanded="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}".....

Also to fix a side effect that came out of using this solution (container scrolling still enabled) I applied a template to the container listview to remove scroll behabiour:

    <UserControl.Resources>
    <ControlTemplate x:Key="NoScroll">
        <ItemsPresenter></ItemsPresenter>
    </ControlTemplate>
</UserControl.Resources>

...

    <ListView x:Name="ContainerListView" Template="{StaticResource NoScroll}"

I am using the mvvm pattern but I consider this pure interface interaction so model has no need to know about this, it is fine in codebehind. And it will work for all further uses in MY application. For "allround" reuse a custom control was a good solution, but too much work for my use IMO.

相关问答

更多
  • 好.. 你无法将listboxitem与自己的模板连接起来...因为基本上他们不知道......这在这里不起作用: