2 Achegas e8b56ba3c2 ... d31bf47615

Autor SHA1 Mensaxe Data
  sxoinas12 d31bf47615 Merge branch 'master' of http://onarbooks.com/nikatlas/word-processor %!s(int64=2) %!d(string=hai) anos
  sxoinas12 3303c2346e create leaf_strategy with basic dfs implementation %!s(int64=2) %!d(string=hai) anos
Modificáronse 2 ficheiros con 20 adicións e 6 borrados
  1. 2 5
      src/__tests__/test_leaf_strategy.py
  2. 18 1
      src/strategies/leaf_strategy.py

+ 2 - 5
src/__tests__/test_leaf_strategy.py

@@ -3,6 +3,7 @@ import pytest
 import spacy
 from spacy import displacy
 
+
 from src.generators import Generator
 from src.strategies import leaf_strategy
 
@@ -15,10 +16,6 @@ def test_leaf_strategy(text, expected):
     generator = Generator(text=text, strategy=leaf_strategy)
 
     results = generator.suggest()
-
+    displacy.serve(docs=[generator.doc])
     doc = generator.doc
-    for token in doc:
-        print(token)
-
-    print(results)
     # assert result == expected

+ 18 - 1
src/strategies/leaf_strategy.py

@@ -1,3 +1,6 @@
+import itertools
+
+
 def leaf_strategy(doc):
     """
     Should return an arrays of variable names based on leaf strategy
@@ -6,4 +9,18 @@ def leaf_strategy(doc):
     :return Array of strings
     """
 
-    pass
+    for token in doc:
+        print(token.text, token.pos_, token.dep_)
+
+    suggestions = dfs(doc[0])
+    return suggestions
+
+
+def dfs(graph, result=[], output=[]):
+    flag = False
+    for u in graph.children:
+        flag = True
+        dfs(u, [*result, graph.text], output)
+    if flag is False:
+        output.append([*result, graph.text])
+    return output