Skip to content

Commit aa74181

Browse files
updated tf_idf_generator.py
1 parent 8b0cd03 commit aa74181

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tf_idf_generator.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'''@Author: Anurag Kumar(mailto:anuragkumarak95@gmail.com)
22
This module is used for generating a TF-IDF file or values from a list of files that contains docs.
33
4+
What is TF-IDF : https://en.wikipedia.org/wiki/Tf%E2%80%93idf
5+
46
python:
57
- 3.5
68
@@ -26,10 +28,11 @@
2628
##END(NOT INCLUDED)
2729
2830
here, every line represents a document.
31+
32+
have fun, cheers.
2933
'''
3034
import os, math, pickle
3135
from colorama import Fore, Style
32-
import pickle
3336

3437
switcher = {
3538
'r':Fore.RED,
@@ -118,8 +121,8 @@ def find_tf_idf(file_names=['./../test/testdata'],prev_file_path=None, dump_path
118121

119122
# dump if a dir-path is given
120123
if dump_path:
121-
if dump_path[-8:] == 'tfidfpkl':
122-
pickle.dump((idf,tf_idf),open(dump_path,'wb'),protocol=pickle.HIGHEST_PROTOCOL)
123-
print(TAG,'Dumping TF-IDF vars @',dump_path)
124+
if dump_path[-8:] != 'tfidfpkl': raise Exception(TAG+"Please provide a .tfidfpkl file_path, it is the standard format of this module.")
125+
pickle.dump((idf,tf_idf),open(dump_path,'wb'),protocol=pickle.HIGHEST_PROTOCOL)
126+
print(TAG,'Dumping TF-IDF vars @',dump_path)
124127
return idf,tf_idf
125128

0 commit comments

Comments
 (0)