Add simple template support

This commit is contained in:
Aleksey Filippov 2022-06-23 22:21:17 +04:00
parent 86e39c28bb
commit 2e55579bb5
2 changed files with 5 additions and 5 deletions

View File

@ -15,9 +15,9 @@ def _main(wav_file: str):
print(f'Text: {text}')
parse_tree: ParseTree = Syntax().get_parse_tree(text)
print(f'Parse tree:\n{parse_tree}')
nouns: List[str] = NLP().get_nouns(parse_tree)
print(f'Nouns:\n{" ".join(nouns)}')
result: str = MyOntology().get_event_description(nouns)
terms: List[str] = NLP().get_by_template(parse_tree, ['NOUN', 'VERB', 'ADJ'])
print(f'Extracted terms:\n{" ".join(terms)}')
result: str = MyOntology().get_event_description(terms)
print(f'Test:\n{result}')

View File

@ -13,10 +13,10 @@ class NLP:
tokens = [token.lemma_ for token in doc]
return ' '.join(tokens)
def get_nouns(self, tree: ParseTree) -> List[str]:
def get_by_template(self, tree: ParseTree, template: List[str]) -> List[str]:
nouns: List[ParseTreeNode] = []
for node in LevelOrderIter(tree.get_tree_root()):
if node.upos != 'NOUN':
if node.upos not in template:
continue
nouns.append(node)
return list(set([self.lemmatizer(noun.lemma) for noun in nouns]))