Пример #1
0
        internal static Trie <char, List <string> > Load(string binaryFilePath, string positionTriePath)
        {
            var ret = new Trie <char, List <string> >();

            using (StreamReader strmReader = File.OpenText(positionTriePath))
                using (var binReader = new BinaryReader(File.OpenRead(binaryFilePath)))
                {
                    string line;
                    while ((line = strmReader.ReadLine()) != null)
                    {
                        string word     = line.Substring(0, line.IndexOf(" "));
                        long   position = Convert.ToInt64(line.Substring(line.IndexOf(" ") + 1));

                        binReader.BaseStream.Position = position;

                        int howMany = binReader.ReadInt32();

                        var list = new List <string>();
                        for (int i = 0; i < howMany; i++)
                        {
                            list.Add(binReader.ReadString());
                        }

                        list = FileCreator.ReduceNumberOfNgrams(list, new int[] { 0, 1, 350, 245, 105 });

                        ret.Add(word, list);
                    }
                }

            return(ret);
        }