adverbial_strategy.py 765 B

12345678910111213141516171819202122232425262728293031
  1. from spacy.tokens import Token
  2. from word_processor.strategies.leaf_strategy import dfs
  3. from word_processor.types import DEP_TYPES
  4. def adverbial_strategy(doc) -> [[Token]]:
  5. """
  6. Should return an arrays of variable names based on leaf strategy
  7. :param doc: spacy document
  8. :return Array of strings
  9. """
  10. for token in doc:
  11. if token.dep_ == DEP_TYPES['ROOT']:
  12. suggestions = process_adverbial_clauses(token)
  13. break
  14. return suggestions or []
  15. # todo - this is dfs
  16. def process_adverbial_clauses(graph, result=[], output=[]):
  17. flag = False
  18. for u in graph.children:
  19. flag = True
  20. dfs(u, [*result, graph], output)
  21. if flag is False:
  22. output.append([*result, graph])
  23. return output