Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sequencial optional #71

Merged
merged 3 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/71.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `-` bug when it is used as stand alone word
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rita-dsl"
version = "0.5.3"
version = "0.5.4"
description = "DSL for building language rules"
authors = [
"Šarūnas Navickas <zaibacu@gmail.com>"
Expand Down
2 changes: 1 addition & 1 deletion rita/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

logger = logging.getLogger(__name__)

__version__ = (0, 5, 3, os.getenv("VERSION_PATCH"))
__version__ = (0, 5, 4, os.getenv("VERSION_PATCH"))


def get_version():
Expand Down
4 changes: 4 additions & 0 deletions rita/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def gen():


def is_complex(arg):
# if we want to use `-` as a word
if arg.strip() == "-":
return False

splitters = ["-", " "]
return any([s in arg
for s in splitters])
Expand Down
21 changes: 21 additions & 0 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,27 @@ def test_prefix_on_unknown_type(self):
"pattern": [{"LOWER": {"REGEX": ".*"}}]
}

def test_multiple_optionals(self):
rules = self.compiler("""
{NUM+, WORD("-")?, NUM?, WORD("/")?, NUM?}->MARK("NUMBER_PATTERN")
""")
print(rules)
assert len(rules) == 1
assert rules[0] == {
"label": "NUMBER_PATTERN",
"pattern": [
{"LOWER": {"REGEX": "\\d+[.]?\\d*"}, "OP": "+"},
{"IS_PUNCT": True, "OP": "?"},
{"LOWER": "-", "OP": "?"},
{"IS_PUNCT": True, "OP": "?"},
{"LOWER": {"REGEX": "\\d+[.]?\\d*"}, "OP": "?"},
{"IS_PUNCT": True, "OP": "?"},
{"LOWER": "/", "OP": "?"},
{"IS_PUNCT": True, "OP": "?"},
{"LOWER": {"REGEX": "\\d+[.]?\\d*"}, "OP": "?"},
]
}


class TestStandalone(object):
@property
Expand Down