-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathget_dict_for_text.py
29 lines (21 loc) · 1.05 KB
/
get_dict_for_text.py
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
from gensim import corpora
from collections import defaultdict
documents = ["Human machine interface for lab abc computer applications",
"A survey of user opinion of computer system response time",
"The EPS user interface management system",
"System and human system engineering testing of EPS",
"Relation of user perceived response time to error measurement",
"The generation of random binary unordered trees",
"The intersection graph of paths in trees",
"Graph minors IV Widths of trees and well quasi ordering",
"Graph minors A survey"]
# word split
doc_text_list = []
for d in documents:
doc_text_list.append( d.split(' ') )
# get dict
dic = corpora.Dictionary(doc_text_list)
print(dic)# Dictionary(45 unique tokens: ['System', 'Graph', 'machine', 'quasi', 'A']...)
# dict property
print(dic.token2id)# word:word_id, such as {'abc': 1, 'applications': 2, 'computer': 3}
print(dic.dfs)# word_id:word_count, such as {1: 1, 2: 1}