Add cli base.

This commit is contained in:
kenkeiras 2017-09-17 22:01:59 -04:00
parent fae11eb875
commit d23329b019
4 changed files with 40 additions and 0 deletions

4
naive-nlu/cli.py Normal file
View File

@ -0,0 +1,4 @@
from tree_nlu import cli
if __name__ == '__main__':
cli.main()

34
naive-nlu/tree_nlu/cli.py Normal file
View File

@ -0,0 +1,34 @@
import logging
from .knowledge_base import KnowledgeBase
from .tests import gac_100
from .modifiable_property import (
ModifiableProperty,
ModifiablePropertyWithAst,
is_modifiable_property,
)
bye_phrases = ['bye', 'exit']
def main():
knowledge = gac_100.main()
while True:
try:
data = input("> ").strip()
except EOFError:
print("bye")
break
if data.lower() in bye_phrases:
break
if not data:
continue
ret = knowledge.process(data)
if ret:
result, _, _ = ret
if not is_modifiable_property(result):
print("<", result)
else:
result.setter()
print("OK")
print("< Bye!")

View File

@ -155,3 +155,4 @@ def main():
test_assumption(False, knowledge, queryFalse) test_assumption(False, knowledge, queryFalse)
test_assumption(True, knowledge, queryTrue) test_assumption(True, knowledge, queryTrue)
return knowledge

View File

@ -741,3 +741,4 @@ def main():
raise NotImplementedError('Example type: {}'.format(example_type)) raise NotImplementedError('Example type: {}'.format(example_type))
print("\r\x1b[K", end='') print("\r\x1b[K", end='')
return knowledge