Last active
August 29, 2015 13:57
-
-
Save nosada/9465753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chat: | |
vocabs = [ | |
"ああ、そうなんだー", | |
"へー", | |
"すごいねー" | |
] | |
negative = "いや、それは違うんじゃないかなーw" | |
farewell = ["またねー", "じゃあねー"] | |
def response(self): | |
"""return response from self.vocabs at random. | |
if self.count becomes larger than threshold given initially, | |
return soft-negative response.""" | |
import random | |
r = random.choice(self.rindex) | |
if self.count > self.threshold: | |
self.count = 0 | |
return self.negative | |
else: | |
self.count += 1 | |
return self.vocabs[r] | |
def bye(self): | |
"""return farewell from self.farewell at random.""" | |
import random | |
r = random.choice(self.findex) | |
return self.farewell[r] | |
def __init__(self, n): | |
"""initialize class Chat. | |
set parameters in Chat.""" | |
self.count = 0 | |
self.threshold = n | |
self.rindex = [i for i in range(len(self.vocabs))] | |
self.findex = [i for i in range(len(self.farewell))] | |
def main(n): | |
C = Chat(n) | |
ibuf = obuf = "" | |
byebye = False | |
print("press 'Q' to quit") | |
while True: | |
ibuf = input('>') | |
if ibuf == "q" or ibuf == "Q": | |
byebye = True | |
obuf = C.bye() | |
else: | |
obuf = C.response() | |
print("Res. >> " + obuf) | |
if byebye: | |
sys.exit() | |
return | |
if __name__ == '__main__': | |
import sys | |
if len(sys.argv) < 2: | |
print("give me threshold", file = sys.stderr) | |
sys.exit() | |
main(int(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment