public void ProcessElement_TableCell_NotContextTest() { var table = TableSimple.Build3x3(); var tableCell = table.Descendants <TableCell>().First(); Assert.IsFalse(_instance.ProcessElement(_elemState, tableCell)); }
public void Build_CellsIgnoreGridBeforeTest() { _table = TableSimple.BuildIgnoreGridBefore(); BuildGrid(); _expected = BuildExpectedCellsIgnoreGridBefore(); AssertExpectedCells(_expected); }
public void Build_Cells3X3Test() { _table = TableSimple.Build3x3(); BuildGrid(); ExpectedCell[] expected = BuildExpectedCell3X3(); AssertExpectedCells(expected); }
//private // =========== Инициирование и построение =========== public override void Init(string connectionstring) { // connectionstring имеет конструкцию: trs:name=value;name2=value2 // path - директрия для базы данных string[] parts = connectionstring.Substring(4).Split('=', ';'); for (int i = 0; i < parts.Length; i += 2) { if (parts[i * 2].ToLower() == "path") { path = parts[i * 2 + 1]; if (path[path.Length - 1] != '/' && path[path.Length - 1] != '\\') { path = path + "/"; } } } tp_record = new PTypeRecord( new NamedType("s", new PType(PTypeEnumeration.sstring)), new NamedType("p", new PType(PTypeEnumeration.sstring)), new NamedType("o", new PTypeUnion( new NamedType("empty", new PType(PTypeEnumeration.none)), new NamedType("uri", new PType(PTypeEnumeration.sstring)), new NamedType("str", new PType(PTypeEnumeration.sstring)), new NamedType("langstr", new PTypeRecord( new NamedType("lang", new PType(PTypeEnumeration.sstring)), new NamedType("str", new PType(PTypeEnumeration.sstring))))))); Func <Stream> gen_stream = () => File.Open(path + "f" + (fno++) + ".bin", FileMode.OpenOrCreate); table = new TableSimple(tp_record, new int[] { 0 }, gen_stream); }
public void Build_Cells321GridBeforeVMergeTest() { _table = TableSimple.Build321GridBeforeVMerge(); BuildGrid(); _expected = BuildExpectedCells321GridBeforeVMerge(); AssertExpectedCells(_expected); }
public void Build_CellsGridSpanTest() { _table = TableSimple.BuildGridSpan(); BuildGrid(); _expected = BuildExpectedCellsGridSpan(); AssertExpectedCells(_expected); }
public void Build_PropsVMergeTest() { _table = TableSimple.BuildVMerge(); BuildGrid(); Assert.AreEqual(1000, _grid.GetWidth(0)); Assert.AreEqual(1000, _grid.GetWidth(1)); Assert.AreEqual(1000, _grid.GetWidth(2)); Assert.AreEqual(3, _grid.RowCount); Assert.AreEqual(3, _grid.ColumnCount); }
public void ProcessElement_TableCell_NotFoundTest() { var table = TableSimple.Build3x3(); _tableContext = new TableContext() { GridStateFactory = _instance.GridStateFactory }; _tableContext.AddTable(table, 10); Assert.IsFalse(_instance.ProcessElement(_elemState, new TableCell())); }
public void ProcessElement_Table_Test() { var table = TableSimple.Build3x3(); Assert.IsTrue(_instance.ProcessElement(_elemState, table)); Assert.IsNotNull(_tableContext); AssertHasAllCells(table); VNode addedVNode = GetAddedVNode(); _elemState.Received(1).CurrentVNode = addedVNode; }
public void Build_Props3X3Test() { _table = TableSimple.Build3x3(); _grid = _instance.Build(_table, 0); Assert.AreEqual(TableRowAlignmentValues.Left, _grid.Jusitification); Assert.IsNotNull(_grid.ClsName); Assert.AreEqual(1000, _grid.GetWidth(0)); Assert.AreEqual(2000, _grid.GetWidth(1)); Assert.AreEqual(3000, _grid.GetWidth(2)); Assert.AreEqual(3, _grid.RowCount); Assert.AreEqual(3, _grid.ColumnCount); }
public void ProcessElement_TableRow_Test() { var table = TableSimple.Build3x3(); _tableContext = new TableContext() { GridStateFactory = _instance.GridStateFactory }; _tableContext.AddTable(table, 10); var row = table.ChildElements.First <TableRow>(); Assert.IsTrue(_instance.ProcessElement(_elemState, row)); }
public void Build_VNode3X3Test() { _table = TableSimple.Build3x3(); BuildGrid(50); var vNode = _grid.VNode; Assert.AreEqual(50, vNode.Index); Assert.AreEqual(9, vNode.Length); CollectionAssert.Contains( vNode.Classes.ToArray(), "grid" ); }
private IElementProcessingState MockElemProcessingStateWithTableContext() { var tableContext = new TableContext() { GridStateFactory = _instance.GridStateFactory }; tableContext.AddTable(TableSimple.Build3x3(), 0); _fullCssData.AddRange(tableContext.GetCssData()); var elemState = new ElementProcessingState(); elemState.SetContext(tableContext); return(elemState); }
public void Build_GetCellFromTable3X3Test() { _table = TableSimple.Build3x3(); BuildGrid(); AssertStateMatchTable(0, 0, 0); AssertStateMatchTable(1, 0, 1); AssertStateMatchTable(2, 0, 2); AssertStateMatchTable(3, 1, 0); AssertStateMatchTable(4, 1, 1); AssertStateMatchTable(5, 1, 2); AssertStateMatchTable(6, 2, 0); AssertStateMatchTable(7, 2, 1); AssertStateMatchTable(8, 2, 2); }
public void Build_Css3X3Test() { _table = TableSimple.Build3x3(); BuildGrid(); var result = _grid.AsCssData(); var expected = new CssData(); expected.AddAttribute(".demo", "display", "grid"); AddGridCols(expected, 1000, 2000, 3000); foreach (var c in BuildExpectedCell3X3()) { c.SetCssData(expected, "demo"); } Assert.AreEqual(expected, result); }
public void ProcessElement_TableCell_Test() { var table = TableSimple.Build3x3(); _tableContext = new TableContext() { GridStateFactory = _instance.GridStateFactory }; _tableContext.AddTable(table, 10); var tableCell = table.Descendants <TableCell>().First(); var cellState = _tableContext.GetCell(tableCell); _instance.ProcessElement(_elemState, tableCell); var cellVNode = cellState.VNode; Assert.IsNotNull(cellVNode); _elemState.Received(1).CurrentVNode = cellVNode; }
public void Build_ApplyLayoutOptimizeTest() { var table = TableSimple.Build3x3(); var layouts = Enumerable.Range(0, 5) .Select(x => Substitute.For <ILayout>()) .ToList(); _instance.LayoutFactory .Build(Arg.Is(table)) .Returns(layouts); var grid = _instance.Build(table, 0); _instance.LayoutFactory.Received(1).Build(table); foreach (var layout in layouts) { layout.Received(1).Apply(Arg.Is(grid)); } _instance.GridOptimizer.Received(1).Optimize(grid); }
static void Main(string[] args) { string path = "../../../../../"; Console.WriteLine("Start Task14_FullTextSearch"); var reader = new StreamReader(path + "Resources/zaliznyak_shortform.txt"); Dictionary <string, string> normal_form = new Dictionary <string, string>(); string line = null; string normal = null; int cnt = 0; while ((line = reader.ReadLine()) != null) { string[] prts = line.Split(' '); normal = prts[0]; foreach (string w in prts) { normal_form.TryAdd(w, normal); } cnt++; } Console.WriteLine($"n={cnt} words={normal_form.Count}"); PType tp_elem = new PTypeRecord( new NamedType("nom", new PType(PTypeEnumeration.integer)), new NamedType("news", new PType(PTypeEnumeration.sstring))); int dnom = 0; Func <Stream> getStream = () => File.Open(path + "Databases/data" + (dnom++), FileMode.OpenOrCreate); TableSimple table = new TableSimple(tp_elem, new int[] { 0 }, getStream); table.Fill(Generate(path + "Resources/academpark-newsflow.txt")); // Построение полнотекстового индекса PType tp_index = new PTypeRecord( new NamedType("nom", new PType(PTypeEnumeration.integer)), new NamedType("word", new PType(PTypeEnumeration.sstring))); TableSimple ft_index = new TableSimple(tp_index, new int[] { 1 }, getStream); char[] delems = new char[] { ' ', ',', '.', '!', '?', '\n', '-', ':' }; //Func<object[]> generateNomWordFlow = () => var generateNomWordFlow = table.ElementValues() .SelectMany(nomtext => { int nom = (int)nomtext[0]; string text = (string)nomtext[1]; string[] words = text.Split(delems); var setofwords = words.Where(w => !string.IsNullOrEmpty(w) && w.Length > 2 && char.IsLetter(w[0])) .Select(w => { if (normal_form.TryGetValue(w.ToLower(), out string wrd)) { return(wrd); } return(null); }) .Where(w => !string.IsNullOrEmpty(w)) .Distinct(); return(setofwords.Select(w => new object[] { nom, w })); }); // Заполнение таблицы ft_index.Fill(generateNomWordFlow); // Поиск по одному слову var qu = ft_index.GetAllByKey(1, "олимпиада"); foreach (object[] vv in qu) { int nom = (int)vv[0]; var qq = table.GetAllByKey(0, nom).FirstOrDefault(); Console.WriteLine($"{qq[0]} {qq[1]}"); } // Тестирование скорости System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); string aaa = "Завтра в Академпарке назовут новых резидентов бизнес инкубаторов 5 марта состоится торжественная церемония закрытия десятой юбилейной инновационной школы Академпарка Начало подведения итогов"; string[] parts = aaa.ToLower().Split(' '); Console.WriteLine(parts.Count() + " samples"); int cont = 0; sw.Start(); foreach (string w in parts) { cont += ft_index.GetAllByKey(1, w).Select((object[] vv) => { int nom = (int)vv[0]; return(table.GetAllByKey(0, nom).FirstOrDefault()); }).Count(); } sw.Stop(); Console.WriteLine($"всего найдено документов: {cont} за время: {sw.ElapsedMilliseconds}"); }
static void Main(string[] args) { Console.WriteLine("Start Task13_TripleStore"); // Создаем генератор триплетов теста фототека. Генерируем поток массивов трех строк. Входным параметром является количество персон Random rnd = new Random(); Func <int, IEnumerable <string[]> > GenerateTriples = n => { // n персон var persons = Enumerable.Range(0, n).SelectMany(i => new string[][] { new string[] { "<p" + (n - i - 1) + ">", "<name>", "Pupkin_" + (n - i - 1) }, // имя new string[] { "<p" + (n - i - 1) + ">", "<age>", "33" } // возраст }); // 2*n фоток var photos = Enumerable.Range(0, 2 * n).SelectMany(i => new string[][] { new string[] { "<ph" + (2 * n - i - 1) + ">", "<name>", "DSP_" + (2 * n - i - 1) }, // имя new string[] { "<ph" + (2 * n - i - 1) + ">", "<age>", "33" } // возраст }); // 6*n отражений var reflections = Enumerable.Range(0, 6 * n).SelectMany(i => new string[][] { new string[] { "<re" + (6 * n - i - 1) + ">", "<reflected>", "<p" + rnd.Next(n) + ">" }, // отражаемое new string[] { "<re" + (6 * n - i - 1) + ">", "<inphoto>", "<ph" + rnd.Next(2 * n) + ">" } // в документе }); return(persons.Concat(photos).Concat(reflections)); }; PType tp_triple = new PTypeRecord( new NamedType("subject", new PType(PTypeEnumeration.sstring)), new NamedType("predicate", new PType(PTypeEnumeration.sstring)), new NamedType("object", new PType(PTypeEnumeration.sstring))); string path = "data"; int nom = 0; TableSimple triples = new TableSimple(tp_triple, new int[] { 0, 2 }, () => File.Open(path + (nom++), FileMode.OpenOrCreate)); int npersons = 400_000; bool toload = true; if (toload) // Загрузка данных { triples.Fill(GenerateTriples(npersons)); } string sample = "<p" + (npersons * 2 / 3) + ">"; var rfls = triples.GetAllByKey(2, sample).Where(r => (string)r[1] == "<reflected>"); foreach (object[] r in rfls) { Console.WriteLine($"{r[0]} {r[1]} {r[2]}"); } Console.WriteLine(); var indocs = rfls.SelectMany(r => triples.GetAllByKey(0, r[0])).Where(t => (string)t[1] == "<inphoto>"); foreach (object[] r in indocs) { Console.WriteLine($"{r[0]} {r[1]} {r[2]}"); } Console.WriteLine(); var phs = indocs.SelectMany(r => triples.GetAllByKey(0, r[2])).Where(t => (string)t[1] == "<name>"); foreach (object[] r in phs) { Console.WriteLine($"{r[0]} {r[1]} {r[2]}"); } Console.WriteLine(); // Теперь цикл по образцам System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); int nsamples = 1000; sw.Start(); int count = 0; for (int i = 0; i < nsamples; i++) { sample = "<p" + rnd.Next(npersons) + ">"; var que = triples.GetAllByKey(2, sample).Where(r => (string)r[1] == "<reflected>") .SelectMany(r => triples.GetAllByKey(0, r[0])).Where(t => (string)t[1] == "<inphoto>") .SelectMany(r => triples.GetAllByKey(0, r[2])).Where(t => (string)t[1] == "<name>"); //foreach (object[] r in que) Console.WriteLine($"{r[0]} {r[1]} {r[2]}"); //Console.WriteLine(); count += que.Count(); } sw.Stop(); Console.WriteLine($"count={count} duration={sw.ElapsedMilliseconds}"); }