Commits

Anonymous committed 48dbcdf

Added a README and removed unused files.

Comments (0)

Files changed (5)

+Hello Justin.tv :)
+My name is Charlie Guse and this is my solution for the spellcheck problem.
+http://www.justin.tv/problems/spellcheck
+
+
+Non-explaining list version of instructions:
+
+Compiling the source:
+    Open up source/spellcheck/spellcheck.sln
+    Compile it.
+    Open up source/spellcheck/spellcheck/bin/Debug(and Release) and put american-english
+    Rename american-english words for the program.
+
+    Follow the same instructions for unspeller to compile and use that.
+
+Using NUnit:
+    Install from http://www.nunit.org/
+    Run NUnit 2.5.10\bin\net-2.0\nunit-x86.exe (NOT nunit.exe)
+    File > Open Project... and open source/nunit_spellcheck/spellcheck.nunit (give an error if the source isn't compiled)
+    
+    Same for source/nunit_unspeller/unspeller.nunit
+
+
+Explaining paragraph version of instructions:  
+
+    If you compile the source code, you will have to manually put the american-english
+dictionary in the Debug/Release folder and rename it words. I didn't make a post-
+build step for that because I only had to do it once. I deleted all of the pre-
+compiled stuff before sending it to you though. Since you know... space is an issue. ;)
+I just wanted to put the source code in it's most basic form as if you were pulling it
+down from source control.
+
+    I used NUnit 2.5.10.11092 for unit testing. If you use the default executable
+(nunit.exe) you will get a BadImageFormat exception. There is a second executable
+named nunit-x86.exe that you need to use instead. If you are unfamiliar with NUnit,
+to use it, open up nunit-x86.exe, File > Open Project... and then go to
+source/nunit_spellcheck/spellcheck.nunit to load the unit test project. If you get
+an error saying Assembly Not Loaded, you will have to compile the Spellcheck project
+once first so it can find the Release version of the dlls.
+
+    This was created in .net 4.0. If this is an issue. Please let me know.
+    

spellcheck/spellcheckLibrary/LetterNode.cs

-using System.Collections.Generic;
-using System.Text;
-
-namespace spellcheckLibrary
-{
-    public class LetterNode
-    {
-        public char Letter;
-        public LetterNode Parent;
-        public Dictionary<char, LetterNode> Nodes;
-        public bool End;
-
-        public LetterNode()
-        {
-            Nodes = new Dictionary<char, LetterNode>();
-        }
-
-        public string GetWord()
-        {
-            StringBuilder word = new StringBuilder();
-            var traverser = this;
-
-            do
-            {
-                word.Insert(0, traverser.Letter);
-                traverser = traverser.Parent;
-            }
-            while (traverser != null);
-
-            return word.ToString();
-        }
-    }
-}

spellcheck/spellcheckLibrary/LetterTree.cs

