Example #1
0
        public void BoingDawg_Generate()
        {
            const string textFile = "boing_crosschecks.txt";
            //const string textFile = "englishWords.txt";

            const string binFile = "boingDAWG.bin";
            //const string binFile = "englishDawg.bin";

            string        fileContents = File.ReadAllText(textFile);
            List <string> boingWords   = Regex.Matches(fileContents, "\\w+").Select(m => m.Value).ToList();

            DawgBuilder <bool> dawgBuilder = new();

            foreach (string word in boingWords)
            {
                dawgBuilder.Insert(word, true);
            }

            Dawg <bool> dawg = dawgBuilder.BuildDawg(); // Computer is working.  Please wait ...

            using (FileStream file = File.Create(binFile)) dawg.SaveTo(file);

            //Now read the file back in and check if a particular word is in the dictionary:
            Dawg <bool> dawg2 = Dawg <bool> .Load(File.Open(binFile, FileMode.Open));
        }
Example #2
0
        private void _rebuildDAWG(string path)
        {
            MRDFileReader mrdFile = new MRDFileReader(_gramtab);

            mrdFile.LoadMrd(Path.Combine(_workDir, @"Dicts\morphs.mrd"));
            _dawg = CreateDAWG(mrdFile);
            _dawg.SaveTo(File.Create(path), WritePayload);
        }
Example #3
0
        private static Dawg <bool> SaveToFileAndLoadBack(Dawg <bool> dawg)
        {
            string binFilePath = Path.GetTempFileName();

            using (var file = File.OpenWrite(binFilePath))
                dawg.SaveTo(file);

            var rehydrated = Dawg <bool> .Load(File.OpenRead(binFilePath));

            return(rehydrated);
        }
 /// <summary>
 /// Сохраняет модель в заданный поток.
 /// </summary>
 /// <param name="fs">Поток.</param>
 public void SaveTo(System.IO.Stream fs)
 {
     dawg = builder.BuildDawg();
     dawg.SaveTo(fs);
 }
Example #5
0
 public void Serialize(Stream stream)
 {
     using var gzipStream = new GZipStream(stream, CompressionLevel.Optimal, leaveOpen: true);
     Serializer.SerializeWithLengthPrefix(gzipStream, allDocuments, PrefixStyle.Base128);
     dawg.SaveTo(gzipStream, writePayload: SerializePayload);
 }