根据微软单词词典生成单词列表 - 在某些时候停止工作 - 为什么?

发布于 2024-09-29 05:05:18 字数 3665 浏览 9 评论 0原文

我编写了一个小应用程序,它生成单词,然后根据 Microsoft Word 2007 词典验证它们。

当我针对 3 个字母长度的英语词典(我猜还有更多字母)对其进行测试时,这对我来说非常有用,但由于某种原因,当我尝试针对希伯来语词典运行它时,它停止工作。

有谁知道为什么吗?如果是,我该如何解决? 如果有更好的方法来做到这一点,如果有人能指出,我会很高兴。

谢谢。

更新:当我说它停止时,我的意思是它停止检查单词。我得到所有单词组合直到最后,但它们没有被检查。

MainWindow.xaml

<Window x:Class="AllHebrewWords.CreateDictionary"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="List of words" Height="250" Width="150" Closing="Window_Closing" ResizeMode="CanMinimize">
    <Grid>
        <ListBox Margin="10,10,10,10" Name="WordsList" />
    </Grid>
</Window>

MainWindow.xaml.cs

using System.Diagnostics;
using System.Reflection;
using System.Threading;
using Microsoft.Office.Interop.Word;

namespace AllHebrewWords
{
    public partial class CreateDictionary : System.Windows.Window
    {
        private Application app = null;
        private _Document doc = null;
        private Thread thread = null;
        object oMissing = Missing.Value;

        public CreateDictionary()
        {
            InitializeComponent();

            app = new Application();
            object visible = false;
            doc = app.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref visible);

            thread = new Thread(SearchThread);
            thread.Start();
        } // End of function

        public void SearchThread()
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            for (char ch = 'א'; ch <= 'ת'; ch++)
            {
                AddLetter(ch.ToString());
            } // End of for

            object FileName = "C:/Words";
            object FileFormat = WdSaveFormat.wdFormatText;
            doc.SaveAs( ref FileName, ref FileFormat, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            stopwatch.Stop();

            Dispatcher.Invoke((ThreadStart)delegate() { WordsList.Items.Add("Dictionary ready"); });
            Dispatcher.Invoke((ThreadStart)delegate() { WordsList.Items.Add(stopwatch.Elapsed); });
            Dispatcher.Invoke((ThreadStart)delegate() { WordsList.ScrollIntoView(WordsList.Items[WordsList.Items.Count - 1]); });
        } // End of function

        public bool CheckWord(string word)
        {
           if (app.CheckSpelling(word))
        {
            doc.Words.Last.InsertAfter(word + '\n');
            return true;
        }
        return false;
        } // End of function

        public void AddLetter(string word)
        {
            CheckWord(word);

            if (word.Length < 3)
            {
                char ch = word[word.Length - 1];

                for (ch = 'א'; ch <= 'ת'; ch++)
                {
                    word += ch;
                    AddLetter(word);
                    word = word.Remove(word.Length - 1);
                } // End of for
            } // End of if
        } // End of function

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            object saveChanges = false;
            doc.Close(ref saveChanges, ref oMissing, ref oMissing);
            thread.Abort();
            app.Quit(ref saveChanges, ref oMissing, ref oMissing);
        } // End of function
    } // End of class
} // End of namespace

I wrote a small app that Generates words and then verifies them against Microsoft Word 2007 dictionary.

This works great for me when I test it against the english dictionary with 3 letters length(and I guess with more letters) but for some reason it stops working when I try to run it against the hebrew dictionary.

Does any one know why? If yes, how can I solve it?
If there is a better way to do this I will be happy if someone can point out.

thanks.

Update: When I said that it stops I meant that it stops checking the words. I get all words combination until the end but they are not checked.

MainWindow.xaml

<Window x:Class="AllHebrewWords.CreateDictionary"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="List of words" Height="250" Width="150" Closing="Window_Closing" ResizeMode="CanMinimize">
    <Grid>
        <ListBox Margin="10,10,10,10" Name="WordsList" />
    </Grid>
</Window>

MainWindow.xaml.cs

using System.Diagnostics;
using System.Reflection;
using System.Threading;
using Microsoft.Office.Interop.Word;

namespace AllHebrewWords
{
    public partial class CreateDictionary : System.Windows.Window
    {
        private Application app = null;
        private _Document doc = null;
        private Thread thread = null;
        object oMissing = Missing.Value;

        public CreateDictionary()
        {
            InitializeComponent();

            app = new Application();
            object visible = false;
            doc = app.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref visible);

            thread = new Thread(SearchThread);
            thread.Start();
        } // End of function

        public void SearchThread()
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            for (char ch = 'א'; ch <= 'ת'; ch++)
            {
                AddLetter(ch.ToString());
            } // End of for

            object FileName = "C:/Words";
            object FileFormat = WdSaveFormat.wdFormatText;
            doc.SaveAs( ref FileName, ref FileFormat, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                        ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            stopwatch.Stop();

            Dispatcher.Invoke((ThreadStart)delegate() { WordsList.Items.Add("Dictionary ready"); });
            Dispatcher.Invoke((ThreadStart)delegate() { WordsList.Items.Add(stopwatch.Elapsed); });
            Dispatcher.Invoke((ThreadStart)delegate() { WordsList.ScrollIntoView(WordsList.Items[WordsList.Items.Count - 1]); });
        } // End of function

        public bool CheckWord(string word)
        {
           if (app.CheckSpelling(word))
        {
            doc.Words.Last.InsertAfter(word + '\n');
            return true;
        }
        return false;
        } // End of function

        public void AddLetter(string word)
        {
            CheckWord(word);

            if (word.Length < 3)
            {
                char ch = word[word.Length - 1];

                for (ch = 'א'; ch <= 'ת'; ch++)
                {
                    word += ch;
                    AddLetter(word);
                    word = word.Remove(word.Length - 1);
                } // End of for
            } // End of if
        } // End of function

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            object saveChanges = false;
            doc.Close(ref saveChanges, ref oMissing, ref oMissing);
            thread.Abort();
            app.Quit(ref saveChanges, ref oMissing, ref oMissing);
        } // End of function
    } // End of class
} // End of namespace

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文