Add cli base.
This commit is contained in:
parent
fae11eb875
commit
d23329b019
4
naive-nlu/cli.py
Normal file
4
naive-nlu/cli.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from tree_nlu import cli
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
cli.main()
|
34
naive-nlu/tree_nlu/cli.py
Normal file
34
naive-nlu/tree_nlu/cli.py
Normal 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!")
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user