Deleted logging
This commit is contained in:
parent
809d543750
commit
2b28cd6594
20
eliza.py
20
eliza.py
@ -1,12 +1,9 @@
|
|||||||
import logging
|
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
|
||||||
try: input = raw_input
|
try: input = raw_input
|
||||||
except NameError: pass
|
except NameError: pass
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class Key:
|
class Key:
|
||||||
def __init__(self, word, weight, decomps):
|
def __init__(self, word, weight, decomps):
|
||||||
@ -144,24 +141,17 @@ class Eliza:
|
|||||||
for decomp in key.decomps:
|
for decomp in key.decomps:
|
||||||
results = self._match_decomp(decomp.parts, words)
|
results = self._match_decomp(decomp.parts, words)
|
||||||
if results is None:
|
if results is None:
|
||||||
log.debug('Decomp did not match: %s', decomp.parts)
|
|
||||||
continue
|
continue
|
||||||
log.debug('Decomp matched: %s', decomp.parts)
|
|
||||||
log.debug('Decomp results: %s', results)
|
|
||||||
results = [self._sub(words, self.posts) for words in results]
|
results = [self._sub(words, self.posts) for words in results]
|
||||||
log.debug('Decomp results after posts: %s', results)
|
|
||||||
reasmb = self._next_reasmb(decomp)
|
reasmb = self._next_reasmb(decomp)
|
||||||
log.debug('Using reassembly: %s', reasmb)
|
|
||||||
if reasmb[0] == 'goto':
|
if reasmb[0] == 'goto':
|
||||||
goto_key = reasmb[1]
|
goto_key = reasmb[1]
|
||||||
if not goto_key in self.keys:
|
if not goto_key in self.keys:
|
||||||
raise ValueError("Invalid goto key {}".format(goto_key))
|
raise ValueError("Invalid goto key {}".format(goto_key))
|
||||||
log.debug('Goto key: %s', goto_key)
|
|
||||||
return self._match_key(words, self.keys[goto_key])
|
return self._match_key(words, self.keys[goto_key])
|
||||||
output = self._reassemble(reasmb, results)
|
output = self._reassemble(reasmb, results)
|
||||||
if decomp.save:
|
if decomp.save:
|
||||||
self.memory.append(output)
|
self.memory.append(output)
|
||||||
log.debug('Saved to memory: %s', output)
|
|
||||||
continue
|
continue
|
||||||
return output
|
return output
|
||||||
return None
|
return None
|
||||||
@ -173,33 +163,26 @@ class Eliza:
|
|||||||
text = re.sub(r'\s*\.+\s*', ' . ', text)
|
text = re.sub(r'\s*\.+\s*', ' . ', text)
|
||||||
text = re.sub(r'\s*,+\s*', ' , ', text)
|
text = re.sub(r'\s*,+\s*', ' , ', text)
|
||||||
text = re.sub(r'\s*;+\s*', ' ; ', text)
|
text = re.sub(r'\s*;+\s*', ' ; ', text)
|
||||||
log.debug('After punctuation cleanup: %s', text)
|
|
||||||
|
|
||||||
words = [w for w in text.split(' ') if w]
|
words = [w for w in text.split(' ') if w]
|
||||||
log.debug('Input: %s', words)
|
|
||||||
|
|
||||||
words = self._sub(words, self.pres)
|
words = self._sub(words, self.pres)
|
||||||
log.debug('After pre-substitution: %s', words)
|
|
||||||
|
|
||||||
keys = [self.keys[w.lower()] for w in words if w.lower() in self.keys]
|
keys = [self.keys[w.lower()] for w in words if w.lower() in self.keys]
|
||||||
keys = sorted(keys, key=lambda k: -k.weight)
|
keys = sorted(keys, key=lambda k: -k.weight)
|
||||||
log.debug('Sorted keys: %s', [(k.word, k.weight) for k in keys])
|
|
||||||
|
|
||||||
output = None
|
output = None
|
||||||
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
output = self._match_key(words, key)
|
output = self._match_key(words, key)
|
||||||
if output:
|
if output:
|
||||||
log.debug('Output from key: %s', output)
|
|
||||||
break
|
break
|
||||||
if not output:
|
if not output:
|
||||||
if self.memory:
|
if self.memory:
|
||||||
index = random.randrange(len(self.memory))
|
index = random.randrange(len(self.memory))
|
||||||
output = self.memory.pop(index)
|
output = self.memory.pop(index)
|
||||||
log.debug('Output from memory: %s', output)
|
|
||||||
else:
|
else:
|
||||||
output = self._next_reasmb(self.keys['xnone'].decomps[0])
|
output = self._next_reasmb(self.keys['xnone'].decomps[0])
|
||||||
log.debug('Output from xnone: %s', output)
|
|
||||||
|
|
||||||
return " ".join(output)
|
return " ".join(output)
|
||||||
|
|
||||||
@ -230,5 +213,4 @@ def main():
|
|||||||
eliza.run()
|
eliza.run()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig()
|
main()
|
||||||
main()
|
|
Loading…
Reference in New Issue
Block a user