Code refactoring

This commit is contained in:
Aleksey Filippov 2022-01-25 14:12:45 +04:00
parent 71e843801f
commit b18e17e961
5 changed files with 10 additions and 10 deletions

View File

@ -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__':

View File

@ -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())

View File

@ -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

View File

@ -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)

View File

@ -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))