Пример #1
0
 public void CreateIndexes()
 {
     if (id_index == null)
     {
         id_index = new FreeIndex(path + "twi_id_index", cell_table.Root, id_field);
     }
     if (name_index == null)
     {
         name_index = new FreeIndex(path + "twi_name_index", cell_table.Root, name_field);
     }
     id_index.Load();
     name_index.Load();
 }
Пример #2
0
 public void MakeIndexes()
 {
     id_index.Load();
     name_index.Load(ent =>
                     ((object[])ent.Field(3).Get())
                     .Cast <object[]>()
                     .Where(r3 => (string)r3[0] == ONames.p_name)
                     .Select(r3 => new object[] { r3[1], ent.offset }).ToArray());
     inverse_index.Load(ent =>
                        ((object[])ent.Field(4).Get())
                        .Cast <object[]>()
                        .Select(r2 => new object[] { r2[1], ent.offset }).ToArray());
 }
Пример #3
0
 public void Load(Func <PaEntry, object[][]> genPairs)
 {
     intern_cell.Clear();
     intern_cell.Fill(new object[0]);
     foreach (PaEntry rec in table.Elements())
     {
         object[][] pairs = genPairs(rec);
         foreach (object[] pair in pairs)
         {
             intern_cell.Root.AppendElement(new object[] { false, pair[0], pair[1] });
         }
     }
     intern_cell.Flush();
     key_index.Load();
 }
Пример #4
0
        public void Load(Func <PaEntry, object[][]> genTriples)
        {
            intern_cell.Clear();
            intern_cell.Fill(new object[0]);
            foreach (PaEntry rec in table.Elements())
            {
                object[][] triples = genTriples(rec);
                foreach (object[] v3 in triples)
                {
                    intern_cell.Root.AppendElement(new object[] { false, v3[0], v3[1], v3[2], v3[3] });
                }
            }
            intern_cell.Flush();
            key_index.Load();
            key_index.AdditionalIndex(3); // дополнительный индекс - предикат

            //Проставим начала групп обратных ссылок и длину групп
            long    inv_beg = Int64.MinValue, inv_count = Int64.MinValue; // offset начала серии в intern_cell и длина серии
            PaEntry tab_el_ent = table.Element(0);
            long    key_offset = Int64.MaxValue;                          // будем фиксировать серию по совпадению оффсета с полем цели

            foreach (PaEntry ent in key_index.GetAll())
            {
                object[] v5      = (object[])ent.Get();
                long     tab_pnt = (long)v5[4]; // указатель на таблицу
                if (tab_pnt != key_offset)
                {                               // заканчивается серия, начинается новая серия
                    if (key_offset != Int64.MaxValue)
                    {                           // надо закончить предыдущую серию
                        tab_el_ent.offset = key_offset;
                        tab_el_ent.Field(5).Set(inv_beg);
                        tab_el_ent.Field(6).Set(inv_count);
                    }
                    // установим новую серию
                    key_offset = tab_pnt;
                    inv_beg    = ent.offset;
                    inv_count  = 0;
                }
                inv_count++;
            }
            // закончим последнюю серию
            tab_el_ent.offset = key_offset;
            tab_el_ent.Field(5).Set(inv_beg);
            tab_el_ent.Field(6).Set(inv_count);
        }
 public void MakeIndexes()
 {
     id_index.Load();
     name_index.Load(ent =>
                     ((object[])ent.Field(3).Get())
                     .Cast <object[]>()
                     .Where(r3 => (string)r3[0] == ONames.p_name)
                     .Select(r3 => new object[] { ent.offset, r3[1] }).ToArray());
     inverse_index.Load(ent =>
                        ((object[])ent.Field(4).Get())
                        .Cast <object[]>()
                        .Select(r2 => new object[]
     {
         ent.offset,
         r2[1],
         r2[0],
         id_index.GetById((string)r2[1]).Offset
     }).ToArray());     // надо вычисление второго поля сделать экономнее
 }
