Mikhail Korobov avatar Mikhail Korobov committed a7235eb

remove_untouched flag for rule_engine.apply_rules

Comments (0)

Files changed (2)


             if r and not r.startswith('#')]
-def apply_rules(parsed_rules, tag):
-    """ Transform ``tag`` according to ``parsed_rules``. """
+def apply_rules(parsed_rules, tag, remove_untouched=True):
+    """
+    Transform ``tag`` according to ``parsed_rules``.
+    If ``remove_untouched`` is true the grammemes that
+    were not converted are removed.
+    """
     grammemes = set(tag)
         grammemes -= from_set
         #print('res: ', tag)
-    return [g.lstrip('_') for g in tag if g not in grammemes]
+    return [g.lstrip('_') for g in tag
+            if not remove_untouched or g not in grammemes]


 plur => pl
-def _transform_tag(tag):
+def _transform_tag(tag, **kwargs):
     rules = rule_engine.parse(RULES2)
     return ','.join(
-        rule_engine.apply_rules(rules, tag.split(','))
+        rule_engine.apply_rules(rules, tag.split(','), **kwargs)
 def test_parsing():
         (['|'], ['_='])
+@pytest.mark.parametrize(("in_tag", "out_tag"), [
     ('NOUN,sing,foo', 'S,sg'),
     ('ADJS', 'A,brev'),
     ('ADJS,sing', 'A,brev,sg'),
     ('COMP', 'A,comp'),
     ('COMP,sing,Cmp2,plur', 'A,sg,pl'),
     ('COMP,sing,Supr,plur,vupr', 'A,sg,supr,dupr,pl'),
+def test_apply(in_tag, out_tag):
+    assert _transform_tag(in_tag) == out_tag
-@pytest.mark.parametrize(("in_tag", "out_tag"), TEST_DATA)
+@pytest.mark.parametrize(("in_tag", "out_tag"), [
+    ('NOUN,sing,foo', 'S,sg,foo'),
+    ('ADJS', 'A,brev'),
+    ('ADJS,sing', 'A,brev,sg'),
+    ('COMP', 'A,comp'),
+    ('COMP,sing,Cmp2,plur', 'A,sg,pl'),
+    ('COMP,sing,Supr,plur,vupr', 'A,sg,supr,dupr,pl,vupr'),
 def test_apply(in_tag, out_tag):
-    assert _transform_tag(in_tag) == out_tag
+    assert _transform_tag(in_tag, remove_untouched=False) == out_tag
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.