Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
TanimSk committed Oct 9, 2022
1 parent 4bfeca5 commit c4f5bc2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion avro/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
AVRO_SHORBORNO = set(AVRO_DICT['data']['shorborno'])
AVRO_KAR = AVRO_DICT['data']['kar']
AVRO_IGNORE = AVRO_DICT['data']['ignore']
EXCEPTIONS = AVRO_DICT['data']['exceptions']
EXCEPTIONS = AVRO_DICT['data']['exceptions']
25 changes: 11 additions & 14 deletions avro/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ def subparse(text: str) -> str:
# Prepare output list.
output = []

# Cursor end point.
cur_end = 0

# Iterate through input text.
for cur, i in enumerate(text):
try:
Expand Down Expand Up @@ -184,22 +181,22 @@ def subparse(text: str) -> str:
output = []

# Split using regex to remove noise
regex_pattern = "(\s|\.|,|\?|\।|\-|;|')"
regex_pattern = "(\\s|\\.|,|\\?|\\।|\\-|;|')"
compiled_regex = re.compile(regex_pattern, re.UNICODE)

for text in texts: # Applies to non-keyword arguments.

exceptions = config.EXCEPTIONS.get(text, None)

if exceptions is None:
separated_texts = compiled_regex.split(text)

for separated_text in separated_texts:
text_segments.append(subparse(separated_text))

output.append(''.join(text_segments))
text_segments = []

else:
output.append(exceptions)

Expand All @@ -226,7 +223,7 @@ def match_patterns(fixed_text: str, cur: int=0, rule: bool=False, reversed: bool
"matched": True,
"found": pattern[0].get('find', None),
"replaced": pattern[0].get('replace', None),
"reversed": reverse_with_rules(cur, fixed_text, pattern[0].get('reverse', None))
"reversed": reverse_with_rules(cur, fixed_text, pattern[0].get('reverse', None))
}
else:
return {
Expand Down Expand Up @@ -274,21 +271,21 @@ def reverse_with_rules(cursor: int, fixed_text: str, text_reversed) -> bool:
'''Enhances The Word With Rules For Reverse Parsing'''
added_suffix = ''

if not (fixed_text[cursor] in config.AVRO_KAR or \
fixed_text[cursor] in config.AVRO_SHORBORNO or \
fixed_text[cursor] in config.AVRO_IGNORE or \
len(fixed_text) == cursor + 1):
if not (fixed_text[cursor] in config.AVRO_KAR
or fixed_text[cursor] in config.AVRO_SHORBORNO
or fixed_text[cursor] in config.AVRO_IGNORE
or len(fixed_text) == cursor + 1):
added_suffix = 'o'

try:
if fixed_text[cursor + 1] in config.AVRO_KAR:
added_suffix = ''
if fixed_text[cursor + 2] in config.AVRO_KAR and not cursor == 0:
added_suffix = ''

except IndexError:
pass

return text_reversed if text_reversed is None else (text_reversed + added_suffix)


Expand Down
3 changes: 2 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def test_patterns_without_rules_from_config() -> None:

for pattern in AVRO_DICT['data']['patterns']:
if 'rules' not in pattern:
assert pattern['replace'] == avro.parse(pattern['find'])
if pattern.get('find', None) is not None:
assert pattern['replace'] == avro.parse(pattern['find'])


def test_patterns_without_rules_not_from_config() -> None:
Expand Down

0 comments on commit c4f5bc2

Please sign in to comment.