如何以正确的顺序从DOCX文件中提取阿拉伯语/FARSI(RTL)文本



我正在尝试从某些DOCX文件中提取大量文本并将其存储在.txt文件中。

我正在使用的语言是Farsi/Arabic(它们是正确的左语言(,因此我很难使用Python-docx。我不能以适当的形式提取文本,它们都被混合在.txt文件中。

提取的表单= https://pasteboard.co/id8jj7g.jpg

原始表格= https://pasteboard.co/id8jv1i.jpg

import docx
doc = docx.Document('1.docx')
text_file = open('data.txt','w', encoding='utf8')

print(len(doc.paragraphs))
for txt in doc.paragraphs:
    text_file.write(txt.text+'n')

我认为首先需要定义适当的形式。如果您正在研究NLP项目,则需要在句子中使用句子和每个单词。我认为以下代码有助于从DOCX文件中提取文本。(Python 2.7(

# library (using pip for installing the libraries)
import docxpy
import codecs
# read Input file : Input.docx
file = 'Input.docx'
# extract text from file 
text = docxpy.process(file)
# save the extracted text to a text file 
output_txt = codecs.open('Input.txt','w','utf-8')
output_txt.write(text)
output_txt.close() 

阅读Docxpy文档以获取更多信息:Docxpy网站

最新更新