在Linux中,可以使用word-count工具进行多语言统计
python-docx库。如果没有安装,可以使用以下命令安装:pip install python-docx创建一个名为multi_language_wordcount.py的Python脚本,并添加以下内容:import sysimport docxfrom collections import defaultdictdef count_words(file_path): word_count = defaultdict(int) doc = docx.Document(file_path) for paragraph in doc.paragraphs: for run in paragraph.runs: if run.text: words = run.text.split() for word in words: word_count[word.lower()] += 1 return word_countdef main(): if len(sys.argv) != 2: print("Usage: python multi_language_wordcount.py <file_path>") sys.exit(1) file_path = sys.argv[1] if not file_path.endswith('.docx'): print("Error: File must be a .docx file") sys.exit(1) word_count = count_words(file_path) for word, count in word_count.itEMS(): print(f"{word}: {count}")if __name__ == "__main__": main()这个脚本可以处理.docx格式的多语言文档。你可以根据需要修改它以处理其他文件格式。
保存脚本并在终端中运行:python multi_language_wordcount.py <file_path>将<file_path>替换为你要分析的.docx文件的路径。脚本将输出每个单词及其出现次数。