notifications & parser improvements
This commit is contained in:
parent
41cc2c4cc4
commit
18e586bfca
11
semantic_parser/gramatics/notification.jsgf
Normal file
11
semantic_parser/gramatics/notification.jsgf
Normal file
@ -0,0 +1,11 @@
|
||||
#JSGF V1.0 UTF-8 pl;
|
||||
|
||||
grammar notifications;
|
||||
|
||||
public <notifications> = pokaż mi [nowe] powiadomienia [<time>];
|
||||
|
||||
<time> = z [ostatniego | ostatnich] <timeunit> {timeunit};
|
||||
|
||||
<timeunit> = miesiąca | tygodnia | dnia | <liczba> dni | <liczba> tygodni | <liczba> miesięcy;
|
||||
|
||||
<liczba> = dwóch | trzech | czterech | pięciu | sześciu | siedmiu | ośmiu | dziewięciu;
|
@ -1,6 +1,15 @@
|
||||
import jsgf
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
|
||||
book_grammar = jsgf.parse_grammar_file('pullrequest.jsgf')
|
||||
mypath = "./gramatics/"
|
||||
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
|
||||
|
||||
grammars = []
|
||||
|
||||
for grammarFile in onlyfiles:
|
||||
grammar = jsgf.parse_grammar_file(mypath + grammarFile)
|
||||
grammars.append(grammar)
|
||||
|
||||
def get_dialog_act(rule):
|
||||
slots = []
|
||||
@ -19,7 +28,11 @@ def get_slots(expansion, slots):
|
||||
get_slots(expansion.referenced_rule.expansion, slots)
|
||||
|
||||
def nlu(utterance):
|
||||
matched = book_grammar.find_matching_rules(utterance)
|
||||
matched = None
|
||||
for grammar in grammars:
|
||||
matched = grammar.find_matching_rules(utterance)
|
||||
if matched:
|
||||
break
|
||||
|
||||
if matched:
|
||||
return get_dialog_act(matched[0])
|
||||
@ -30,6 +43,8 @@ def nlu(utterance):
|
||||
#result = nlu('jakie są dostępne funkcje')
|
||||
#result = nlu('w czym możesz mi pomóc')
|
||||
|
||||
result = nlu('jakie są nowe pull requesty')
|
||||
#result = nlu('jakie są nowe pull requesty')
|
||||
#result = nlu('ile jest nowych pull requestów')
|
||||
|
||||
result = nlu('pokaż mi nowe powiadomienia z trzech tygodni')
|
||||
print(result)
|
Loading…
Reference in New Issue
Block a user