Пример #1
0
        public static Dawg <FormInterpretations> CreateDAWG(MRDFileReader mrdFile)
        {
            DateTime start = DateTime.Now;

            Console.WriteLine("Inserting forms in DAWG... Please wait...");
            DawgSharp.DawgBuilder <FormInterpretations> dawgBuilder = new DawgBuilder <FormInterpretations>();
            UInt64 cntForms = 0;

            foreach (WordForm f in mrdFile.AllForms)
            {
                string word = f.Prefix + f.Flexia.Prefix + f.Lemma.Base + f.Flexia.Flexion;
                FormInterpretations payload = null;
                dawgBuilder.TryGetValue(word, out payload);
                if (payload == null)
                {
                    payload = new FormInterpretations();
                    dawgBuilder.Insert(word, payload);
                }
                payload.Add(f);
                cntForms++;
            }
            Console.WriteLine("All forms count: " + cntForms);
            Console.WriteLine("Building... please wait...");
            Dawg <FormInterpretations> dawg = dawgBuilder.BuildDawg();

            Console.WriteLine("DAWG create time: {0}", DateTime.Now - start);
            return(dawg);
        }
Пример #2
0
        public void EmptyKey()
        {
            var db = new DawgBuilder <int>();

            Assert.False(db.TryGetValue("", out int n));
            Assert.AreEqual(0, n);
        }
Пример #3
0
        private static void Increment(DawgBuilder <int> db, string key)
        {
            int n;

            db.TryGetValue(key, out n);
            db.Insert(key, n + 1);
        }
Пример #4
0
        public void EmptyKey()
        {
            var db = new DawgBuilder<int>();

            int n;
            Assert.AreEqual(true, db.TryGetValue("", out n));
            Assert.AreEqual(0, n);
        }
Пример #5
0
        public void TryGetValueOnPartialKey()
        {
            var builder = new DawgBuilder <bool>();

            builder.Insert("dates", true);
            bool b = builder.TryGetValue("date", out var v);

            Assert.False(v);
            Assert.False(b);
        }
Пример #6
0
        /// <summary>
        /// Добавляет новую лексему к модели.
        /// </summary>
        /// <param name="lexem">Лексема.</param>
        public void AddLexem(WordForm lexem)
        {
            ulong tagOut = (ulong)Tag.NoWord;
            ulong tag    = (ulong)lexem.Tag;

            if (builder.TryGetValue(lexem.Word, out tagOut))
            {
                tag |= tagOut;
            }
            builder.Insert(lexem.Word, tag);
        }
Пример #7
0
        public void TryGetValueUnexpectedBehaviour()
        {
            var builder = new DawgBuilder <string>();

            builder.Insert("dates", "dates");

            bool b = builder.TryGetValue("date", out var v);

            Assert.True(b);
            Assert.Null(v);
        }
Пример #8
0
        public void IncrementValue()
        {
            var db = new DawgBuilder<int>();

            Increment(db, "test");
            Increment(db, "test");
            Increment(db, "test");

            int n;
            Assert.AreEqual(true, db.TryGetValue("test", out n));
            Assert.AreEqual(3, n);
        }
Пример #9
0
        public void IncrementValue()
        {
            var db = new DawgBuilder <int>();

            Increment(db, "test");
            Increment(db, "test");
            Increment(db, "test");

            int n;

            Assert.AreEqual(true, db.TryGetValue("test", out n));
            Assert.AreEqual(3, n);
        }
Пример #10
0
        public void IndexTerm(DocumentId id, string word, int position)
        {
            builder.TryGetValue(word, out var blockList);

            if (blockList == null)
            {
                blockList = new RangePostingsList();
                builder.Insert(word, blockList);
            }

            blockList.Add(id);
            allDocuments.Add(id);
        }
Пример #11
0
 private static void Increment(DawgBuilder<int> db, string key)
 {
     int n;
     db.TryGetValue(key, out n);
     db.Insert(key, n + 1);
 }