Esempio n. 1
0
        public static void Init()
        {
            Initialized = true;

            schemas.BeginInit();
            items.Clear();

            var assembly     = Assembly.GetExecutingAssembly();
            var resourceName = "LingvoNET.Dict.сущ.bin";

            using (var stream = assembly.GetManifestResourceStream(resourceName))
                using (var zip = new GZipStream(stream, CompressionMode.Decompress))
                    using (var sr = new StreamReader(zip, Encoding.GetEncoding(1251)))
                        while (sr.Peek() >= 0)
                        {
                            var line = sr.ReadLine();
                            if (!string.IsNullOrEmpty(line))
                            {
                                items.Add(ParseNoun(line));
                            }
                        }

            //additional custom words
            if (CustomWordsNeeded != null)
            {
                var ea = new CustomWordsNeededEventArgs()
                {
                    CustomWords = new List <string>()
                };
                CustomWordsNeeded(null, ea);

                var comparer = new StringReverseComparer <NounRaw>();

                foreach (var line in ea.CustomWords)
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        var v = ParseNoun(line);

                        var i = items.BinarySearch(v, comparer);
                        if (i >= 0 && i < items.Count)
                        {
                            items[i] = v;
                        }
                        else
                        {
                            i = -i - 1;
                            items.Insert(i, v);
                        }
                    }
                }
            }

            schemas.EndInit();
        }
Esempio n. 2
0
 public int CompareTo(WordForm other)
 {
     return(StringReverseComparer <string> .CompareStrings(Form, other.Form));
 }
Esempio n. 3
0
        public static void Init()
        {
            Initialized = true;

            schemas.BeginInit();
            items.Clear();

            var assembly     = Assembly.GetExecutingAssembly();
            var resourceName = "LingvoNET.Dict.глаголы";

            using (var stream = assembly.GetManifestResourceStream(resourceName))
                using (var sr = new StreamReader(stream))
                    while (sr.Peek() >= 0)
                    {
                        var line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            items.Add(ParseVerb(line));
                        }
                    }

            //additional custom words
            if (CustomWordsNeeded != null)
            {
                var ea = new CustomWordsNeededEventArgs()
                {
                    CustomWords = new List <string>()
                };
                CustomWordsNeeded(null, ea);

                var comparer = new StringReverseComparer <VerbRaw>();

                foreach (var line in ea.CustomWords)
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        var v = ParseVerb(line);

                        var i = items.BinarySearch(v, comparer);
                        if (i >= 0 && i < items.Count)
                        {
                            items[i] = v;
                        }
                        else
                        {
                            i = -i - 1;
                            items.Insert(i, v);
                        }
                    }
                }
            }

            schemas.EndInit();

            //загружаем пары несоверш-соверш
            resourceName = "LingvoNET.Dict.ImperfectPerfect";

            using (var stream = assembly.GetManifestResourceStream(resourceName))
                using (var sr = new StreamReader(stream))
                    while (sr.Peek() >= 0)
                    {
                        var line = sr.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            var parts = line.Split('\t');
                            imperfectToPerfect.Add(new Pair {
                                Item1 = parts[0], Item2 = parts[1]
                            });
                        }
                    }

            //
            ToBe = FindOne("быть");
        }