Пример #1
0
        public void XlsxTypeCTest()
        {
            string   xlsxFile       = Path.Combine(TestUtil.GetTestDataPath(), "c_sample.xlsx");
            IAdapter adapter        = AsposeExcelAdapter.CreateAdapter(xlsxFile);
            var      columnOrdering = ColumnDetector.ExamineTableBeginning(adapter);

            Smart.Parser.Lib.Parser parser      = new Smart.Parser.Lib.Parser(adapter);
            Declaration             declaration = parser.Parse(columnOrdering, false, null);
            string comments = "";
            string output   = DeclarationSerializer.Serialize(declaration, ref comments);
        }
Пример #2
0
        static Declaration BuildDeclarations(IAdapter adapter, string inputFile)
        {
            Declaration declaration;
            string      inputFileName = Path.GetFileName(inputFile);

            Smart.Parser.Lib.Parser parser = new Smart.Parser.Lib.Parser(adapter, !SkipRelativeOrphan);

            if (adapter.CurrentScheme == default)
            {
                var columnOrdering = ColumnDetector.ExamineTableBeginning(adapter);

                // Try to extract declaration year from file name if we weren't able to get it from document title
                if (!columnOrdering.Year.HasValue)
                {
                    columnOrdering.Year = TextHelpers.ExtractYear(inputFileName);
                }

                Logger.Info("Column ordering: ");
                foreach (var ordering in columnOrdering.ColumnOrder)
                {
                    Logger.Info(ordering.ToString());
                }

                Logger.Info(String.Format("OwnershipTypeInSeparateField: {0}",
                                          columnOrdering.OwnershipTypeInSeparateField));

                if (ColumnsOnly)
                {
                    return(null);
                }

                if (ColumnToDump != DeclarationField.None)
                {
                    DumpColumn(adapter, columnOrdering, ColumnToDump);
                    return(null);
                }

                if (columnOrdering.Title != null)
                {
                    Logger.Info("Declaration Title: {0} ", columnOrdering.Title);
                }

                if (columnOrdering.Year != null)
                {
                    Logger.Info("Declaration Year: {0} ", columnOrdering.Year.Value);
                }

                if (columnOrdering.MinistryName != null)
                {
                    Logger.Info("Declaration Ministry: {0} ", columnOrdering.MinistryName);
                }


                if (!(columnOrdering.ContainsField(DeclarationField.NameOrRelativeType) ||
                      columnOrdering.ContainsField(DeclarationField.NameAndOccupationOrRelativeType)))
                {
                    // TODO сначала поискать первый section_row и проверить, именно там может быть ФИО
                    // https://declarator.org/admin/declarations/jsonfile/186842/change/
                    Logger.Error("Insufficient fields: No any of Declarant Name fields found.");
                    return(null);
                }

                if (!(columnOrdering.ContainsField(DeclarationField.DeclarantIncome) ||
                      columnOrdering.ContainsField(DeclarationField.DeclarantIncomeInThousands) ||
                      columnOrdering.ContainsField(DeclarationField.DeclaredYearlyIncome) ||
                      columnOrdering.ContainsField(DeclarationField.DeclaredYearlyIncomeThousands)))
                {
                    if (!ColumnOrdering.SearchForFioColumnOnly)
                    {
                        Logger.Error("Insufficient fields: No any of Declarant Income fields found.");
                        return(null);
                    }
                }

                declaration = parser.Parse(columnOrdering, BuildTrigrams, UserDocumentFileId);
                SaveRandomPortionToToloka(adapter, columnOrdering, declaration, inputFile);
            }
            else
            {
                declaration = adapter.CurrentScheme.Parse(parser, UserDocumentFileId);
            }
            return(declaration);
        }