semantic parsing init
This commit is contained in:
parent
6b285c68f4
commit
aa489f5fba
35
semantic_parser/parser.py
Normal file
35
semantic_parser/parser.py
Normal 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)
|
9
semantic_parser/pomoc.jsgf
Normal file
9
semantic_parser/pomoc.jsgf
Normal 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;
|
11
semantic_parser/pullrequest.jsgf
Normal file
11
semantic_parser/pullrequest.jsgf
Normal 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ą;
|
Loading…
Reference in New Issue
Block a user