2017-02-15 2 views
-1

Ich möchte den Inhalt einer .docx Datei, Kapitelvise extrahieren. Also, mein .docx Dokument hat ein Register und jedes Kapitel hat einige Inhalte.docx Datei Kapitel Extraktion

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 

So schließlich wäre es toll, eine Nx3 Matrix zu erhalten, die Indexnummer, die Indexnamen und mindestens den Inhalt.

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

Danke für Ihre Hilfe

+0

Eine R- oder Python-Lösung würde zu Ihnen passen? –

+0

Eher in R wäre aber auch Python möglich. –

Antwort

0

Sie exportieren könnten oder Ihre .docx in einer TXT-copy-paste und diese R-Skript anwenden:

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) 

Es ist nicht, wenn Ihr Dokument funktioniert enthält jede Art von Zeile, die keine Überschrift ist, die mit einer Nummer beginnt (zB Fußnoten oder nummerierte Listen)

(bitte, keine sinnlose Überschrift: dieses Skript funktioniert perfekt mit dem angegebenen Beispiel)