forked from lcdevelop/ChatBotCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathword_segment_py3.py
More file actions
56 lines (47 loc) · 1.78 KB
/
word_segment_py3.py
File metadata and controls
56 lines (47 loc) · 1.78 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
# coding:utf-8
import sys
# reload(sys)
# sys.setdefaultencoding( "utf-8" )
import jieba
from jieba import analyse
def segment(input, output):
input_file = open(input, "r")
output_file = open(output, "w")
segments = ""
while True:
line = input_file.readline()
if line:
line = line.strip()
seg_list = jieba.cut(line)
segment = ''
# segments = "GO_ID"
for seg in seg_list:
if seg != '\n':
segment += seg + " "
segments += segment + "\n"
else:
break
output_file.write(segments)
input_file.close()
output_file.close()
def segment_text(text):
line = text.strip()
seg_list = jieba.cut(line)
# segments = ""
segments = []
for str in seg_list:
segments.append(str)
return segments
if __name__ == '__main__':
# if 3 != len(sys.argv):
# print("Usage: ", sys.argv[0], "input output")
# sys.exit(-1)
# segment(sys.argv[1], sys.argv[2])
# segment('chatbotv5/samples/question.big.norepeat', 'chatbotv5/samples/question.big.norepeat.segment')
# segment('chatbotv5/samples/answer.big.norepeat', 'chatbotv5/samples/answer.big.norepeat.segment')
# segment('chatbotv5/samples/backup/question', 'chatbotv5/samples/backup/question.segment')
# segment('chatbotv5/samples/backup/answer', 'chatbotv5/samples/backup/answer.segment')
# segment('chatbotv2/data/question.all.norepeat', 'chatbotv2/data/question.all.norepeat.segment')
# segment('chatbotv2/data/answer.all.norepeat', 'chatbotv2/data/answer.all.norepeat.segment')
# segment('./chatbotv5/samples/answer', './chatbotv5/samples/answer.segment')
segment('./chatbotv5/samples/question', './chatbotv5/samples/question.segment')