55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
|
import jsgf
|
||
|
|
||
|
from Modules.NLG_module import NLG
|
||
|
from Modules.DP_module import DP
|
||
|
from Modules.DST_module import DST
|
||
|
from Modules.Book_NLU_module import Book_NLU
|
||
|
from Modules.ML_NLU_module import ML_NLU
|
||
|
|
||
|
import random
|
||
|
import torch
|
||
|
random.seed(42)
|
||
|
torch.manual_seed(42)
|
||
|
|
||
|
if torch.cuda.is_available():
|
||
|
torch.cuda.manual_seed(0)
|
||
|
torch.cuda.manual_seed_all(0)
|
||
|
torch.backends.cudnn.enabled = False
|
||
|
torch.backends.cudnn.benchmark = False
|
||
|
torch.backends.cudnn.deterministic = True
|
||
|
|
||
|
class Janet:
|
||
|
def __init__(self):
|
||
|
self.acts={
|
||
|
0: "greetings",
|
||
|
1: "request",
|
||
|
}
|
||
|
self.arguments={
|
||
|
0: "name"
|
||
|
}
|
||
|
self.nlg = NLG(self.acts, self.arguments)
|
||
|
self.dp = DP(self.acts, self.arguments)
|
||
|
self.dst = DST(self.acts, self.arguments)
|
||
|
self.nlu = Book_NLU(self.acts, self.arguments, jsgf.parse_grammar_file('book.jsgf'))
|
||
|
self.nlu_v2 = ML_NLU(self.acts, self.arguments)
|
||
|
|
||
|
def test(self, command):
|
||
|
out = self.nlu_v2.test_nlu(command)
|
||
|
return out
|
||
|
|
||
|
def process(self, command):
|
||
|
act = self.nlu.analyze(command)
|
||
|
self.dst.store(act)
|
||
|
dest_act = self.dp.choose_tactic(self.dst.transfer())
|
||
|
return self.nlg.change_to_text(dest_act)
|
||
|
|
||
|
|
||
|
def main():
|
||
|
janet = Janet()
|
||
|
while(1):
|
||
|
print('\n')
|
||
|
text = input("Wpisz tekst: ")
|
||
|
print(janet.test(text))
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|