Пример #6
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Start");
            string path = @"..\..\..\Databases\";

            string[] ids = new[]
            {
                "svet_100616111408_10844",
                "pavl_100531115859_2020",
                "piu_200809051791",
                "pavl_100531115859_6952",
                "svet_100616111408_10864",
                "w20090506_svetlana_5727",
                "piu_200809051742",
                "p0013313",
                "p0011098",
                "svet_100616111408_14354"
            };
            XElement formats             = XElement.Load(path + "ApplicationProfile.xml").Element("formats");
            bool     toload              = true;
            XElement db                  = null;
            IEnumerable <XElement> query = Enumerable.Empty <XElement>();

            if (toload)
            {
                //db = XElement.Load(@"D:\home\dev2012\tm3.xml");
                db    = XElement.Load(@"..\..\..\Databases\0001.xml");
                query = db.Elements()
                        .Where(el => el.Attribute(ONames.rdfabout) != null && el.Element(ONames.tag_name) != null);
            }


            DateTime tt0 = DateTime.Now;

            string variant = "rdfengineflex";

            //string variant = "rdfengine";
            //string variant = "bigintset";
            //string variant = "freeindex";
            //string variant = "semiindex";
            if (variant == "sql")
            {
                var test = new SQLTest(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\home\FactographDatabases\test20131025.mdf;Integrated Security=True;Connect Timeout=30");
                test.PrepareToLoad();
                Console.WriteLine("PrepareToLoad ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                test.Load(query);
                Console.WriteLine("Load ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                test.Index1();
                Console.WriteLine("Index1 ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;


                test.SelectById("w20070417_5_8436");
                Console.WriteLine("Первый Select ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                foreach (string id in ids)
                {
                    test.SelectById(id);
                }
                Console.WriteLine("SelectById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                //test.SelectById("pavl_100531115859_6952");
                //Console.WriteLine("SelectById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                test.Count();
            }
            else if (variant == "polartest")
            {
                var test2 = new PolarTest(@"..\..\..\Databases\");
                //test2.Load(query);
                //Console.WriteLine("Load ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                //test2.CreateIndex();
                //Console.WriteLine("Index ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;

                test2.SelectById("w20070417_5_8436");
                Console.WriteLine("Index ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                foreach (string id in ids)
                {
                    test2.SelectById(id);
                }
                Console.WriteLine("SelectById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
            }
            else if (variant == "semiindex")
            {
                Console.WriteLine("SemiIndex Strat. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                SITest sit = new SITest(path);
                sit.Load(query);
                Console.WriteLine("Load ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                var rec = sit.GetById("w20070417_5_8436");
                Console.WriteLine("GetById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                //Console.WriteLine(rec.Type.Interpret(rec.Value));
                foreach (string id in ids)
                {
                    sit.GetById(id);
                }
                Console.WriteLine("10 GetById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                sit.Search("марчук");
                Console.WriteLine("Search ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
            }
            else if (variant == "freeindex")
            {
                Console.WriteLine("FreeIndex Start. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                FITest fit = new FITest(path);
                fit.Load(query);
                Console.WriteLine("Load ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                fit.CreateIndexes();
                Console.WriteLine("Indexes ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                var rec = fit.GetById("w20070417_5_8436");
                Console.WriteLine("GetById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                //Console.WriteLine(rec.Type.Interpret(rec.Value));
                foreach (string id in ids)
                {
                    fit.GetById(id);
                }
                Console.WriteLine("10 GetById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                foreach (PValue v in fit.Search("марчук"))
                {
                    Console.WriteLine(v.Type.Interpret(v.Value));
                }
                Console.WriteLine("Search ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
            }
            else if (variant == "bigintset")
            {
                Console.WriteLine("BigIntSet Start. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                PaCell iset_cell = new PaCell(new PTypeSequence(new PTypeRecord(
                                                                    new NamedType("deleted", new PType(PTypeEnumeration.boolean)),
                                                                    new NamedType("value", new PType(PTypeEnumeration.integer)))), path + "intset.pac", false);

                // Загрузка таблицы
                System.Random rnd = new Random();
                iset_cell.Clear();
                iset_cell.Fill(new object[0]);
                for (int i = 0; i < 1000000; i++)
                {
                    iset_cell.Root.AppendElement(new object[] { false, rnd.Next() });
                }
                int special = 7777777; // Это для поиска
                for (int i = 0; i < 11; i++)
                {
                    iset_cell.Root.AppendElement(new object[] { false, special + i * 10000000 });
                }
                iset_cell.Flush();
                Console.WriteLine("Load ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;

                // подключение индекса
                FreeIndex iset_index = new FreeIndex(path + "intset_index", iset_cell.Root, 1);

                // Создание индекса
                iset_index.Load();
                Console.WriteLine("Index ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;

                // Поиск
                int sample = 7777777;
                Find(iset_index, sample);
                Console.WriteLine("Search ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                for (int i = 1; i < 11; i++)
                {
                    Find(iset_index, sample + i * 10000000);
                }
                Console.WriteLine("10 Search ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
            }
            else if (variant == "rdfengine")
            {
                Console.WriteLine("RdfEngine start");
                PolarBasedEngineSpecial engine = new PolarBasedEngineSpecial(path);

                //toload = false;
                if (toload)
                {
                    engine.Load(db);
                    Console.WriteLine("Load ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                    engine.MakeIndexes();
                    Console.WriteLine("Indexes ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                }
                tt0 = DateTime.Now;
                var val = engine.GetById("w20070417_5_8436");
                Console.WriteLine(val.Type.Interpret(val.Value));
                Console.WriteLine("GetById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                foreach (string id in ids)
                {
                    engine.GetById(id);
                }
                Console.WriteLine("10 GetById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                foreach (XElement res in engine.SearchByName("Марчук"))
                {
                    //Console.WriteLine(res.ToString());
                }
                Console.WriteLine("Search ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                //engine.GetInverse("w20070417_5_8436");
                engine.GetById("w20070417_5_8436");
                Console.WriteLine("GetById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                //var xres = engine.GetItemByIdBasic("w20070417_5_8436", true); // Это я
                var xres = engine.GetItemByIdBasic("w20071030_1_20927", true); // Это Андрей
                Console.WriteLine("GetItemByIdBasic ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                Console.WriteLine(xres.ToString());

                XElement format = formats.Elements("record").First(r => r.Attribute("type").Value == "http://fogid.net/o/person");
                xres = engine.GetItemById("w20070417_5_8436", format);
                Console.WriteLine("GetItemById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                Console.WriteLine(xres.Elements().Count());
                foreach (string id in ids)
                {
                    engine.GetItemById(id, format);
                }
                Console.WriteLine("10 GetItemById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
            }
            else if (variant == "rdfengineflex")
            {
                Console.WriteLine("RdfEngineFlex start");
                tt0 = DateTime.Now;
                PolarBasedEngineFlex engine = new PolarBasedEngineFlex(path);
                Console.WriteLine("Init ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;

                toload = false;
                if (toload)
                {
                    engine.Load(db);
                    Console.WriteLine("Load ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                    engine.MakeIndexes();
                    Console.WriteLine("Indexes ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                }
                var val = engine.GetById("w20070417_5_8436");
                //Console.WriteLine(val.Type.Interpret(val.Value));
                Console.WriteLine("GetById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                foreach (string id in ids)
                {
                    engine.GetById(id);
                }
                Console.WriteLine("10 GetById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                foreach (XElement res in engine.SearchByName("Марчук"))
                {
                    //Console.WriteLine(res.ToString());
                }
                Console.WriteLine("Search ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;

                //engine.GetInverse("w20070417_5_8436");
                //engine.GetInverse("w20071030_1_20927");
                //Console.WriteLine("GetInverse ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;

                //var xres = engine.GetItemByIdBasic("w20070417_5_8436", true); // Это я
                var xres = engine.GetItemByIdBasic("piu_200809051508", true); // Это Г.И.
                //var xres = engine.GetItemByIdBasic("w20071030_1_20927", true); // Это Андрей
                Console.WriteLine("GetItemByIdBasic ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                //Console.WriteLine(xres.ToString());

                XElement format = formats.Elements("record").First(r => r.Attribute("type").Value == "http://fogid.net/o/person");
                tt0  = DateTime.Now;
                xres = engine.GetItemById("w20070417_5_8436", format);
                //xres = engine.GetItemById("piu_200809051508", format);
                Console.WriteLine("GetItemById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                //Console.WriteLine(xres.ToString());
                //Console.WriteLine(xres.Descendants().Count());
                xres.Save(path + "look.xml");
                foreach (string id in ids)
                {
                    engine.GetItemById(id, format);
                }
                Console.WriteLine("10 GetItemById ok. Duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
                //Console.ReadKey();
            }
        }