Commit c2bc75b4 authored by Tags's avatar Tags

Chang self.tags (list) to self.tags_dict (dictionary)

parent 5163f92a
......@@ -38,9 +38,14 @@ class Classifier:
rez = self.db.store_result()
tags = list()
for id, description in rez.fetch_row(maxrows=0):
tags.append((id, description))
tags.append((int(id), description))
self.tags_dict = dict(tags)
self.tags = tags
# print(len(tags), tags)
# print('tags array = ', len(self.tags), self.tags)
# print(self.tags_dict)
# print(self.tags_dict[355])
# exit(0)
del tags
# train_data = []
......@@ -176,10 +181,13 @@ class Classifier:
# print(sorted_probabl_probabl)
for item in sorted_probabl_probabl:
if item[1] < persantage / 100: continue
# print (item[0], item[1], self.tags[item[0] - 1][1].decode ("ascii", 'ignore'), end=", ")
# print (item[0], end=", ")
# print(int(item[1] * 1000) / 10, end=", ")
# print("item in my tags: ", item[0] - 1)
# print(self.tags_dict[item[0]].decode("ascii", 'ignore'), end=", ")
vector_accordance.append(
(item[0], int(item[1] * 1000) / 10,
self.tags[item[0] - 1][1].decode("ascii", 'ignore')))
self.tags_dict[item[0]].decode("ascii", 'ignore')))
return vector_accordance
......@@ -247,12 +255,12 @@ class Classifier:
if file_info == None:
return False
file_info.write("number of features = " + str(len(self.vectorizer.get_feature_names())) + '\n')
file_info.write("Quantity of tags = " + str(len(self.tags)) + '\n')
file_info.write("Quantity of tags = " + str(len(self.tags_dict)) + '\n')
file_info.write("\ndata_tag_frequency.csv ---- Model data matrix --- " + \
str(self.X_data.shape) + "\n")
file_info.write("\nDictionary.txt -- Total number words in is---" + str(
len(self.vectorizer.get_feature_names())) + '\n')
file_info.write("\ntags.txt --- Total number is ---" + str(len(self.tags)) + '\n')
file_info.write("\ntags.txt --- Total number is ---" + str(len(self.tags_dict)) + '\n')
file_info.close()
# save model matrix
......@@ -280,7 +288,7 @@ class Classifier:
file_info_tags = open(directory + "/tags.txt", "w")
if file_info_tags == None:
return False
for text1, text2 in self.tags:
for text1, text2 in self.tags_dict:
file_info_tags.write(text1 + " " + text2.decode('ascii', "ignore") + "\n")
file_info_tags.close()
return True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment