kota7 / striprtf

R Package for Extracting Text from RTF (Rich Text Format) File
Other
19 stars 4 forks source link

Fix the table parsing of some RTF (SAS-generated?) #22

Closed kota7 closed 1 year ago

kota7 commented 1 year ago

The table in this document (the same as provided in #20) is not precisely parsed.

The table should have five columns 姓名, 性别, 年龄, 身高(英寸), 体重(磅).

read_rtf("tests/testthat/chinese-sas.rtf")
 [1] "SAS "                       "系统"                       ""                           ""                          
 [5] "*| 姓名"                    "*|  | "                     "*| 性别"                    "*|  | "                    
 [9] "*| 年龄"                    "*|  | "                     "*| 身高(英寸)"            "*|  | "                    
[13] "*| 体重(磅)"              "*|  | "                     "*| 阿尔弗雷德"              "*|  | "                    
[17] "*| 男"                      "*|  | 14 | 69 | 112.5 | "   "*| 爱丽丝"                  "*|  | "                    
[21] "*| 女"                      "*|  | 13 | 56.5 | 84 | "    "*| 芭芭拉"                  "*|  | "                    
[25] "*| 女"                      "*|  | 13 | 65.3 | 98 | "    "*| 凯露"                    "*|  | "                    
[29] "*| 女"                      "*|  | 14 | 62.8 | 102.5 | " "*| 亨利"                    "*|  | "                    
[33] "*| 男"                      "*|  | 14 | 63.5 | 102.5 | " "*| 詹姆斯"                  "*|  | "                    
[37] "*| 男"                      "*|  | 12 | 57.3 | 83 | "    "*| 简"                      "*|  | "                    
[41] "*| 女"                      "*|  | 12 | 59.8 | 84.5 | "  "*| 雅妮特"                  "*|  | "                    
[45] "*| 女"                      "*|  | 15 | 62.5 | 112.5 | " "*| 杰弗瑞"                  "*|  | "                    
[49] "*| 男"                      "*|  | 13 | 62.5 | 84 | "    "*| 约翰"                    "*|  | "                    
[53] "*| 男"                      "*|  | 12 | 59 | 99.5 | "    "*| 乔伊斯"                  "*|  | "                    
[57] "*| 女"                      "*|  | 11 | 51.3 | 50.5 | "  "*| 茱迪"                    "*|  | "                    
[61] "*| 女"                      "*|  | 14 | 64.3 | 90 | "    "*| 罗伊斯"                  "*|  | "                    
[65] "*| 女"                      "*|  | 12 | 56.3 | 77 | "    "*| 玛丽"                    "*|  | "                    
[69] "*| 女"                      "*|  | 15 | 66.5 | 112 | "   "*| 菲利普"                  "*|  | "                    
[73] "*| 男"                      "*|  | 16 | 72 | 150 | "     "*| 罗伯特"                  "*|  | "                    
[77] "*| 男"                      "*|  | 12 | 64.8 | 128 | "   "*| 罗纳德"                  "*|  | "                    
[81] "*| 男"                      "*|  | 15 | 67 | 133 | "     "*| 托马斯"                  "*|  | "                    
[85] "*| 男"                      "*|  | 11 | 57.5 | 85 | "    "*| 威廉"                    "*|  | "                    
[89] "*| 男"                      "*|  | 15 | 66.5 | 112 | "   ""                           ""           

test_cn.zip

kota7 commented 1 year ago

Fixed by #23.

read_rtf("tests/testthat/chinese-sas.rtf")
 [1] "SAS 系统"                                             ""                                                    
 [3] "*| 姓名 | 性别 | 年龄 | 身高(英寸) | 体重(磅) | " "*| 阿尔弗雷德 | 男 | 14 | 69 | 112.5 | "             
 [5] "*| 爱丽丝 | 女 | 13 | 56.5 | 84 | "                   "*| 芭芭拉 | 女 | 13 | 65.3 | 98 | "                  
 [7] "*| 凯露 | 女 | 14 | 62.8 | 102.5 | "                  "*| 亨利 | 男 | 14 | 63.5 | 102.5 | "                 
 [9] "*| 詹姆斯 | 男 | 12 | 57.3 | 83 | "                   "*| 简 | 女 | 12 | 59.8 | 84.5 | "                    
[11] "*| 雅妮特 | 女 | 15 | 62.5 | 112.5 | "                "*| 杰弗瑞 | 男 | 13 | 62.5 | 84 | "                  
[13] "*| 约翰 | 男 | 12 | 59 | 99.5 | "                     "*| 乔伊斯 | 女 | 11 | 51.3 | 50.5 | "                
[15] "*| 茱迪 | 女 | 14 | 64.3 | 90 | "                     "*| 罗伊斯 | 女 | 12 | 56.3 | 77 | "                  
[17] "*| 玛丽 | 女 | 15 | 66.5 | 112 | "                    "*| 菲利普 | 男 | 16 | 72 | 150 | "                   
[19] "*| 罗伯特 | 男 | 12 | 64.8 | 128 | "                  "*| 罗纳德 | 男 | 15 | 67 | 133 | "                   
[21] "*| 托马斯 | 男 | 11 | 57.5 | 85 | "                   "*| 威廉 | 男 | 15 | 66.5 | 112 | "                   
[23] ""                                                     ""