-using System.Collections;
-using System.Collections.Generic;
-using System.Text;
-
-namespace spellcheckLibrary
-{
-    public struct TraversalData
-    {
-        public int Location;
-        public LetterNode CurrentNode;
-        public Dictionary<char,LetterNode> Nodes;
-    }
-
-    public class LetterTree
-    {
-        private const string NO_SUGGESTION_TEXT = "NO SUGGESTION";
-
-        public Dictionary<char, LetterNode> Tree { get; private set; }
-
-        public LetterTree()
-        {
-            Tree = new Dictionary<char,LetterNode>();
-        }
-
-        public TraversalData GetRoot()
-        {
-            TraversalData treeData = new TraversalData();
-            treeData.Location = -1;
-            treeData.CurrentNode = null;
-            treeData.Nodes = Tree;
-
-            return treeData;
-        }
-
-        public void Add(string word)
-        {
-            var traversal = Traverse(word, GetRoot());
-            AddAtLocation(word, traversal);
-        }
-
-        private void AddAtLocation(string word, TraversalData traversal)
-        {
-            LetterNode node;
-
-            if (traversal.Location < word.Length - 1)
-            {
-                node = new LetterNode();
-                node.Parent = traversal.CurrentNode;
-                node.Letter = word[++traversal.Location];
-                traversal.Nodes.Add(node.Letter,node);
-
-                if (traversal.Location + 1 < word.Length)
-                {
-                    traversal.CurrentNode = node;
-                    traversal.Nodes = node.Nodes;
-                    AddAtLocation(word, traversal);
-                }
-                else
-                    node.End = true;
-            }
-            else
-                traversal.CurrentNode.End = true;
-        }
-
-        // Travels as far as it can before it either comes to the wrong letter
-        // or comes to the end of the tree
-        private TraversalData Traverse(string word, TraversalData traversal)
-        {
-            TraversalData oldSpot;
-            TraversalData newSpot = traversal;
-
-            do
-            {
-                oldSpot = newSpot;
-                newSpot = TraverseOneStep(word, oldSpot);
-
-            } while (oldSpot.Location != newSpot.Location);
-
-            return newSpot;
-        }
-
-        private TraversalData TraverseOneStep(string word, TraversalData traversal)
-        {
-            var currentNode = TraverseNode(word, traversal);
-
-            if (currentNode != null)
-            {
-                traversal.CurrentNode = currentNode;
-                traversal.Nodes = currentNode.Nodes;
-                traversal.Location++;
-            }
-
-            return traversal;
-        }
-
-
-        private LetterNode TraverseNode(string word, TraversalData traversal)
-        {
-            if (traversal.Location < word.Length - 1)
-            {
-                var potentialKey = word[traversal.Location + 1];
-
-                // Check TraversalData.Nodes instead of TraversalData.CurrentNode
-                // because there is not a single tree structure containing all of
-                // the nodes. Instead it is a hash of nodes based on the first letter
-                if (traversal.Nodes.ContainsKey(potentialKey))
-                    return traversal.Nodes[potentialKey];
-            }
-            
-            return null;
-        }
-
-        public string Spellcheck(string word)
-        {
-            return Spellcheck(word, GetRoot());
-        }
-
-        // This function is called recursively from within itself and from within
-        // each letter changing case (including case change)
-        // The order is as follows:
-        // Go to the next letter in the word.
-        // If the letter is good, go to the next letter.
-        // Otherwise, change the casing and and try that.
-        // If that doesn't work, check for repeating letters.
-        // Finally, try changing the vowel if it is one.
-        public string Spellcheck(string word, TraversalData traversal, 
-                                 bool checkingVowel = false, bool checkingCase = false)
-        {
-            if (traversal.CurrentNode != null)
-            {
-                var currentWord = traversal.CurrentNode.GetWord();
-                if (traversal.CurrentNode.End == true && currentWord == word)
-                    return currentWord;
-            }
-            var nextLocation = TraverseOneStep(word, traversal);
-            if (traversal.Location != nextLocation.Location)
-            {
-                var returnedWord = Spellcheck(word, nextLocation);
-
-                if (returnedWord != NO_SUGGESTION_TEXT)
-                    return returnedWord;
-            }
-
-            // If you already changed the case, don't try checking it again.
-            if (!checkingCase && 0 <= traversal.Location + 1 && traversal.Location + 1 < word.Length)
-            {
-                var changedCasing = CheckForImpropperCasing(word, traversal);
-
-                if (changedCasing != NO_SUGGESTION_TEXT)
-                    return changedCasing;
-            }
-
-            if (0 <= traversal.Location && word.Length > 1 && traversal.Location + 1 < word.Length
-                && word[traversal.Location] == word[traversal.Location + 1])
-            {
-                var processedWord = ProcessRepeatedLetter(word, traversal);
-
-                if (processedWord != NO_SUGGESTION_TEXT)
-                    return processedWord;
-            }
-
-            // If you are still checking vowels, so don't try checking them again.
-            if (!checkingVowel && 0 <= traversal.Location + 1 
-                && traversal.Location + 1 < word.Length
-                && IsVowel(word[traversal.Location + 1]))
-            {
-                var changedVowel = CheckForIncorrectVowel(word, traversal);
-
-                if (changedVowel != NO_SUGGESTION_TEXT)
-                    return changedVowel;
-            }
-
-            return NO_SUGGESTION_TEXT;
-        }
-
-        private string CheckForImpropperCasing(string word, TraversalData traversal)
-        {
-            StringBuilder newWord = new StringBuilder(word);
-
-            if (char.IsLower(word[traversal.Location + 1]))
-                newWord[traversal.Location + 1] = char.ToUpper(newWord[traversal.Location + 1]);
-            else
-                newWord[traversal.Location + 1] = char.ToLower(newWord[traversal.Location + 1]);
-
-            return Spellcheck(newWord.ToString(), traversal, true, checkingCase: true);
-        }
-
-        private string CheckForIncorrectVowel(string word, TraversalData traversal)
-        {
-            StringBuilder newWord = new StringBuilder(word);
-
-            foreach (char vowel in GetVowel())
-            {
-                if (vowel != char.ToLower(word[traversal.Location+1]))
-                {
-                    newWord[traversal.Location+1] = vowel;
-                    var spellcheckReturn = Spellcheck(newWord.ToString(), traversal, checkingVowel: true);
-
-                    if (spellcheckReturn != NO_SUGGESTION_TEXT)
-                        return spellcheckReturn;
-                }
-            }
-            return NO_SUGGESTION_TEXT;
-        }
-
-        private string ProcessRepeatedLetter(string word, TraversalData traversal)
-        {
-            // Strip off the repeating letter and run it through spellcheck again
-            StringBuilder newWord = new StringBuilder(word);
-
-            if (traversal.Location >= 0
-                   && newWord[traversal.Location] == newWord[traversal.Location + 1])
-            {
-                newWord = newWord.Remove(traversal.Location, 1);
-
-                if (traversal.CurrentNode.End
-                    && traversal.CurrentNode.GetWord() == newWord.ToString())
-                    return traversal.CurrentNode.GetWord();
-
-                // Try to backtrack one because if you delete on and it lands
-                // on a vowel, you will need to be able switch it out in the
-                // spellcheck function
-                if (traversal.CurrentNode.Parent != null)
-                {
-                    traversal.CurrentNode = traversal.CurrentNode.Parent;
-                    traversal.Nodes = traversal.CurrentNode.Nodes;
-                    traversal.Location--;
-                }
-                var spellCheckedWord = Spellcheck(newWord.ToString(), traversal);
-
-                if (spellCheckedWord != NO_SUGGESTION_TEXT)
-                    return spellCheckedWord;
-
-            }
-            return NO_SUGGESTION_TEXT;
-        }
-
-        private bool IsVowel(char character)
-        {
-            foreach (char vowel in GetVowel())
-            {
-                if (char.ToLower(character) == vowel)
-                    return true;
-            }
-            return false;
-        }
-
-        private IEnumerable GetVowel()
-        {
-            yield return 'a';
-            yield return 'e';
-            yield return 'i';
-            yield return 'o';
-            yield return 'u';
-            yield return 'y';
-        }
-    }
-}

spellcheck/spellcheckLibrary/Properties/AssemblyInfo.cs

-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following 
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("spellcheckLibrary")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("spellcheckLibrary")]
-[assembly: AssemblyCopyright("Copyright ©  2011")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible 
-// to COM components.  If you need to access a type in this assembly from 
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("40e3ba2e-f675-4d88-b1ea-338b1a941538")]
-
-// Version information for an assembly consists of the following four values:
-//
-//      Major Version
-//      Minor Version 
-//      Build Number
-//      Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers 
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]

spellcheck/spellcheckLibrary/spellcheckLibrary.csproj

-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>8.0.30703</ProductVersion>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectGuid>{E16E9C15-3763-426E-AAC1-14B6FCBF1AE3}</ProjectGuid>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>spellcheckLibrary</RootNamespace>
-    <AssemblyName>spellcheckLibrary</AssemblyName>
-    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <ItemGroup>
-    <Reference Include="System" />
-    <Reference Include="System.Core" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Xml" />
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="LetterNode.cs" />
-    <Compile Include="LetterTree.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
-  </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>