python-negar 1.4__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.
@@ -1,3 +1,10 @@
1
+ 1.4.2 - 2025-01-23
2
+ -- Fixed issue with همان‌طور، نشان‌دهنده
3
+
4
+ 1.4.1 - 2025-01-06
5
+ -- Fixed issue with immutability check.
6
+ -- Added several additional immutable words.
7
+
1
8
  1.4 - 2025-01-05
2
9
  -- Added a new feature to ignore text after #> as a comment trigger.
3
10
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-negar
3
- Version: 1.4
3
+ Version: 1.4.2
4
4
  Summary: Negar is a spell corrector and Persian text editor
5
5
  Home-page: http://github.com/shahinism/python-negar
6
6
  Author: Shahin Azad
@@ -1,7 +1,7 @@
1
1
  import platform
2
2
  from pathlib import Path
3
3
 
4
- __version__ = "1.4"
4
+ __version__ = "1.4.2"
5
5
 
6
6
  DATAFILE = Path(__file__).parent.absolute() / "data/immutable.words"
7
7
  APPDATA = "AppData/Roaming/" if platform.system() == "Windows" else "."
@@ -194,6 +194,8 @@
194
194
  بلغارستان
195
195
  بلوچستان
196
196
  بلوچستان
197
+ بمان
198
+ بمانی
197
199
  بنانها
198
200
  بنگستان
199
201
  بنگستان
@@ -213,6 +215,8 @@
213
215
  بهترین
214
216
  به‌تنهایی
215
217
  بهمان
218
+ بهمان
219
+ بهمانی
216
220
  بوتان
217
221
  بودنتان
218
222
  بوستان
@@ -337,6 +341,9 @@
337
341
  بیبل
338
342
  بی‌بها
339
343
  بی‌بهایی
344
+ بیبی
345
+ بیبی‌فیس
346
+ بیبی‌گرل
340
347
  بیت
341
348
  بیت‌التکمه‌ها
342
349
  بیت‌الحکمه
@@ -416,6 +423,7 @@
416
423
  بیدی
417
424
  بیر
418
425
  بیرالده
426
+ بیرانوند
419
427
  بیراه
420
428
  بیراهه
421
429
  بیراهه‌ها
@@ -800,6 +808,7 @@
800
808
  پاک‌نها
801
809
  پانسمان
802
810
  پایتان
811
+ پخشان
803
812
  پراستر
804
813
  پراشتها
805
814
  پرالتها
@@ -883,6 +892,9 @@
883
892
  تنهای
884
893
  تنهایی
885
894
  تنهایی
895
+ تنهایی‌ها
896
+ تنهایی‌های
897
+ تنهایی‌هایی
886
898
  تنوره‌کشان
887
899
  تهیدستان
888
900
  توتستان
@@ -910,8 +922,15 @@
910
922
  چایمان
911
923
  چپ‌دستان
912
924
  چچستان
925
+ چشمانتان
926
+ چشمان‌تان
927
+ چشمانشان
928
+ چشمان‌شان
929
+ چشمانمان
930
+ چشمان‌مان
913
931
  چنارستان
914
932
  چیستان
933
+ حاکمان
915
934
  حرفتان
916
935
  حسابتان
917
936
  حصیرستان
@@ -978,6 +997,7 @@
978
997
  دفتری
979
998
  دکتر
980
999
  دکتری
1000
+ دکترین
981
1001
  دلستر
982
1002
  دنیاپرستان
983
1003
  دهستان
@@ -1065,6 +1085,8 @@
1065
1085
  شبستری
1066
1086
  شبها
1067
1087
  شتان
1088
+ شتر
1089
+ شتری
1068
1090
  شعردوستان
1069
1091
  شفها
1070
1092
  شکرافشان
@@ -1860,6 +1882,8 @@
1860
1882
  هلی‌کوپتر
1861
1883
  هلیکوپتر
1862
1884
  همان
1885
+ همان
1886
+ همان‌ها
1863
1887
  همانی
1864
1888
  هم‌بستر
1865
1889
  هم‌پیمان
@@ -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
 
@@ -130,7 +131,7 @@ class PersianEditor:
130
131
  """Remove immutable words temporarily and reapply them at the end of the process."""
131
132
  if state == State.save:
132
133
  self.immutable_words = {}
133
- words = self.text.split()
134
+ words = re.findall(r"\b[\w\u200c]+\b", self.text, re.UNICODE)
134
135
  for i, word in enumerate(words):
135
136
  if (word := word.strip()) in ImmutableWords.get():
136
137
  self.immutable_words[i] = word
@@ -259,7 +260,7 @@ class PersianEditor:
259
260
  if self._exaggerating_zwnj
260
261
  else ""
261
262
  )
262
- regx = re.compile(
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
- )\b""",
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: re.Pattern):
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 = re.sub(
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
- try:
393
- # for compatibility with previous versions, since immutable.words was untouchable.dat before ver 1.2.10
394
- if (USERFILE / "untouchable.dat").exists():
395
- (USERFILE / "untouchable.dat").rename(USERFILE / "immutable.words")
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__":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-negar
3
- Version: 1.4
3
+ Version: 1.4.2
4
4
  Summary: Negar is a spell corrector and Persian text editor
5
5
  Home-page: http://github.com/shahinism/python-negar
6
6
  Author: Shahin Azad
@@ -139,11 +139,21 @@ class Test(unittest.TestCase):
139
139
  self.input_ = "بیستم ماه میلادی"
140
140
  self.output_ = "بیستم ماه میلادی"
141
141
 
142
- @_assertEqual("Ignote Comment")
142
+ @_assertEqual("Ignore Comment")
143
143
  def test_ignore_comment(self):
144
144
  self.input_ = "کشیـــــــــده شده اند #> می نویسد .... "
145
145
  self.output_ = "کشیده شده‌اند #> می نویسد .... "
146
146
 
147
+ @_assertEqual("mix_parentheses_suffix")
148
+ def test_mix_parentheses_suffix(self):
149
+ self.input_ = '"دختر تنهایی " ( کهتر بمان )'
150
+ self.output_ = "«دختر تنهایی» (کهتر بمان)"
151
+
152
+ @_assertEqual("unchanged")
153
+ def test_unchanged(self):
154
+ self.input_ = "نشان‌دهنده همان‌طور"
155
+ self.output_ = "نشان‌دهنده همان‌طور"
156
+
147
157
 
148
158
  if __name__ == "__main__":
149
159
  unittest.main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes