Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hiber committed Oct 25, 2018
1 parent e30de94 commit c816f6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions demo_run.py
Expand Up @@ -40,12 +40,12 @@ def load_data_2_root(data):


if __name__ == "__main__":
root_name = basedir + "data/root.pkl"
root_name = basedir + "/data/root.pkl"
stopwords = get_stopwords()
if os.path.exists(root_name):
root = load_model(root_name)
else:
dict_name = basedir + 'data/dict.txt'
dict_name = basedir + '/data/dict.txt'
word_freq = load_dictionary(dict_name)
root = TrieNode('*', word_freq)
save_model(root, root_name)
Expand Down
1 change: 1 addition & 0 deletions model.py
Expand Up @@ -81,6 +81,7 @@ def add(self, word):
length = len(word)
node = self.root
if length == 3:
word = list(word)
word[0], word[1], word[2] = word[1], word[2], word[0]

for count, char in enumerate(word):
Expand Down
5 changes: 4 additions & 1 deletion utils.py
Expand Up @@ -15,7 +15,10 @@ def get_stopwords():


def generate_ngram(input_list, n):
return zip(*[input_list[i:] for i in range(n)])
result = []
for i in range(1, n+1):
result.extend(zip(*[input_list[j:] for j in range(i)]))
return result


def load_dictionary(filename):
Expand Down

0 comments on commit c816f6a

Please sign in to comment.