leaf_strategy.py 480 B

1234567891011121314151617181920212223
  1. import itertools
  2. def leaf_strategy(doc):
  3. """
  4. Should return an arrays of variable names based on leaf strategy
  5. :param doc: spacy document
  6. :return Array of strings
  7. """
  8. suggestions = dfs(doc[0])
  9. return suggestions
  10. def dfs(graph, result=[], output=[]):
  11. flag = False
  12. for u in graph.children:
  13. flag = True
  14. dfs(u, [*result, graph.text], output)
  15. if flag is False:
  16. output.append([*result, graph.text])
  17. return output