Ejemplo n.º 1
0
        static public void ReadHeader(IAdapter adapter, int headerStartRow, ColumnOrdering columnOrdering)
        {
            int headerEndRow;
            var cells = GetColumnCells(adapter, headerStartRow, out headerEndRow);

            MapStringsToConstants(adapter, cells, columnOrdering);

            columnOrdering.HeaderBegin = headerStartRow;
            columnOrdering.HeaderEnd   = headerEndRow;
            int firstDataRow = columnOrdering.HeaderEnd.Value;

            // пропускаем колонку с номерами
            if (firstDataRow < adapter.GetRowsCount())
            {
                string cellText1 = adapter.GetCell(firstDataRow, 0).GetText();
                string cellText2 = adapter.GetCell(firstDataRow, 1).GetText();
                if (cellText1 == "1" && cellText2 == "2")
                {
                    firstDataRow++;
                }
            }

            columnOrdering.FirstDataRow = firstDataRow;

            if (columnOrdering.ColumnOrder.Count() == 0)
            {
                throw new SmartParserException("cannot find headers");
            }
            // todo check whether we need them
            FixMissingSubheadersForMixedRealEstate(adapter, columnOrdering);
            FixMissingSubheadersForVehicle(adapter, columnOrdering);
            FixBadColumnName01(columnOrdering);
            FixBadColumnName02(columnOrdering);
            columnOrdering.FinishOrderingBuilding(cells[0].AdditTableIndention);
        }
Ejemplo n.º 2
0
        static void FixMissingSubheadersForMixedRealEstate(IAdapter adapter, ColumnOrdering columnOrdering)
        {
            //see DepEnergo2010.doc  in tests
            if (!columnOrdering.ContainsField(DeclarationField.MixedColumnWithNaturalText))
            {
                return;
            }
            TColumnInfo dummy;
            var         headerCell = adapter.GetDeclarationFieldWeak(columnOrdering, columnOrdering.HeaderBegin.Value, DeclarationField.MixedColumnWithNaturalText, out dummy);
            var         subCells   = FindSubcellsUnder(adapter, headerCell);

            if (subCells.Count != 3)
            {
                return;
            }
            for (int row = columnOrdering.FirstDataRow; row < adapter.GetRowsCount(); row++)
            {
                if (row > columnOrdering.FirstDataRow + 5)
                {
                    break;
                }
                // we check only the  second column, todo check the  first one and  the third
                string areaStr = adapter.GetCell(row, subCells[1].Col).GetText(true);
                if (!DataHelper.ParseSquare(areaStr).HasValue)
                {
                    return;
                }
            }
            AddColumn(columnOrdering, DeclarationField.MixedRealEstateType, subCells[0]);
            AddColumn(columnOrdering, DeclarationField.MixedRealEstateSquare, subCells[1]);
            AddColumn(columnOrdering, DeclarationField.MixedRealEstateCountry, subCells[2]);
            columnOrdering.Delete(DeclarationField.MixedColumnWithNaturalText);
        }
Ejemplo n.º 3
0
        public static DeclarationField PredictEmptyColumnTitle(IAdapter adapter, Cell headerCell)
        {
            List <string> texts           = new List <string>();
            int           rowIndex        = headerCell.Row + headerCell.MergedRowsCount;
            const int     maxRowToCollect = 10;

            for (int i = 0; i < maxRowToCollect; i++)
            {
                var    cells = adapter.GetCells(rowIndex, IAdapter.MaxColumnsCount);
                string dummy;
                if (IAdapter.IsSectionRow(cells, adapter.GetColsCount(), false, out dummy))
                {
                    rowIndex += 1;
                }
                else
                {
                    var c = adapter.GetCell(rowIndex, headerCell.Col);
                    if (c != null)
                    {
                        texts.Add(c.GetText(true));
                        rowIndex += c.MergedRowsCount;
                    }
                    else
                    {
                        rowIndex += 1;
                    }
                }
                if (rowIndex >= adapter.GetRowsCount())
                {
                    break;
                }
            }
            var field = PredictByStrings(texts);

            if (headerCell.TextAbove != null && ((field & DeclarationField.AllOwnTypes) > 0))
            {
                string h = headerCell.TextAbove;
                // AllOwnTypes defined from
                field &= ~DeclarationField.AllOwnTypes;
                if (HeaderHelpers.IsMixedColumn(h))
                {
                    field |= DeclarationField.Mixed;
                }
                else if (HeaderHelpers.IsStateColumn(h))
                {
                    field |= DeclarationField.State;
                }
                else if (HeaderHelpers.IsOwnedColumn(h))
                {
                    field |= DeclarationField.Owned;
                }
            }
            Logger.Debug(string.Format("predict by {0}  -> {1}",
                                       String.Join("\\n", texts), field));
            return(field);
        }