From aa489f5fba2bb2bb454ad3f11d8b085c3378e439 Mon Sep 17 00:00:00 2001 From: Jakub Adamski Date: Mon, 23 May 2022 12:32:16 +0200 Subject: [PATCH] semantic parsing init --- semantic_parser/parser.py | 35 ++++++++++++++++++++++++++++++++ semantic_parser/pomoc.jsgf | 9 ++++++++ semantic_parser/pullrequest.jsgf | 11 ++++++++++ 3 files changed, 55 insertions(+) create mode 100644 semantic_parser/parser.py create mode 100644 semantic_parser/pomoc.jsgf create mode 100644 semantic_parser/pullrequest.jsgf diff --git a/semantic_parser/parser.py b/semantic_parser/parser.py new file mode 100644 index 0000000..2396f61 --- /dev/null +++ b/semantic_parser/parser.py @@ -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) \ No newline at end of file diff --git a/semantic_parser/pomoc.jsgf b/semantic_parser/pomoc.jsgf new file mode 100644 index 0000000..293ec1a --- /dev/null +++ b/semantic_parser/pomoc.jsgf @@ -0,0 +1,9 @@ +#JSGF V1.0 UTF-8 pl; + +grammar pomoc; + +public = jakie są dostępne {functions} | w czym możesz mi {help}; + + = pomoc | pomóc; + + = komenda | komendy | funckja | funkcje | polecenie | polecenia; diff --git a/semantic_parser/pullrequest.jsgf b/semantic_parser/pullrequest.jsgf new file mode 100644 index 0000000..6c6a78a --- /dev/null +++ b/semantic_parser/pullrequest.jsgf @@ -0,0 +1,11 @@ +#JSGF V1.0 UTF-8 pl; + +grammar pullrequest; + +public = {action} ; + + = [nowe] | [nowych]; + + = pull requesty | pull requestów; + + = ile jest | jakie są; \ No newline at end of file