This repository was archived by the owner on Sep 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·68 lines (55 loc) · 2.26 KB
/
main.py
File metadata and controls
executable file
·68 lines (55 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from functions import *
from operator import itemgetter, attrgetter
# Read from files for more sentences
def get_search_sentences():
search_sentences = []
f = open('test.txt')
if f is not None:
content = f.read()
search_sentences = content.splitlines()
return search_sentences
# search_sentences = get_search_sentences()
# for sentence in search_sentences:
# features = convert_to_features(dictionary, sentence)
# result = predict_category(features)
# print(result[0] + ' => ' + result[1])
# ss = 'កីឡាកររមណីដ្ឋាននៃប្រទេសកម្ពុជានៅខេត្តមណ្ឌលគិរី'
# ss = 'រមណីដ្ឋាន'
# ss = 'រមណីយដ្ឋានធម្មជាតិ'
# ss = 'ធម្មជាតិ'
# ss = 'កីឡាករធម្មជាតិ'
# ss = 'ធម្មជាតិកីឡាករ'
ss = 'afsfsdfsd'
words = ss.split('')
# Clean words
adjust_words = []
for i in range(0, len(words)):
word = clean_word(words[i])
if word != '':
adjust_words.append(word)
words = adjust_words
print(words)
# Do not forget to re-train in case there are new keywords
dictionary = make_keywords_dictionary()
features = sentence_to_features(dictionary, words)
result = predict_category(features)
print('Predict result: ' + str(result[0]) + ' => ' + result[1] + '\n')
if result[0] > 0:
# Display related posts
keyword_posts = []
for keyword in words:
posts = get_posts_by_category_and_keyword(result[0], keyword)
keyword_posts.append([len(posts), keyword, posts])
# sort keyword_posts
sort_keyword_posts = sorted(keyword_posts, key=itemgetter(0), reverse=True)
# Display posts
for sort_keyword_post in sort_keyword_posts:
print('* ' + sort_keyword_post[1] + ':')
for post in sort_keyword_post[2]:
print('\t - ' + str(post[0]) + ' | ' + post[2])
print('---------------------------------------------------------------------------------------------------------')
print('\n Update keywords frequency')
# Update keyword frequency of found category
for keyword in words:
print('- ' + keyword)
update_keyword_frequency(result[0], keyword, True)