Created
October 10, 2014 08:32
-
-
Save sudipto80/5c887a7df2971c84c196 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string keyPad = @"2 = ABC2 | |
3 = DEF3 | |
4 = GHI4 | |
5 = JKL5 | |
6 = MNO6 | |
7 = PQRS7 | |
8 = TUV8 | |
9 = WXYZ9"; | |
Dictionary<char,char> keyMap = new Dictionary<char,char>(); | |
//4663 can lead to "good","home" etc | |
string key = "4663"; | |
//"735328";//select/reject | |
//"select" and "reject" can be typed using the key combination "735328" | |
List<KeyValuePair<string,string>> keyAndLetters = | |
keyPad.ToLower() | |
.Split(new char[]{'\r','\n'},StringSplitOptions.RemoveEmptyEntries) | |
.Select | |
( | |
p => | |
new KeyValuePair<string,string>(p.Split('=')[0].Trim(),p.Split('=')[1].Trim())) | |
.ToList(); | |
foreach (var keyL in keyAndLetters) | |
{ | |
foreach (char c in keyL.Value.ToCharArray()) | |
keyMap.Add(c,Convert.ToChar( keyL.Key)); | |
} | |
StreamReader sr = new StreamReader ("C:\\T9.txt"); | |
string total = sr.ReadToEnd(); | |
sr.Close(); | |
var query = total | |
.Split(new char[]{'\r','\n',' '},StringSplitOptions.RemoveEmptyEntries) | |
.Where (t => t.Length==key.Length) | |
.Select (t => t.Trim()); | |
query | |
.ToList() | |
.Select(w => new KeyValuePair<string,string>(w, | |
new string( w.ToCharArray() | |
.Select (x => keyMap[x] ) | |
.ToArray()))) | |
.Where (w => w.Value==key) | |
.Select (w => w.Key) | |
.Dump("Word suggestions"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment