コード例 #1
0
        private static void Main(string[] args)
        {
            var trie = new UkkonenTrie <char, int>(0);

            //You can replace it with other trie data structures too
            //ITrie<int> trie = new Trie<int>();
            //ITrie<int> trie = new PatriciaSuffixTrie<int>(3);


            try
            {
                //Build-up
                BuildUp("sample.txt", trie);
                //Look-up
                LookUp("a", trie);
                LookUp("e", trie);
                LookUp("u", trie);
                LookUp("i", trie);
                LookUp("o", trie);
                LookUp("fox", trie);
                LookUp("overs", trie);
                LookUp("porta", trie);
                LookUp("supercalifragilisticexpialidocious", trie);
            }
            catch (IOException ioException) { Console.WriteLine("Error: {0}", ioException.Message); }
            catch (UnauthorizedAccessException unauthorizedAccessException) { Console.WriteLine("Error: {0}", unauthorizedAccessException.Message); }

            Console.WriteLine("-------------Press any key to quit--------------");
            Console.ReadKey();
        }
コード例 #2
0
    public List <string> CheckForItems <T>(string start, UkkonenTrie <string> trie, Dictionary <string, T> dico, char separator)
    {
        List <string> options = new List <string>();

        string[] splittedNarration = start.Split(' ');
        foreach (string s in splittedNarration)
        {
            IEnumerable <string> verbResults = trie.Retrieve(s);
            foreach (string i in verbResults)
            {
                if (i.StartsWith(s))
                {
                    string[] trySplit = i.Split(separator);
                    string   toAdd    = string.Empty;
                    if (trySplit.Length > 1)
                    {
                        bool containsAllParts = true;
                        foreach (string splitted in trySplit)
                        {
                            if (!start.Contains(splitted))
                            {
                                containsAllParts = false;
                            }
                        }
                        if (containsAllParts)
                        {
                            if (typeof(T) == typeof(VerbClasses))
                            {
                                toAdd = string.Format("<color=red>{0}</color>", (dico as Dictionary <string, VerbClasses>)[i].class_key);
                            }
                            if (typeof(T) == typeof(NounClasses))
                            {
                                toAdd = string.Format("<color=blue>{0}</color>", (dico as Dictionary <string, NounClasses>)[i].class_key);
                            }
                        }
                    }
                    else if (start.Contains(i))
                    {
                        if (typeof(T) == typeof(VerbClasses))
                        {
                            toAdd = string.Format("<color=red>{0}</color>", (dico as Dictionary <string, VerbClasses>)[i].class_key);
                        }
                        if (typeof(T) == typeof(NounClasses))
                        {
                            toAdd = string.Format("<color=blue>{0}</color>", (dico as Dictionary <string, NounClasses>)[i].class_key);
                        }
                    }

                    if (!string.IsNullOrEmpty(toAdd) && !options.Contains(toAdd))
                    {
                        options.Add(toAdd);
                    }
                }
            }
        }

        return(options);
    }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: gmamaladze/trienet
 public MainForm()
 {
     InitializeComponent();
     m_Trie          = new UkkonenTrie <char, string>(3);
     folderName.Text =
         Path.Combine(
             Directory.GetCurrentDirectory(),
             "texts");
 }
