2017-02-15 2 views
-1

.docx 파일 인 chaptervise의 내용을 추출하고 싶습니다. 그래서, 내 .docx 문서는 레지스터를 가지고 있으며, 각 장에서는 일부 콘텐츠 그래서 결국.docx 파일 챕터 추출

1. Intro 
    some text about Intro, these things, those things 
2. Special information 
    these information are really special 
    2.1 General information about the environment 
     environment should be also important 
    2.2 Further information 
     and so on and so on 

는 인덱스 번호, 인덱스 이름과 최소한의 내용을 포함하는 Nx3 매트릭스를받을 좋은 것있다. 당신의 도움에 대한

i_number  i_name     content 
1   Intro     some text about Intro, these things, those things 
2   Special Information these information are really special 
... 

감사

당신은 내보내거나이 R 스크립트를 .txt 인에 .DOCX을 복사 - 붙여 넣기 및 적용 할 수
+0

R 또는 Python 솔루션이 적합할까요? –

+0

R 대신 파이썬도 가능합니다. –

답변

0

가 : 문서 경우

library(stringr) 
library(readr) 

doc <- read_file("filename.txt") 

pattern_chapter <- regex("(\\d+\\.)(.{4,100}?)(?:\r\n)", dotall = T) 

i_name <- str_match_all(doc, pattern_chapter)[[1]][,1] 
paragraphs <- str_split(doc, pattern_chapter)[[1]] 
content <- paragraphs[-which(paragraphs=="")] 

result <- data.frame(i_name, content) 
result$i_number <- seq.int(nrow(result)) 

View(result) 

그것은 작동하지 않습니다 숫자 (예 : 각주 또는 번호 매기기 목록)로 시작하는 제목이 아닌 모든 종류의 행을 포함합니다.

(제발,이 스크립트는 주어진 예제와 완벽하게 작동합니다)