Re: PATCH: Beagle Spell Checker



On Wed, 7 Jul 2004 11:32:40 -0400, gasiorek wrote
> Hi all, I hacked up some code to bring a spell checker to beagle.  
> First sorry for the long email.  Now because of the veriety of 
> searches that Best will receive (names, words, phrases...) no single 
> spell checker really does the whole job.  Therefor I have 
> implemented the spell checker to be as extendable as possible as to 
> incorporate lots of "dictionarys".  This patch is just of the 
> utility file that does the work and does not actual function as part 
> of Best, yet.  It would be nice to get some more dictionarys in it.  
> Dictionarys that I have looked at are:
> 
> Google     Good:  Incorporates more than just words
>            Bad:   Need Net connection to use
> 
> Aspell#    Good:  Project on Novell Forge
>            Bad:   No code
> 
> Aspell.NET Good:  Bindings written
>            Bad:   Written with a win32 system in mind
> 
> Gnome-spell Good:  Comes with GNOME
>             Bad:   Bonobo & Cobra code nastyness
> 
> NetSpell    Good:  Very good spell checker
>             Bad:   Written for win32
> 
> With the Spell Check system I hacked up to incorporate a new 
> dictionary all that is required is to create a class derived from 
> the generic "Dictionary" class, and add your spell checker to the 
> initialization in the SpellChecers Constructor.
> 
> To incorporate the spell checker into Best all you need is the following:
> SpellCheckers sc = new SpellCheckers (); // Only Done Once
> sc.CheckWord (searchString);
> 
> Anyways, again sorry for the long email.  Please email me if you 
> have any suggestions.
> 
> -- Joe Gasiorek
> gasiorek yakko cs wmich edu
> 
> _______________________________________________
> Dashboard-hackers mailing list
> Dashboard-hackers gnome org
> http://mail.gnome.org/mailman/listinfo/dashboard-hackers

Very sorry...this time I will attach the patch.

-- Joe Gasiorek
gasiorek yakko cs wmich edu

diff -u --recursive --exclude=CVS --new-file clean/beagle/Util/Makefile.am beagle/Util/Makefile.am
--- clean/beagle/Util/Makefile.am	2004-06-24 20:55:16.000000000 -0400
+++ beagle/Util/Makefile.am	2004-07-07 11:00:57.698074104 -0400
@@ -21,6 +21,7 @@
 	$(srcdir)/MultiReader.cs	\
 	$(srcdir)/NautilusTools.cs	\
 	$(srcdir)/PullingReader.cs	\
+	$(srcdir)/Spell.cs		\
 	$(srcdir)/StringFu.cs
 
 ASSEMBLIES =			\
diff -u --recursive --exclude=CVS --new-file clean/beagle/Util/Spell.cs beagle/Util/Spell.cs
--- clean/beagle/Util/Spell.cs	1969-12-31 19:00:00.000000000 -0500
+++ beagle/Util/Spell.cs	2004-07-07 11:00:57.697074256 -0400
@@ -0,0 +1,133 @@
+//
+// Spell.cs
+//
+// Copyright (C) 2004 Joe Gasiorek
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+using System.Collections;
+using System.Threading;
+
+namespace Beagle.Util {
+
+	public class SpellCheckers {
+	
+		static bool SpelledCorrectly;
+		static string Search;
+		static ArrayList Suggestions;
+		ArrayList Dictionarys = new ArrayList ();
+
+		//
+		// Dictionary Defaults
+		// Must be overridden
+		//
+		
+		protected abstract class Dictionary {
+			public bool Initialized;
+			public Thread thread;
+		
+			public Dictionary () { } // Default Constructor, should get overriden for initization is needed
+			virtual public void ThreadLoop () { } // Code to check spelling, needs to be overriden
+			public Thread MakeThread () { 
+				return new Thread (new ThreadStart (this.ThreadLoop));
+			}
+			
+		}	
+		
+		//
+		// Individual Dictionary Classes
+		//
+
+		protected class GoogleDictionary : Dictionary {
+			string googleKey;
+			GoogleSearchService gss = new GoogleSearchService ();
+
+			public GoogleDictionary () {
+				googleKey = Environment.GetEnvironmentVariable ("GOOGLE_WEB_API_KEY");
+				if (googleKey == null || googleKey == "") {
+					Console.WriteLine ("No Google Key");
+					Initialized = false;
+					return;
+				}
+				Initialized = true;
+			}
+
+			public override void ThreadLoop () {
+				string result = gss.doSpellingSuggestion (googleKey, Search);
+				lock (this) {
+					if (result != null) {
+						Suggestions.Add (result);
+						SpelledCorrectly = false;
+						Console.WriteLine ("SPELLER:  {0}", result);
+					}
+				}
+			}
+		}
+			
+		public SpellCheckers () {
+
+			Dictionary Google = new GoogleDictionary ();
+			if (Google.Initialized)
+				Dictionarys.Add (Google);
+		
+		}
+
+		public ArrayList CheckWord (string query) {
+			
+			Suggestions = new ArrayList ();
+			Search = query;
+			SpelledCorrectly = true;
+			bool AllThreadsDead = false;
+
+			foreach (Dictionary sct in Dictionarys) {
+				sct.thread = sct.MakeThread ();
+				sct.thread.Start ();
+			}
+
+			while ((AllThreadsDead == false) && (SpelledCorrectly == true)) {
+				AllThreadsDead = true;
+				foreach (Dictionary sct in Dictionarys) {
+					if (sct.thread.IsAlive)
+						AllThreadsDead = false;
+				}
+				Thread.Sleep (1);
+			}
+			
+			foreach (Dictionary sct in Dictionarys) {
+				if (sct.thread.IsAlive)
+					sct.thread.Abort ();
+			}
+
+			if (SpelledCorrectly == false) {
+				Console.WriteLine ("SPELLER: Word was spelled wrong");
+				foreach (String s in Suggestions)
+					Console.WriteLine ("SPELLER: Try {0}", s);
+			}
+			else {
+				Console.WriteLine ("SPELLER: Word was spelled correctly");
+			}
+			return Suggestions;
+		}
+	}
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]