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