semantic parsing init

This commit is contained in:
Jakub Adamski 2022-05-23 12:32:16 +02:00
parent 6b285c68f4
commit aa489f5fba
3 changed files with 55 additions and 0 deletions

35
semantic_parser/parser.py Normal file
View File

@ -0,0 +1,35 @@
import jsgf
book_grammar = jsgf.parse_grammar_file('pullrequest.jsgf')
def get_dialog_act(rule):
slots = []
get_slots(rule.expansion, slots)
return {'act': rule.grammar.name, 'slots': slots}
def get_slots(expansion, slots):
if expansion.tag != '':
slots.append((expansion.tag, expansion.current_match))
return
for child in expansion.children:
get_slots(child, slots)
if not expansion.children and isinstance(expansion, jsgf.NamedRuleRef):
get_slots(expansion.referenced_rule.expansion, slots)
def nlu(utterance):
matched = book_grammar.find_matching_rules(utterance)
if matched:
return get_dialog_act(matched[0])
else:
return {'act': 'null', 'slots': []}
#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('ile jest nowych pull requestów')
print(result)

View File

@ -0,0 +1,9 @@
#JSGF V1.0 UTF-8 pl;
grammar pomoc;
public <pomoc_zapytanie> = jakie są dostępne <functions> {functions} | w czym możesz mi <help> {help};
<help> = pomoc | pomóc;
<functions> = komenda | komendy | funckja | funkcje | polecenie | polecenia;

View File

@ -0,0 +1,11 @@
#JSGF V1.0 UTF-8 pl;
grammar pullrequest;
public <pull_request_zapytanie> = <action> {action} <new> <pullrequest>;
<new> = [nowe] | [nowych];
<pullrequest> = pull requesty | pull requestów;
<action> = ile jest | jakie są;