瀏覽代碼

add adverbial strategy wip

Nikos Atlas 2 年之前
父節點
當前提交
6a5506968b

+ 1 - 1
.idea/word-recommender.iml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <module type="PYTHON_MODULE" version="4">
   <component name="NewModuleRootManager">
-    <content url="file://$MODULE_DIR$/../word_recommender" />
+    <content url="file://$MODULE_DIR$" />
     <orderEntry type="jdk" jdkName="Python 3.8 (word-recommender)" jdkType="Python SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>

+ 14 - 0
document.txt

@@ -58,3 +58,17 @@ const filterAndSanitize = (values: Values): Object =>
  */
 zoomLevels: ZoomLevelType
 
+
+
+### React-DOM variable names
+// Setter for attempting to hydrate synchronously
+setAttemptSynchronousHydration(attemptSynchronousHydration);
+// Setter for attempting to hydrate discretely
+setAttemptDiscreteHydration(attemptDiscreteHydration);
+// Setter for attempting to hydrate continously
+setAttemptContinuousHydration(attemptContinuousHydration);
+// Setter for priority of attempting hydration
+setAttemptHydrationAtCurrentPriority(attemptHydrationAtCurrentPriority);
+// Setter for getCurrentUpdate priority
+setGetCurrentUpdatePriority(getCurrentUpdatePriority);
+setAttemptHydrationAtPriority(runWithPriority);

+ 4 - 0
word_processor/strategies/__init__.py

@@ -1,5 +1,9 @@
 from .leaf_strategy import leaf_strategy
+from .leaf_no_preps_strategy import leaf_no_prep_strategy
+from .adverbial_strategy import adverbial_strategy
 
 __all__ = [
     'leaf_strategy',
+    'adverbial_strategy',
+    'leaf_no_prep_strategy',
 ]

+ 31 - 0
word_processor/strategies/adverbial_strategy.py

@@ -0,0 +1,31 @@
+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

+ 8 - 3
word_processor/tests/test.py

@@ -13,10 +13,11 @@ from spacy import displacy
     [
         # 'Regex for redacted phone numbers with extra info for PlayStation',
         # 'Two days ago i was shocked by a red pair of trousers',
-        'Setting priority for attempting hydration',
+        #'Setting priority for attempting hydration',
         # 'Attempting to set hydration priority',
         # 'file Cache Provider get Cache Dir',
-        #'Setters Value Animator Animator Update Listener'
+        #'Setters Value Animator Animator Update Listener',
+        'Stick element after scroll has passed the element'
     ]
 )
 def test_antonyms(snapshot, text):
@@ -29,5 +30,9 @@ def test_antonyms(snapshot, text):
         text_results.append([token.lemma_ for token in suggestion])
 
     presented_results = generator.present()
-    # displacy.serve(generator.doc, port=5001)
+    displacy.serve(generator.doc, port=5001)
     print(presented_results)
+
+
+# ADVCL
+# follow adverbial clauses and discard the verb

+ 26 - 0
word_processor/tests/test_adverbial_strategy.py

@@ -0,0 +1,26 @@
+import json
+
+import pytest
+
+import spacy
+
+from word_processor.generators import Generator
+from word_processor.strategies import leaf_strategy, adverbial_strategy
+
+nlp = spacy.load("en_core_web_trf")
+
+
[email protected]('text', [
+    # 'Regex for redacted phone numbers with extra info for PlayStation',
+    'Stick element after scroll has passed the element',
+])
+def test_adverbial_strategy(snapshot, text):
+    generator = Generator(text=text, strategy=adverbial_strategy)
+
+    results = generator.suggest()
+
+    text_results = []
+    for suggestion in results:
+        text_results.append([token.lemma_ for token in suggestion])
+
+    assert text_results == snapshot