private static void Reload(AdapterVirtuoso store, int npersons) { Polar.Data.Phototeka generator = new Polar.Data.Phototeka(npersons, 777777); Func<XElement,IEnumerable<Tuple<string, string, ObjectVariants>>> f= (XElement ele) => { string id = ele.Name + ele.Attribute("id").Value; var seq = Enumerable.Repeat(Tuple.Create(id, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", (ObjectVariants)new OV_iri(ele.Name.LocalName)), 1) .Concat(ele.Elements().Select(subele => { XAttribute ratt = subele.Attribute("ref"); Tuple<string, string, ObjectVariants> triple = null; if (ratt != null) { string r = (subele.Name == "reflected" ? "person" : "photo_doc") + ratt.Value; triple = Tuple.Create(id, subele.Name.LocalName, (ObjectVariants)new OV_iri(r)); } else { string value = subele.Value; // Нужны языки и другие варианты! bool possiblenumber = !string.IsNullOrEmpty(value); if (possiblenumber) { char c = value[0]; if (char.IsDigit(c) || c == '-') { } else possiblenumber = false; } triple = Tuple.Create(id, subele.Name.LocalName,possiblenumber ? (ObjectVariants)new OV_int(int.Parse(value)) : (ObjectVariants)new OV_string(value)); } return triple; })); return seq; }; store.Load(generator.Generate1of3().SelectMany(f).Concat(generator.Generate2of3().SelectMany(f)).Concat(generator.Generate3of3().SelectMany(f))); }
public static void Main() { Console.WriteLine("Start TestGenerator"); string path = ProjectDirectory.GetProjectDirectory(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); TextWriter res = new StreamWriter(new FileStream(path + "res.txt", FileMode.Append, FileAccess.Write)); XElement xcnf = XElement.Load(path + "tests.xml"); XElement xcommon = XElement.Load(path + "../common.xml"); xcommon.Add(xcnf); Random rnd; //MySQL db = new MySQL("server=localhost;uid=root;port=3306;password=fetnaggi;"); //SQLite db = new SQLite("Data Source=" + path + "../databases/test.db3"); SQLdatabase db = new SQLdatabase(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Users\Marchuk\Documents\TestPhototeka.mdf;Integrated Security=True;Connect Timeout=30"); string dbname = db.GetType().Name; foreach (XElement xprobe in xcnf.Elements()) { ProbeFrame probe = new ProbeFrame(xprobe.AncestorsAndSelf().Attributes()); int npersons = (int)probe.siz; if (probe.sol == dbname + "_load") { db.PrepareToLoad(); sw.Restart(); Polar.Data.Phototeka generator = new Polar.Data.Phototeka(npersons, 777777); db.LoadElementFlow(generator.Generate1of3()); db.LoadElementFlow(generator.Generate2of3()); db.LoadElementFlow(generator.Generate3of3()); sw.Stop(); probe.lod = sw.ElapsedMilliseconds; sw.Restart(); db.MakeIndexes(); sw.Stop(); probe.ndx = sw.ElapsedMilliseconds; Console.WriteLine("Load ok."); // 10000: 14.9 сек. res.WriteLine(probe.ToCSV()); } else if (probe.sol == dbname + "_SelectById") { rnd = new Random(777777777); sw.Restart(); long sum = 0; for (int i = 0; i < probe.nte; i++) { int id = rnd.Next(0, (int)probe.siz - 1); sum += (int)(db.GetById(id, "person")[2]); } sw.Stop(); probe.tim = sw.ElapsedMilliseconds; probe.sum = sum; Console.WriteLine("SelectById ok. Duration={0}", sw.ElapsedMilliseconds); // 7 res.WriteLine(probe.ToCSV()); } else if (probe.sol == dbname + "_SearchByName") { rnd = new Random(777777777); sw.Restart(); long sum = 0; for (int i = 0; i < probe.nte; i++) { int id = rnd.Next(0, (int)probe.siz - 1); sum += db.SearchByName("Pupkin" + id / 10, "person").Count(); } sw.Stop(); probe.tim = sw.ElapsedMilliseconds; probe.sum = sum; Console.WriteLine("SearchByName ok. Duration={0}", sw.ElapsedMilliseconds); // 7 res.WriteLine(probe.ToCSV()); } else if (probe.sol == dbname + "_GetRelationByPerson") { rnd = new Random(777777777); sw.Restart(); long sum = 0; for (int i = 0; i < probe.nte; i++) { int id = rnd.Next(0, (int)probe.siz - 1); sum += db.GetPhotosOfPersonUsingRelation(id).Count(); } sw.Stop(); probe.tim = sw.ElapsedMilliseconds; probe.sum = sum; Console.WriteLine("GetRelationByPerson ok. Duration={0}", sw.ElapsedMilliseconds); // 7 res.WriteLine(probe.ToCSV()); } else if (probe.sol == "unused") { } } res.Close(); }
public static void Main() { Console.WriteLine("Start P06_Virtuoso"); string path = ProjectDirectory.GetProjectDirectory(); TextWriter res = new StreamWriter(new FileStream(path + "res.txt", FileMode.Append, FileAccess.Write)); XElement xcnf = XElement.Load(path + "tests.xml"); XElement xcommon = XElement.Load(path + "../common.xml"); xcommon.Add(xcnf); Random rnd; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); AdapterVirtuosoSimple engine = new AdapterVirtuosoSimple("HOST=localhost:1550;UID=dba;PWD=dba;Charset=UTF-8;Connection Timeout=500", "g"); foreach (XElement xprobe in xcnf.Elements()) { ProbeFrame probe = new ProbeFrame(xprobe.AncestorsAndSelf().Attributes()); int npersons = (int)probe.siz; if (probe.sol == "virtuoso_load") { engine.PrepareToLoad(); Polar.Data.Phototeka generator = new Polar.Data.Phototeka(npersons, 777777); sw.Restart(); engine.Load(generator.Generate1of3()); engine.Load(generator.Generate2of3()); engine.Load(generator.Generate3of3()); sw.Stop(); Console.WriteLine("Load ok. Duration={0}", sw.ElapsedMilliseconds); // 10000: 14.9 сек. probe.ndx = sw.ElapsedMilliseconds; res.WriteLine(probe.ToCSV()); } else if (probe.sol == "virtuoso_SelectById") { rnd = new Random(777777777); long sum = 0; sw.Restart(); //var rcommand = engine.RunStart(); for (int i = 0; i < probe.nte; i++) { string sid = "person" + rnd.Next(0, (int)probe.siz - 1); var v = engine.Query("sparql select * { <" + sid + "> ?p ?o }") .First(po => po[0].ToString() == "age") .ToArray(); // .First(po => (string)po[0] == "age"); string s = v[1].ToString(); sum += Int32.Parse(s); } //engine.RunStop(rcommand); sw.Stop(); probe.tim = sw.ElapsedMilliseconds; probe.sum = sum; Console.WriteLine("SelectById ok. Duration={0}", sw.ElapsedMilliseconds); // 7 res.WriteLine(probe.ToCSV()); } else if (probe.sol == "virtuoso_SearchByName") { rnd = new Random(777777777); sw.Restart(); long sum = 0; for (int i = 0; i < probe.nte; i++) { var intId = rnd.Next(0, (int)probe.siz - 1); string namePrefix = "Pupkin" + intId / 10; //sum += (int)engine.Query(string.Format("sparql select ?s {{ ?s <name> ?o . Filter(strStarts(str(?o), \"{0}\")) }}", namePrefix)).Count(); var enumerable = engine.Query(string.Format("sparql select ?s {{ ?s <name> ?o . Filter(strStarts(str(?o), \"{0}\")) }}", namePrefix)); //foreach (var objectse in enumerable) //{ // foreach (var o in objectse) // { // Console.WriteLine(o); // } // Console.WriteLine(); //} sum += (int)enumerable.Count(); } sw.Stop(); probe.tim = sw.ElapsedMilliseconds; probe.sum = sum; Console.WriteLine("SearchByName ok. Duration={0}", sw.ElapsedMilliseconds); // 7 res.WriteLine(probe.ToCSV()); } else if (probe.sol == "virtuoso_GetRelationByPerson") { rnd = new Random(777777777); sw.Restart(); long sum = 0; for (int i = 0; i < probe.nte; i++) { string persId = "person" + rnd.Next(0, (int)probe.siz - 1); sum += engine.Query( "sparql select ?phname {?refl <reflected> <" + persId + "> . ?refl <in_doc> ?ph . ?ph <name> ?phname}") //"sparql select ?refl {?refl <reflected> <"+persId+"> . }") .Count(); } sw.Stop(); probe.tim = sw.ElapsedMilliseconds; probe.sum = sum; Console.WriteLine("GetRelationByPerson ok. Duration={0}", sw.ElapsedMilliseconds); // 7 res.WriteLine(probe.ToCSV()); } else if (probe.sol == "unused") { } } res.Close(); }
public static void Main() { Console.WriteLine("Start P05_Phototeka3TabsInt"); //string path = ProjectDirectory.GetProjectDirectory(); //if (!Directory.Exists(path + "../Databases/P05_Phototeka3TabsInt")) Directory.CreateDirectory(path + "../Databases/P05_Phototeka3TabsInt"); string path = ""; TextWriter res = new StreamWriter(new FileStream(path + "res.txt", FileMode.Append, FileAccess.Write)); //XElement xcnf = XElement.Load(path + "tests.xml"); //XElement xcommon = XElement.Load(path + "../common.xml"); //xcommon.Add(xcnf); Random rnd = new Random(777777777); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); string dbpath = path; // + "../Databases/P05_Phototeka3TabsInt/"; int npersons = 40000; P05_Phototeka3TabsInt.Stan3TabsInt tabs = new P05_Phototeka3TabsInt.Stan3TabsInt(dbpath); sw.Restart(); Polar.Data.Phototeka generator = new Polar.Data.Phototeka(npersons, 777777); //var n = generator.Generate1of3().Count(); //tabs.Build( // generator.Generate1of3()); tabs.Clear(); var query_p = generator.Generate1of3(); tabs.BuildPersons(query_p); var query_ph = generator.Generate2of3(); tabs.BuildPhoto_docs(query_ph); var query_r = generator.Generate3of3(); tabs.BuildReflections(query_r); sw.Stop(); Console.WriteLine("Load ok. Duration={0}", sw.ElapsedMilliseconds); // 10000: 14.9 сек. sw.Restart(); tabs.BuildIndexes(); sw.Stop(); Console.WriteLine("BuildIndexes ok. Duration={0}", sw.ElapsedMilliseconds); // 10000: 14.9 сек. //foreach (XElement xprobe in xcnf.Elements()) //{ // ProbeFrame probe = new ProbeFrame(xprobe.AncestorsAndSelf().Attributes()); // int npersons = (int)probe.siz; // if (probe.sol == "Stan3TabsInt_load") // { // sw.Restart(); // Polar.Data.Phototeka generator = new Polar.Data.Phototeka(npersons, 777777); // //var n = generator.Generate1of3().Count(); // //tabs.Build( // // generator.Generate1of3()); // tabs.Clear(); // var query_p = generator.Generate1of3(); // tabs.BuildPersons(query_p); // var query_ph = generator.Generate2of3(); // tabs.BuildPhoto_docs(query_ph); // var query_r = generator.Generate3of3(); // tabs.BuildReflections(query_r); // sw.Stop(); // probe.lod = sw.ElapsedMilliseconds; // Console.WriteLine("Load ok. Duration={0}", sw.ElapsedMilliseconds); // 10000: 14.9 сек. // sw.Restart(); // tabs.BuildIndexes(); // sw.Stop(); // probe.ndx = sw.ElapsedMilliseconds; // Console.WriteLine("BuildIndexes ok. Duration={0}", sw.ElapsedMilliseconds); // 10000: 14.9 сек. // res.WriteLine(probe.ToCSV()); // } // else if (probe.sol == "Stan3TabsInt_SelectById") // { // rnd = new Random(777777777); // sw.Restart(); // long sum = 0; // for (int i = 0; i < probe.nte; i++) // { // int id = rnd.Next(0, (int)probe.siz - 1); // var p = tabs.GetPersonByCode(id); // sum += (int)p[2]; // } // sw.Stop(); // probe.tim = sw.ElapsedMilliseconds; // probe.sum = sum; // Console.WriteLine("SelectById ok. Duration={0}", sw.ElapsedMilliseconds); // 46 (1000) // res.WriteLine(probe.ToCSV()); // } // else if (probe.sol == "Stan3TabsInt_SearchByName") // { // rnd = new Random(777777777); // sw.Restart(); // long sum = 0; // for (int i = 0; i < probe.nte; i++) // { // int id = rnd.Next(0, (int)probe.siz - 1); // string namePrefix = "Pupkin" + id / 10; // var ob = tabs.GetPersonsByName(namePrefix).ToArray(); // sum += ob.Length; // sum = sum + 1 - 1; // //sum += (int)simpleTripleStore.GetSubjects("a", "person").Select(personId => simpleTripleStore.GetObject(personId, "name").FirstOrDefault()).Count(name => name.StartsWith(namePrefix)); // } // sw.Stop(); // probe.tim = sw.ElapsedMilliseconds; // probe.sum = sum; // Console.WriteLine("SearchByName ok. Duration={0}", sw.ElapsedMilliseconds); // 7 // res.WriteLine(probe.ToCSV()); // } // else if (probe.sol == "Stan3TabsInt_GetRelationByPerson") // { // rnd = new Random(777777777); // sw.Restart(); // long sum = 0; // for (int i = 0; i < probe.nte; i++) // { // int id = rnd.Next(0, (int)probe.siz - 1); // //var qu = tabs.GetReflectionsByReflected(id); // sum += tabs.GetReflectionsByReflected(id).Count(); // } // sw.Stop(); // probe.tim = sw.ElapsedMilliseconds; // probe.sum = sum; // Console.WriteLine("GetRelationByPerson ok. Duration={0}", sw.ElapsedMilliseconds); // 7 // res.WriteLine(probe.ToCSV()); // } // else if (probe.sol == "unused") // { // int cnt = 0; // bool toload = false; // toload = true; // if (toload) // { // sw.Restart(); // Polar.Data.Phototeka generator = new Polar.Data.Phototeka(npersons, 2378459); // tabs.Build( // generator.Generate1of3() // .Concat(generator.Generate2of3() // .Concat(generator.Generate3of3()))); // sw.Stop(); // Console.WriteLine("Load ok. duration={0}", sw.ElapsedMilliseconds); // } // sw.Restart(); // for (int i = 0; i < 10000; i++) // { // int code = rnd.Next(npersons - 1); // object[] v = tabs.GetPersonByCode(code); // } // sw.Stop(); // Console.WriteLine("10000 persons ok. duration={0}", sw.ElapsedMilliseconds); // sw.Restart(); // for (int i = 0; i < 10000; i++) // { // int code = rnd.Next(2 * npersons - 1); // object[] v = tabs.GetPhoto_docByCode(code); // if (i == 200) // { // Console.WriteLine("photo_doc record: {0} {1}", v[0], v[1]); // } // } // sw.Stop(); // Console.WriteLine("10000 photo_docs ok. duration={0}", sw.ElapsedMilliseconds); // sw.Restart(); // for (int i = 0; i < 10000; i++) // { // int code = rnd.Next(2 * npersons - 1); // cnt = tabs.GetReflectionsByReflected(code).Count(); // } // sw.Stop(); // Console.WriteLine("10000 portraits ok. duration={0}", sw.ElapsedMilliseconds); // } //res.Close(); }
private static void Main(string[] args) { string path = ProjectDirectory.GetProjectDirectory(); if (!Directory.Exists(path + "../Databases/simple triple store")) { Directory.CreateDirectory(path + "../Databases/simple triple store"); } Console.WriteLine("Start TestGenerator"); TextWriter res = new StreamWriter(new FileStream(path + "res.txt", FileMode.Append, FileAccess.Write)); XElement xcnf = XElement.Load(path + "tests.xml"); XElement xcommon = XElement.Load(path + "../common.xml"); xcommon.Add(xcnf); Random rnd; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); SimpleTripleStore.SimpleTripleStore simpleTripleStore = new SimpleTripleStore.SimpleTripleStore(path + "../Databases/simple triple store/", 1000 * 1000); foreach (XElement xprobe in xcnf.Elements()) { ProbeFrame probe = new ProbeFrame(xprobe.AncestorsAndSelf().Attributes()); int npersons = (int)probe.siz; if (probe.sol == "simpleTripleStore_load") { // Directory.Delete(path + "../Databases/simple triple store", true); sw.Restart(); Polar.Data.Phototeka generator = new Polar.Data.Phototeka(npersons, 777777); simpleTripleStore.Build(generator.GenerateRDF()); sw.Stop(); Console.WriteLine("Load ok. Duration={0}", sw.ElapsedMilliseconds); // 10000: 14.9 сек. probe.ndx = sw.ElapsedMilliseconds; res.WriteLine(probe.ToCSV()); } else if (probe.sol == "simpleTripleStore_SelectById") { rnd = new Random(777777777); sw.Restart(); long sum = 0; for (int i = 0; i < probe.nte; i++) { int id = rnd.Next(0, (int)probe.siz - 1); sum += Convert.ToInt32(simpleTripleStore.GetDirects(id).FirstOrDefault(tuple => tuple.Item1 == "age").Item2); } sw.Stop(); probe.tim = sw.ElapsedMilliseconds; probe.sum = sum; Console.WriteLine("SelectById ok. Duration={0}", sw.ElapsedMilliseconds); // 7 res.WriteLine(probe.ToCSV()); } else if (probe.sol == "simpleTripleStore_SearchByName") { rnd = new Random(777777777); sw.Restart(); WordIndex index = new WordIndex(); for (int i = 0; i < probe.siz; i++) { var w = simpleTripleStore.GetObject(i, "name").First(); index.Insert(w, i); } Console.WriteLine("build words trigrams index " + sw.ElapsedMilliseconds); Console.WriteLine("RAM used {0} mb.", GC.GetTotalMemory(false) / 1024 / 1024); sw.Restart(); long sum = 0, sum2 = 0; for (int i = 0; i < probe.nte; i++) { int id = rnd.Next(0, (int)probe.siz - 1); string namePrefix = "Pupkin" + id / 10; sum += (int)index.FindBySubWord(namePrefix).Count(); } Console.WriteLine(sum); Console.WriteLine(sum2); sw.Stop(); probe.tim = sw.ElapsedMilliseconds; probe.sum = sum; Console.WriteLine("SearchByName ok. Duration={0}", sw.ElapsedMilliseconds); // 7 res.WriteLine(probe.ToCSV()); } else if (probe.sol == "simpleTripleStore_GetRelationByPerson") { rnd = new Random(777777777); sw.Restart(); long sum = 0; for (int i = 0; i < probe.nte; i++) { int persId = rnd.Next(0, (int)probe.siz - 1); sum += simpleTripleStore.GetSubjects("reflected", persId.ToString()) .Select(refid => simpleTripleStore.GetObject(refid, "in_doc").First()) .Select(int.Parse) .Select(photoId => simpleTripleStore.GetDirects(photoId)) .Count(); } sw.Stop(); probe.tim = sw.ElapsedMilliseconds; probe.sum = sum; Console.WriteLine("GetRelationByPerson ok. Duration={0}", sw.ElapsedMilliseconds); // 7 res.WriteLine(probe.ToCSV()); } else if (probe.sol == "unused") { } } res.Close(); }