python-negar 1.4.1__tar.gz → 1.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_negar-1.4.1 → python_negar-1.4.2}/Changelog.txt +3 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/PKG-INFO +1 -1
- {python_negar-1.4.1 → python_negar-1.4.2}/negar/constants.py +1 -1
- {python_negar-1.4.1 → python_negar-1.4.2}/negar/virastar.py +10 -10
- {python_negar-1.4.1 → python_negar-1.4.2}/python_negar.egg-info/PKG-INFO +1 -1
- {python_negar-1.4.1 → python_negar-1.4.2}/tests/test_unittest.py +5 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/AUTHORS +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/LICENSE +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/MANIFEST.in +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/README.md +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/negar/__init__.py +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/negar/data/immutable.words +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/negar/gui.py +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/python_negar.egg-info/SOURCES.txt +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/python_negar.egg-info/dependency_links.txt +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/python_negar.egg-info/entry_points.txt +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/python_negar.egg-info/requires.txt +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/python_negar.egg-info/top_level.txt +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/setup.cfg +0 -0
- {python_negar-1.4.1 → python_negar-1.4.2}/setup.py +0 -0
|
@@ -5,6 +5,7 @@ import enum
|
|
|
5
5
|
import re
|
|
6
6
|
import sys
|
|
7
7
|
from pathlib import Path
|
|
8
|
+
from contextlib import suppress
|
|
8
9
|
|
|
9
10
|
import regex
|
|
10
11
|
|
|
@@ -259,7 +260,7 @@ class PersianEditor:
|
|
|
259
260
|
if self._exaggerating_zwnj
|
|
260
261
|
else ""
|
|
261
262
|
)
|
|
262
|
-
regx =
|
|
263
|
+
regx = regex.compile(
|
|
263
264
|
rf"""\b(\S+?) # not-greedy fetch to handle some case like هایشان instead شان
|
|
264
265
|
({exag}
|
|
265
266
|
# تر(ی(ن)?)?
|
|
@@ -267,13 +268,13 @@ class PersianEditor:
|
|
|
267
268
|
# ها(ی(ی|ت|م|ش|تان|شان)?)?|
|
|
268
269
|
شناس(ی)?|
|
|
269
270
|
گذار(ی)?|گزار(ی)?
|
|
270
|
-
)
|
|
271
|
+
)(?:(?=\b)|(?=\u200C))""", # ensures that it is followed by either \b or \u200C
|
|
271
272
|
re.VERBOSE,
|
|
272
273
|
)
|
|
273
274
|
# Checks that the suffix (tar*, haye*) is part of a word or not, like بهتر.
|
|
274
275
|
self.__immutability_check__(regx)
|
|
275
276
|
|
|
276
|
-
def __immutability_check__(self, regx:
|
|
277
|
+
def __immutability_check__(self, regx: regex.Pattern):
|
|
277
278
|
# Replace backslashes with a temporary placeholder
|
|
278
279
|
text = self.text.replace("\\", "PN__BACKSLASH__PN")
|
|
279
280
|
wlist = text.split()
|
|
@@ -281,7 +282,7 @@ class PersianEditor:
|
|
|
281
282
|
regx_iter = regx.finditer(word)
|
|
282
283
|
for p in regx_iter:
|
|
283
284
|
# if p.group() not in ImmutableWords.get():
|
|
284
|
-
text =
|
|
285
|
+
text = regex.sub(
|
|
285
286
|
rf"\b{re.escape(p.group())}\b",
|
|
286
287
|
p.group(1) + "\u200c" + p.group(2),
|
|
287
288
|
text,
|
|
@@ -389,15 +390,14 @@ class ImmutableWords:
|
|
|
389
390
|
with DATAFILE.open(encoding="utf8") as f:
|
|
390
391
|
for line in f:
|
|
391
392
|
cls.words.add(line.strip())
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
393
|
+
|
|
394
|
+
# for compatibility with previous versions, since immutable.words was untouchable.dat before ver 1.2.10
|
|
395
|
+
if (USERFILE / "untouchable.dat").exists():
|
|
396
|
+
(USERFILE / "untouchable.dat").rename(USERFILE / "immutable.words")
|
|
397
|
+
with suppress(FileNotFoundError):
|
|
396
398
|
with (USERFILE / "immutable.words").open(encoding="utf8") as f:
|
|
397
399
|
for line in f:
|
|
398
400
|
cls.words.add(line.strip())
|
|
399
|
-
except FileNotFoundError:
|
|
400
|
-
pass
|
|
401
401
|
|
|
402
402
|
|
|
403
403
|
if __name__ == "__main__":
|
|
@@ -149,6 +149,11 @@ class Test(unittest.TestCase):
|
|
|
149
149
|
self.input_ = '"دختر تنهایی " ( کهتر بمان )'
|
|
150
150
|
self.output_ = "«دختر تنهایی» (کهتر بمان)"
|
|
151
151
|
|
|
152
|
+
@_assertEqual("unchanged")
|
|
153
|
+
def test_unchanged(self):
|
|
154
|
+
self.input_ = "نشاندهنده همانطور"
|
|
155
|
+
self.output_ = "نشاندهنده همانطور"
|
|
156
|
+
|
|
152
157
|
|
|
153
158
|
if __name__ == "__main__":
|
|
154
159
|
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|