我正試圖計算我正在編譯的斯瓦希里語語料庫的頻率分析。目前,這是我有:創建一個頻率表,捕獲在一定長度的字符串中流行的子串 - Python
import os
import sys
from collections import Counter
import re
path = 'C:\Python27\corpus\\'
cnt = Counter()
listing = os.listdir(path)
for infile in listing:
print "Currently parsing: " + path + infile
corpus = open(path+infile, "r")
for lines in corpus:
for words in lines.split(' '):
if len(words) >= 2 and re.match("^[A-Za-z]*$", words):
words = words.strip()
cnt[words] += 1
print "Completed parsing: " + path + infile
#output = open(n + ".out", "w")
#print "current file is: " + infile
corpus.close()
#output.close()
for (counter, content) in enumerate(cnt.most_common(1000)):
print str(counter+1) + " " + str(content)
所以這個程序會遍歷所有文件在給定的路徑,在每個文件的文本閱讀,並顯示1000個高頻詞。以下是問題:斯瓦希里語是一種凝聚性語言,它意味着將單詞,後綴和前綴添加到單詞中以傳達諸如時態,因果關係,虛擬語氣,介詞等之類的東西。
因此,動詞根就像'-fanya'意思是'做'可能是nitakufanya - '我要去做你'。 因此,這個頻率列表偏向於連接不使用所述中綴的'for','in','out'這樣的詞。
有沒有一種簡單的方式來看看像'nitakufanya'或'tunafanya'這樣的單詞,並在總數中加入'fanya'這個詞?
看一些潛在的東西:
- 動詞根將在字
- 結束在一個單詞的開頭的主題標誌物可以是以下之一:「妮」( (你),'一'(他/她),'他們'(他們),'我們','我','你'全部
- 主題標記緊隨其後的是時態標記它們是:'na'(現在),'li'(過去),'ta'(未來),'ji'(反身),'nge'(有條件的)
謝謝