// Returns a BK-Tree (String match tree) public static MatchTree <string> InitBKTree(string filePath) { bool finishedBuildingTree = false; int addedLines = 0; MatchTree <string> bkTree = new MatchTree <string>(); try { // Reads the words dictionary file, eeach line contains different word string[] readLines = File.ReadAllLines(filePath); // Start a new Task to print to the console the progress of the building Task writeToConsoleTask = Task.Factory.StartNew(() => { while (!finishedBuildingTree) { Console.WriteLine("Reading word dictionary {0}/{1}", addedLines, readLines.Length); } }); Console.WriteLine("Started building tree"); foreach (string line in readLines) { bkTree.add(line); addedLines++; } finishedBuildingTree = true; Console.Clear(); Console.WriteLine("Finished building tree"); } catch (IOException ioe) { Console.WriteLine("Something went wrong reading the input file."); Console.WriteLine(ioe.Message); } catch (Exception e) { Console.WriteLine("Something went wrong"); Console.WriteLine(e.Message); } return(bkTree); }
// Called after Awake is done, run once // Used for second initialization private async void Start() { matchTree = SuggesterHelper.InitBKTree(dictionaryFilePath); //CancellationTokenSource cts = new CancellationTokenSource(); // //var searchTask = matchTree.root.SearchSubTree("hello", 3, cts.Token); //Dictionary<string, int> foundMatches = await searchTask; // //foreach (KeyValuePair<string, int> pair in foundMatches) { // Console.WriteLine(" - {0}", pair.Key); //} searchQueue = new SearchQueue <string>(); drawTask = Task.Factory.StartNew(() => { while (true) { Draw(); Thread.Sleep(drawTaskSleep); } }); updateTask = Task.Factory.StartNew(() => { while (true) { Update(); } }); }