Большое обновление всего проекта
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
class NgramInfo:
|
||||
def __init__(self, id):
|
||||
self.id = id
|
||||
self.frequency = 1
|
||||
|
||||
class NgramsDictionary:
|
||||
def __init__(self, ngram_size):
|
||||
self.ngrams = {}
|
||||
self.ngram_size = ngram_size
|
||||
self.last_id = 0
|
||||
|
||||
def update(self, words):
|
||||
for last_word_index in range(self.ngram_size, len(words) + 1):
|
||||
ngram = ""
|
||||
for current_word_index in range(0, self.ngram_size):
|
||||
ngram += words[last_word_index - self.ngram_size + current_word_index] + " "
|
||||
|
||||
self.addNgram(ngram[:-1])
|
||||
|
||||
def addNgram(self, ngram):
|
||||
if ngram in self.ngrams:
|
||||
self.ngrams[ngram].frequency += 1
|
||||
else:
|
||||
word_info = NgramInfo(self.last_id)
|
||||
self.last_id += 1
|
||||
self.ngrams[ngram] = word_info
|
||||
@@ -0,0 +1,20 @@
|
||||
class Constants:
|
||||
whitespace = r"\s*"
|
||||
unknown_begin_part = r"<(\d{1,2})>"
|
||||
month = r"([A-Za-z]{3})"
|
||||
number = r"(\d+)"
|
||||
time = r"(\d{2}:\d{2}:\d{2})"
|
||||
word = r"(\S+)"
|
||||
anything = r"(.*)"
|
||||
|
||||
class Pattern:
|
||||
def __int__(self):
|
||||
self.parts = []
|
||||
|
||||
def __str__(self):
|
||||
result = ""
|
||||
|
||||
for part in self.parts:
|
||||
result += part[0] + Constants.whitespace
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user