コード例 #4
0
ファイル: Deck.cs プロジェクト: adelasm/FPlus
        public Card ClosestCard(string input)
        {
            var trie = new UkkonenTrie <int>();

            for (int i = 0; i < cards.Length; i++)
            {
                trie.Add(cards[i].name, i);
            }

            return(cards[trie.Retrieve(input).First()]);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: Nenkai/trienet
        private static void Main(string[] args)
        {
            var trie = new UkkonenTrie <int>(3);

            //You can replace it with other trie data structures too
            //ITrie<int> trie = new Trie<int>();
            //ITrie<int> trie = new PatriciaSuffixTrie<int>(3);


            try
            {
                //Build-up
                BuildUp("sample.txt", trie);
                //Look-up
                LookUp("the", trie);
            }
            catch (IOException ioException) { Console.WriteLine("Error: {0}", ioException.Message); }
            catch (UnauthorizedAccessException unauthorizedAccessException) { Console.WriteLine("Error: {0}", unauthorizedAccessException.Message); }

            Console.WriteLine("-------------Press any key to quit--------------");
            Console.ReadKey();
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: GauthamBanasandra/temp
        static void Main(string[] args)
        {
            var fileHelperEngine = new FileHelperEngine <GeoLocation>();
            var geoLocations     = fileHelperEngine.ReadFile(@"C:\Users\Gautham\Downloads\IN\IN.txt");

            Console.WriteLine($"Count={geoLocations.Length}");

            var indexer = new UkkonenTrie <GeoLocation>(geoLocations.Length);

            foreach (var geoLocation in geoLocations)
            {
                indexer.Add(geoLocation.AsciiName, geoLocation);
            }
            Console.WriteLine("Finished indexing");

            var result = indexer.Retrieve("Bangalore");

            foreach (var geoLocation in result)
            {
                Console.WriteLine($"Id={geoLocation.Id} Name={geoLocation.Name}");
            }
        }
コード例 #7
0
 public void Unload()
 {
     _controlPanelItems = null;
 }
コード例 #8
0
ファイル: AppSearchPlugin.cs プロジェクト: sunero4/pinpoint
 public void Unload()
 {
     _trie = null;
     AppSearchFrequency.Reset();
 }
コード例 #9
0
        //Load a frequency dictionary or create a frequency dictionary from a text corpus
        public static void Main(string[] args)
        {
            var path = AppDomain.CurrentDomain.BaseDirectory + @"all-suggests-cleaned.txt";

            Console.Write("Creating trie ...");
            long      memSize   = GC.GetTotalMemory(true);
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            var wordToIndex   = new Dictionary <string, int>();
            var wordFrequency = new Dictionary <string, int>();
            var phraseList    = new List <string>();
            int count         = 0;

            using (StreamReader sr = new StreamReader(path))
            {
                while (sr.Peek() >= 0)
                {
                    var s = sr.ReadLine();
                    phraseList.Add(s.Trim());

                    var tokens = s.Trim().Split(' ');

                    for (int i = 0; i < tokens.Length; ++i)
                    {
                        int index = 0, freq = 0;
                        if (!wordToIndex.TryGetValue(tokens[i], out index))
                        {
                            wordToIndex[tokens[i]] = count++;
                        }
                        if (!wordFrequency.TryGetValue(tokens[i], out freq))
                        {
                            wordFrequency[tokens[i]] = 1;
                        }
                        else
                        {
                            wordFrequency[tokens[i]] = freq + 1;
                        }
                    }
                }
            }

            long memDeltaForStoringValues = GC.GetTotalMemory(true) - memSize;

            Console.WriteLine("Memory for storing value: " + memDeltaForStoringValues + ". Going to add to trie");

            var trie  = new UkkonenTrie <int>(1);
            int value = 0;

            foreach (var phrase in phraseList)
            {
                trie.Add(phrase, value++);
            }

            //Load a frequency dictionary
            stopWatch.Stop();
            long memDelta = GC.GetTotalMemory(true) - memSize;

            Console.WriteLine("Done in " + stopWatch.Elapsed.TotalMilliseconds.ToString("0.0") + "ms "
                              + (memDelta / 1024 / 1024.0).ToString("N0") + " MB. Token count: " + wordToIndex.Count);

            // spell checker
            var spellChecker = new SymSpell(wordToIndex.Count, 2);

            foreach (var entry in wordFrequency)
            {
                spellChecker.CreateDictionaryEntry(entry.Key, entry.Value);
            }

            while (true)
            {
                Console.WriteLine("Input string to search:");
                var s = Console.ReadLine();
                if (s == "exit")
                {
                    return;
                }

                var normalized = s.ToLower();
                var suggests   = spellChecker.LookupCompound(normalized, 2);

                // lookup in trie
                var results = trie.Retrieve(normalized);

                var resultCount = 0;
                foreach (var result in results)
                {
                    Console.WriteLine("--> " + phraseList[result]);
                    resultCount++;
                }

                var suggest = suggests[0].term;
                foreach (var sug in suggests)
                {
                    Console.WriteLine("Can search for: " + sug.term);
                }
                if (suggest != normalized)
                {
                    Console.WriteLine("Did you mean: " + suggest + "?");
                }

                Console.WriteLine(String.Format("Found {0} result", resultCount));
            }
        }