//// Идея хорошая, но надо менять схему реализации //private GroupedEntities getable; //private Dictionary<int, object[]> geHash; public TripleStoreInt(string path) { this.path = path; InitTypes(); otriples = new PaCell(tp_otriple_seq, path + "otriples.pac", false); otriples_op = new PaCell(tp_otriple_seq, path + "otriples_op.pac", false); dtriples = new PaCell(tp_dtriple_seq, path + "dtriples.pac", false); dtriples_sp = new PaCell(tp_dtriple_spf, path + "dtriples_spf.pac", false); scale = new ScaleCell(path); if (!otriples.IsEmpty) { OpenCreateIndexes(); } ewt = new EntitiesWideTable(path, new DiapasonScanner <int>[] { new DiapasonScanner <int>(otriples, ent => (int)((object[])ent.Get())[0]), new DiapasonScanner <int>(otriples_op, ent => (int)((object[])ent.Get())[2]), new DiapasonScanner <int>(dtriples_sp, ent => (int)((object[])ent.Get())[0]) }); ewtHash = new EntitiesMemoryHashTable(ewt); ewtHash.Load(); //getable = new GroupedEntities(path); // Это хорошая идея, но нужно менять схему реализации //getable.CheckGroupedEntities(); //geHash = getable.GroupedEntitiesHash(); }
public void LoadTurtle(string filepath) { DateTime tt0 = DateTime.Now; Load(filepath); Console.WriteLine("Load ok. Duration={0} sec.", (DateTime.Now - tt0).Ticks / 10000000L); tt0 = DateTime.Now; PrepareArrays(); Console.WriteLine("PrepareArrays ok. Duration={0} sec.", (DateTime.Now - tt0).Ticks / 10000000L); tt0 = DateTime.Now; // Упорядочивание otriples по s-p-o SPOComparer spo_compare = new SPOComparer(); otriples.Root.SortByKey <SubjPredObjInt>(rec => new SubjPredObjInt(rec), spo_compare); Console.WriteLine("otriples.Root.Sort ok. Duration={0} sec.", (DateTime.Now - tt0).Ticks / 10000000L); tt0 = DateTime.Now; SPComparer sp_compare = new SPComparer(); // Упорядочивание otriples_op по o-p otriples_op.Root.SortByKey <SubjPredInt>(rec => { object[] r = (object[])rec; return(new SubjPredInt() { pred = (int)r[1], subj = (int)r[2] }); }, sp_compare); Console.WriteLine("otriples_op Sort ok. Duration={0} sec.", (DateTime.Now - tt0).Ticks / 10000000L); tt0 = DateTime.Now; // Упорядочивание dtriples_sp по s-p dtriples_sp.Root.SortByKey(rec => { object[] r = (object[])rec; return(new SubjPredInt() { pred = (int)r[1], subj = (int)r[0] }); }, sp_compare); Console.WriteLine("dtriples_sp.Root.Sort ok. Duration={0} sec.", (DateTime.Now - tt0).Ticks / 10000000L); tt0 = DateTime.Now; Scale.WriteScale(otriples); Console.WriteLine("CreateScale ok. Duration={0} sec.", (DateTime.Now - tt0).Ticks / 10000000L); tt0 = DateTime.Now; // Создание "широкой" таблицы ewt.Load(); Console.WriteLine("ewt.Load() ok. Duration={0} sec.", (DateTime.Now - tt0).Ticks / 10000000L); tt0 = DateTime.Now; // Вычисление кеша. Это можно не делать, все равно - кеш в оперативной памяти ewtHash.Load(); Console.WriteLine("ewtHash.Load() ok. Duration={0} sec.", (DateTime.Now - tt0).Ticks / 10000000L); tt0 = DateTime.Now; }
private static void TestEWT(TripleStoreInt ts) { DateTime tt0 = DateTime.Now; EntitiesMemoryHashTable hashTable = new EntitiesMemoryHashTable(ts.ewt); hashTable.Load(); // Проверка построенной ewt Console.WriteLine("n_entities={0}", ts.ewt.EWTable.Root.Count()); bool notfirst = false; int code = Int32.MinValue; long cnt_otriples = 0; foreach (object[] row in ts.ewt.EWTable.Root.ElementValues()) { int cd = (int)row[0]; // Проверка на возрастание значений кода if (notfirst && cd <= code) { Console.WriteLine("ERROR!"); } code = cd; notfirst = true; // Проверка на то, что коды в диапазонах индексов совпадают с cd. Подсчитывается количество object[] odia = (object[])row[1]; long start = (long)odia[0]; long number = (long)odia[1]; foreach (object[] tri in ts.otriples.Root.ElementValues(start, number)) { int c = (int)tri[0]; if (c != cd) { Console.WriteLine("ERROR2!"); } } cnt_otriples += number; } if (cnt_otriples != ts.otriples.Root.Count()) { Console.WriteLine("ERROR3! cnt_triples={0} otriples.Root.Count()={1}", cnt_otriples, ts.otriples.Root.Count()); } Console.WriteLine("Проверка ewt OK. duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now; }
public void LoadTurtle(string filepath) { otriples.Clear(); otriples.Fill(new object[0]); dtriples.Clear(); dtriples.Fill(new object[0]); // Только для специальных целей: TurtleInt.sarr = new List <string>(); int i = 0; //Entity e = new Entity(); foreach (var triple in TurtleInt.LoadGraph(filepath)) { if (i % 10000 == 0) { Console.Write("{0} ", i / 10000); } i++; if (triple is OTripleInt) { var tr = (OTripleInt)triple; otriples.Root.AppendElement(new object[] { tr.subject, tr.predicate, tr.obj }); } else { var tr = (DTripleInt)triple; Literal lit = tr.data; object[] da; switch (lit.vid) { case LiteralVidEnumeration.integer: da = new object[] { 1, lit.Value }; break; case LiteralVidEnumeration.date: da = new object[] { 3, lit.Value }; break; case LiteralVidEnumeration.boolean: da = new object[] { 4, lit.Value }; break; case LiteralVidEnumeration.text: { Text t = (Text)lit.Value; da = new object[] { 2, new object[] { t.Value, t.Lang } }; } break; case LiteralVidEnumeration.typedObject: { TypedObject t = (TypedObject)lit.Value; da = new object[] { 5, new object[] { t.Value, t.Type } }; } break; default: da = new object[] { 0, null }; break; } dtriples.Root.AppendElement(new object[] { tr.subject, tr.predicate, da }); } } Console.WriteLine(); otriples.Flush(); dtriples.Flush(); // Только для специальных целей: bool specialpurposes = false; if (specialpurposes) { int ii = 0; foreach (string s in TurtleInt.sarr) { if (ii % 20 == 0) { Console.WriteLine("\"{0}\", ", s); } ii++; } Console.WriteLine("sarr.Count() = {0}", TurtleInt.sarr.Count()); } SPOComparer spo_compare = new SPOComparer(); SPComparer sp_compare = new SPComparer(); // Создание и упорядочивание дополнительных структур otriples_op.Clear(); otriples_op.Fill(new object[0]); foreach (object v in otriples.Root.ElementValues()) { otriples_op.Root.AppendElement(v); } otriples_op.Flush(); dtriples_sp.Clear(); dtriples_sp.Fill(new object[0]); foreach (PaEntry entry in dtriples.Root.Elements()) { int s = (int)entry.Field(0).Get(); int p = (int)entry.Field(1).Get(); dtriples_sp.Root.AppendElement(new object[] { s, p, entry.offset }); } dtriples_sp.Flush(); // Упорядочивание otriples по s-p-o otriples.Root.SortByKey <SubjPredObjInt>(rec => new SubjPredObjInt(rec), spo_compare); // Упорядочивание otriples_op по o-p otriples_op.Root.SortByKey <SubjPredInt>(rec => { object[] r = (object[])rec; return(new SubjPredInt() { pred = (int)r[1], subj = (int)r[2] }); }, sp_compare); // Упорядочивание dtriples_sp по s-p dtriples_sp.Root.SortByKey(rec => { object[] r = (object[])rec; return(new SubjPredInt() { pred = (int)r[1], subj = (int)r[0] }); }, sp_compare); // Индексирование if (spo_o_index == null) { OpenCreateIndexes(); } //spo_o_index.Load(spo_compare); //sp_d_index.Load(sp_compare); //op_o_index.Load(sp_compare); if (filescale) { // Создание шкалы (Надо переделать) CreateScale(); //ShowScale(); oscale.Clear(); oscale.Fill(new object[0]); foreach (int v in scale.Values()) { oscale.Root.AppendElement(v); } oscale.Flush(); CalculateRange(); // Наверное, range считается в CreateScale() } ewt.Load(); ewtHash.Load(); //getable.ConstructGroupedEntities(new DiapLinksScanner[] { // new DiapLinksScanner(otriples, 0), // new DiapLinksScanner(otriples_op, 2), // new DiapLinksScanner(dtriples_sp, 0)}); }