Esempio n. 1
0
 public FileDR(string binaryFilePath, string positionTriePath)
 {
     positionTrie       = PositionTrieCreator.CreatePositionTrie(positionTriePath);
     reader             = new BinaryReader(File.OpenRead(binaryFilePath));
     cache              = new Cache(1000);
     countOfCacheSolved = 0;
 }
Esempio n. 2
0
 internal FileDR(string binaryFilePath, string positionTriePath)
 {
     if (positionTrie == null)
     {
         positionTrie = PositionTrieCreator.CreatePositionTrie(positionTriePath);
     }
     reader = new BinaryReader(File.OpenRead(binaryFilePath));
     cache  = new Cache(1000);
 }
Esempio n. 3
0
        public static string BinaryFilePartitioningStats(string binFilePath, string positionTriePath, string word)
        {
            string statName = TextFile.FileName(binFilePath) + "PARTITION-STATS-" + word + ".txt";

            var positionTrie = PositionTrieCreator.CreatePositionTrie(positionTriePath);

            using (var binaryReader = new BinaryReader(File.Open(binFilePath, FileMode.Open)))
                using (var statWriter = new StreamWriter(statName))
                {
                    var position = positionTrie.Find(word);

                    binaryReader.BaseStream.Position = position;
                    int howMany = binaryReader.ReadInt32();
                    var ngrams  = new List <string>();

                    for (int i = 0; i < howMany; i++)
                    {
                        ngrams.Add(binaryReader.ReadString());
                    }

                    statWriter.WriteLine($"Word: {word}");
                    int len = 1;
                    while (ngrams.Count != 0)
                    {
                        var found = ngrams.Where(x => x.Length == len);

                        if (found.Count() != 0)
                        {
                            statWriter.WriteLine($"{len} - {found.Count()}");

                            foreach (var n in found.ToList())

                            {
                                ngrams.Remove(n);
                            }
                        }
                        len++;
                    }
                }
            return(statName);
        }