12345678910111213141516171819202122232425262728293031 |
- from spacy.tokens import Token
- from word_processor.strategies.leaf_strategy import dfs
- from word_processor.types import DEP_TYPES
- def adverbial_strategy(doc) -> [[Token]]:
- """
- Should return an arrays of variable names based on leaf strategy
- :param doc: spacy document
- :return Array of strings
- """
- for token in doc:
- if token.dep_ == DEP_TYPES['ROOT']:
- suggestions = process_adverbial_clauses(token)
- break
- return suggestions or []
- # todo - this is dfs
- def process_adverbial_clauses(graph, result=[], output=[]):
- flag = False
- for u in graph.children:
- flag = True
- dfs(u, [*result, graph], output)
- if flag is False:
- output.append([*result, graph])
- return output
|