在Linux中,可以使用word-count
工具進行多語言統(tǒng)計
python-docx
庫。如果沒有安裝,可以使用以下命令安裝:pip install python-docx
multi_language_wordcount.py
的Python腳本,并添加以下內(nèi)容:import sys
import docx
from collections import defaultdict
def 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_count
def 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格式的多語言文檔。你可以根據(jù)需要修改它以處理其他文件格式。
python multi_language_wordcount.py <file_path>
將<file_path>
替換為你要分析的.docx文件的路徑。腳本將輸出每個單詞及其出現(xiàn)次數(shù)。