From b18e17e96197038643221324b974e2060d7204dc Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Tue, 25 Jan 2022 14:12:45 +0400 Subject: [PATCH] Code refactoring --- src/main.py | 8 ++++---- src/nlp.py | 6 +++--- src/ontology.py | 2 +- src/speech.py | 2 +- src/syntax.py | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.py b/src/main.py index 136747a..f72022e 100644 --- a/src/main.py +++ b/src/main.py @@ -17,16 +17,16 @@ def _main(): exit(1) # wav_file = sys.argv[1] # speech_server = 'http://vosk.athene.tech' - # text = Speech().run(wav_file, speech_server) + # text = Speech().run_recognition(wav_file, speech_server) text = 'не могу оплатить из-за ограничений карты' print(f'Text: {text}') syntax_server = 'http://syntaxnet.athene.tech' - parse_tree = Syntax().run(text, syntax_server) + parse_tree = Syntax().get_parse_tree(text, syntax_server) print(f'Parse tree:\n{parse_tree}') - nouns = NLP().run(parse_tree) + nouns = NLP().get_nouns(parse_tree) print(f'Nouns:\n{nouns}') onto = Ontology() - print(f'Test: {onto.run()}') + print(f'Test: {onto.get_event()}') if __name__ == '__main__': diff --git a/src/nlp.py b/src/nlp.py index 504516a..70c1e8d 100644 --- a/src/nlp.py +++ b/src/nlp.py @@ -14,13 +14,13 @@ class NLP: tokens = [token.lemma_ for token in doc] return ' '.join(tokens) - def _get_nouns(self, tree: ParseTreeNode) -> str: + def _get_nouns(self, tree: ParseTreeNode) -> List[str]: nouns: List[ParseTreeNode] = [] for node in LevelOrderIter(tree): if node.upos != 'NOUN': continue nouns.append(node) - return self._lemmatizer(' '.join([noun.lemma for noun in nouns])) + return [self._lemmatizer(noun.lemma) for noun in nouns] - def run(self, tree: ParseTree) -> str: + def get_nouns(self, tree: ParseTree) -> List[str]: return self._get_nouns(tree.get_tree_root()) diff --git a/src/ontology.py b/src/ontology.py index 9ff91f4..dc6fb0e 100644 --- a/src/ontology.py +++ b/src/ontology.py @@ -5,5 +5,5 @@ class Ontology: def __init__(self) -> None: self._onto = get_ontology("file://./ontology.owl").load() - def run(self) -> str: + def get_event(self) -> str: return self._onto.Concept diff --git a/src/speech.py b/src/speech.py index f391b71..daa02db 100644 --- a/src/speech.py +++ b/src/speech.py @@ -36,5 +36,5 @@ class Speech: return result['text'] if not result['code'] else f'Server error: {result}' - def run(self, wav_file: str, server: str) -> str: + def run_recognition(self, wav_file: str, server: str) -> str: return self.__stt(wav_file, server) diff --git a/src/syntax.py b/src/syntax.py index 51bda3f..a416bc2 100644 --- a/src/syntax.py +++ b/src/syntax.py @@ -20,5 +20,5 @@ class Syntax: return result - def run(self, text: str, server: str) -> ParseTree: + def get_parse_tree(self, text: str, server: str) -> ParseTree: return ParseTree(self.__parsey(text, server))