leaf_strategy.py 452 B

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