当前位置: 首页>>代码示例>>C#>>正文


C# Trie.Put方法代码示例

本文整理汇总了C#中Trie.Put方法的典型用法代码示例。如果您正苦于以下问题:C# Trie.Put方法的具体用法?C# Trie.Put怎么用?C# Trie.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Trie的用法示例。


在下文中一共展示了Trie.Put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main()
    {
        Trie<string> trie = new Trie<string>();
        StreamReader reader = new StreamReader(@"../../../text.txt");
        using (reader)
        {
            string text = reader.ReadToEnd();

            char[] separators = { ' ', '.', '!', '-', '?', '_' };
            string[] array = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < array.Length; i++)
            {
                trie.Put(array[i], i.ToString());
            }

            string word = "Conan";
            for (int i = 0; i < word.Length; i++)
            {

            }
            foreach (var item in trie.Matcher.GetPrefixMatches())
            {
                Console.WriteLine(item);
            }
            Console.WriteLine(trie.Matcher.GetExactMatch());
        }
    }
开发者ID:Jarolim,项目名称:TelerikAcademy-1,代码行数:28,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            GenerateRandomWords();
            GenerateText("..//..//text.txt");

            Dictionary<string,int> wordsCount=new Dictionary<string, int>();

            var trie=new Trie<string>();
            var reader = new StreamReader("..//..//text.txt");
            
            string result = reader.ReadToEnd();
            reader.Close();

            var wordsWritten = result.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < 10000; i++)
            {
                trie.Put( words[i], i.ToString());
            }

            foreach (var word in wordsWritten)
            {
                foreach (var c in word)
                {
                    if (!trie.Matcher.NextMatch(c))
                    {
                        break;
                    }
                }
                if (trie.Matcher.IsExactMatch())
                {
                    var w = trie.Matcher.GetPrefix();
                    if (!wordsCount.ContainsKey(w))
                    {
                        wordsCount[w] = 0;
                    }
                    wordsCount[w]++;
                }
                trie.Matcher.ResetMatch();
               
            }

            Console.WriteLine("There are {0} matched words in the dictionary wordsCount",wordsCount.Count);
        }
开发者ID:GenoGenov,项目名称:TelerikAcademyAssignments,代码行数:43,代码来源:Program.cs

示例3: LoadDictionary

        public bool LoadDictionary(string flieName)
        {
            XmlDocument xmlDoc = new XmlDocument();
            if (!File.Exists(flieName))
                return false;
            xmlDoc.Load(flieName);
            if (!xmlDoc.DocumentElement.HasChildNodes)
                return false;

            XmlNodeList dictionaryNode = xmlDoc.DocumentElement.ChildNodes;
            Trie<Word> tempTrie = new Trie<Word>();
            for (int i = 0; i < dictionaryNode.Count; i++)
            {
                if (dictionaryNode[i].Name == "word")
                {
                    if (dictionaryNode[i].HasChildNodes)
                    {
                        XmlNodeList wordNodes = dictionaryNode[i].ChildNodes;
                        Word word = new Word();
                        for (int j = 0; j < wordNodes.Count; j++)
                        {
                            if (wordNodes[j].Name == "term")
                            {
                                word.Term = wordNodes[j].InnerText;
                            }
                            else if (wordNodes[j].Name == "frequency")
                            {
                                ushort f = 0;
                                ushort.TryParse(wordNodes[j].InnerText, out f);
                                word.OverallFrequency = f;
                            }
                        }
                        if (this.IsCaseSensitive)
                            tempTrie.Put(word.Term, word);
                        else
                            tempTrie.Put(word.Term.ToLower(System.Globalization.CultureInfo.CurrentCulture), word);
                    }
                }
                else if (dictionaryNode[i].Name == "settings")
                {
                    if (dictionaryNode[i].HasChildNodes)
                    {
                        XmlNodeList settingsNodes = dictionaryNode[i].ChildNodes;
                        for (int j = 0; j < settingsNodes.Count; j++)
                        {
                            if (settingsNodes[j].Name == "case_sensitive")
                            {
                                if (settingsNodes[j].InnerText == "true")
                                    this.IsCaseSensitive = true;
                                else if (settingsNodes[j].InnerText == "false")
                                    this.IsCaseSensitive = false;
                            }
                            else if (settingsNodes[j].Name == "valid_characters")
                            {
                                this.ValidCharacters.Clear();
                                string s = settingsNodes[j].InnerText;
                                foreach (char ch in s)
                                   this.ValidCharacters.Add(ch);
                            }
                            else if (settingsNodes[j].Name == "reset_characters")
                            {
                                this.ResetCharacters.Clear();
                                foreach (char ch in settingsNodes[j].InnerText)
                                    this.ResetCharacters.Add(ch);
                            }
                        }
                    }
                }
            }
            this.ValidCharacters.Sort();
            this.ResetCharacters.Sort();
            this.trie = tempTrie;
            return true;
        }
开发者ID:tqphan,项目名称:Virtual-Keyboard,代码行数:74,代码来源:WordPredictor.cs


注:本文中的Trie.Put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。