-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcake.py
40 lines (34 loc) · 990 Bytes
/
cake.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
30
31
32
33
34
35
36
37
38
39
40
from knowledge import *
def rmSym(input):
result = ''
for char in input.lower():
if ('a' <= char and char <= 'z') or (char == ' '):
result += char
return result
def rmNoiseWords(input):
result = []
for item in input:
if not (item in noise_words):
result.append(item)
return result
def compare(input, keywords):
result = 0
for item in input:
for keyword in keywords:
if item == keyword:
result += 1
return result
def search(input):
input = rmNoiseWords(rmSym(input).split(' '))
temp = []
for i in range(0, len(knowledge_base)):
keywords = knowledge_base[i][0]
if len(input) >= len(keywords):
temp.append(compare(input, keywords))
else:
temp.append(0)
max_tmp = max(temp)
if max_tmp != 0:
return knowledge_base[temp.index(max_tmp)][1]
else:
return "Sorry, but i don't know its answer."