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