python-negar 1.3__tar.gz → 1.4__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,6 @@
1
+ 1.4 - 2025-01-05
2
+ -- Added a new feature to ignore text after #> as a comment trigger.
3
+
1
4
  1.3 - 2025-01-01
2
5
  -- Enhanced the handling of immutable words to achieve greater accuracy in results.
3
6
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-negar
3
- Version: 1.3
3
+ Version: 1.4
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
@@ -42,7 +42,7 @@ Installation
42
42
 
43
43
  ## Git
44
44
 
45
- You can get latest stable changes from github server:
45
+ You can get the latest stable changes from the GitHub server:
46
46
 
47
47
  $ git clone https://github.com/shahinism/python-negar.git
48
48
  $ cd python-negar
@@ -62,11 +62,11 @@ Get the latest tarball & install:
62
62
 
63
63
  ### Windows
64
64
 
65
- Download latest zip archive.
65
+ Download the latest zip archive.
66
66
 
67
67
  https://github.com/shahinism/python-negar/archive/master.zip
68
68
 
69
- Decompress it, and run the following command in root directory of `python-negar`
69
+ Decompress it, and run the following command in the root directory of `python-negar`
70
70
 
71
71
  $ python setup.py install
72
72
 
@@ -85,7 +85,7 @@ Calling by default options:
85
85
  * جایگزینی
86
86
  + خط تیره های پیاپی نظیر (--) و (---) با معادل های استاندارد شان
87
87
  + سه نقطه ی پیاپی (...) با کاراکتر استانداردش در زبان فارسی
88
- + علایمی نظیر کتیشن فارسی با گیومه ؛ 'نگار'
88
+ + علایمی نظیر کوتیشن فارسی با گیومه ؛ 'نگار'
89
89
  + اعداد عربی '١٢٣٤٥٦٧٨٩٠' و انگلیسی '1234567890' با معادل فارسی
90
90
  + کاراکتر های غیر فارسی نظیر ',;%يةك' با معادل های فارسی
91
91
 
@@ -21,7 +21,7 @@ Installation
21
21
 
22
22
  ## Git
23
23
 
24
- You can get latest stable changes from github server:
24
+ You can get the latest stable changes from the GitHub server:
25
25
 
26
26
  $ git clone https://github.com/shahinism/python-negar.git
27
27
  $ cd python-negar
@@ -41,11 +41,11 @@ Get the latest tarball & install:
41
41
 
42
42
  ### Windows
43
43
 
44
- Download latest zip archive.
44
+ Download the latest zip archive.
45
45
 
46
46
  https://github.com/shahinism/python-negar/archive/master.zip
47
47
 
48
- Decompress it, and run the following command in root directory of `python-negar`
48
+ Decompress it, and run the following command in the root directory of `python-negar`
49
49
 
50
50
  $ python setup.py install
51
51
 
@@ -64,7 +64,7 @@ Calling by default options:
64
64
  * جایگزینی
65
65
  + خط تیره های پیاپی نظیر (--) و (---) با معادل های استاندارد شان
66
66
  + سه نقطه ی پیاپی (...) با کاراکتر استانداردش در زبان فارسی
67
- + علایمی نظیر کتیشن فارسی با گیومه ؛ 'نگار'
67
+ + علایمی نظیر کوتیشن فارسی با گیومه ؛ 'نگار'
68
68
  + اعداد عربی '١٢٣٤٥٦٧٨٩٠' و انگلیسی '1234567890' با معادل فارسی
69
69
  + کاراکتر های غیر فارسی نظیر ',;%يةك' با معادل های فارسی
70
70
 
@@ -1,7 +1,7 @@
1
1
  import platform
2
2
  from pathlib import Path
3
3
 
4
- __version__ = "1.3"
4
+ __version__ = "1.4"
5
5
 
6
6
  DATAFILE = Path(__file__).parent.absolute() / "data/immutable.words"
7
7
  APPDATA = "AppData/Roaming/" if platform.system() == "Windows" else "."
@@ -57,6 +57,7 @@ class PersianEditor:
57
57
  self.cleanup()
58
58
 
59
59
  def cleanup(self):
60
+ self.__handle_comments__(State.save)
60
61
  self.__handle_urls__(State.save)
61
62
  # fix punctuation spaces at first
62
63
  # : ; , ! ? and their Persian counterparts should have one space after and no space before
@@ -95,6 +96,7 @@ class PersianEditor:
95
96
  if self._trim_leading_trailing_whitespaces:
96
97
  self.text = "\n".join([line.strip() for line in self.text.split("\n")])
97
98
  self.__handle_urls__(State.restore)
99
+ self.__handle_comments__(State.restore)
98
100
  return self.text
99
101
 
100
102
  def __repr__(self):
@@ -102,8 +104,19 @@ class PersianEditor:
102
104
 
103
105
  __str__ = __repr__
104
106
 
107
+ def __handle_comments__(self, state):
108
+ """Extract comments, process the content, and reinsert the comments at the end."""
109
+ if state == State.save:
110
+ self.comments = list(set(re.findall(r"#>.*$", self.text, re.I | re.M)))
111
+ self.comments.sort(key=lambda x: len(x), reverse=True)
112
+ for i, comment in enumerate(self.comments):
113
+ self.text = regex.sub(rf"{re.escape(comment)}", rf"__COMMENT__#{i}__", self.text)
114
+ if state == State.restore:
115
+ for i, comment in enumerate(self.comments):
116
+ self.text = re.sub(f"__COMMENT__#{i}__", comment, self.text)
117
+
105
118
  def __handle_urls__(self, state):
106
- """Remove URLs and putting them back at the end of the process."""
119
+ """Remove URLs temporarily and reinsert them at the end of the process."""
107
120
  if state == State.save:
108
121
  self.urls = list(set(re.findall(URLREGX, self.text, re.M | re.I | re.X)))
109
122
  self.urls.sort(key=lambda x: len(x), reverse=True)
@@ -114,12 +127,12 @@ class PersianEditor:
114
127
  self.text = re.sub(f"__URL__#{i}__", url, self.text)
115
128
 
116
129
  def __handle_immutable_words__(self, state):
117
- """Remove URLs and putting them back at the end of the process."""
130
+ """Remove immutable words temporarily and reapply them at the end of the process."""
118
131
  if state == State.save:
119
132
  self.immutable_words = {}
120
133
  words = self.text.split()
121
134
  for i, word in enumerate(words):
122
- if (word:=word.strip()) in ImmutableWords.get():
135
+ if (word := word.strip()) in ImmutableWords.get():
123
136
  self.immutable_words[i] = word
124
137
  self.text = regex.sub(rf"\b{word}\b", rf"__IMM__#{i}__", self.text)
125
138
  if state == State.restore:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-negar
3
- Version: 1.3
3
+ Version: 1.4
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
@@ -42,7 +42,7 @@ Installation
42
42
 
43
43
  ## Git
44
44
 
45
- You can get latest stable changes from github server:
45
+ You can get the latest stable changes from the GitHub server:
46
46
 
47
47
  $ git clone https://github.com/shahinism/python-negar.git
48
48
  $ cd python-negar
@@ -62,11 +62,11 @@ Get the latest tarball & install:
62
62
 
63
63
  ### Windows
64
64
 
65
- Download latest zip archive.
65
+ Download the latest zip archive.
66
66
 
67
67
  https://github.com/shahinism/python-negar/archive/master.zip
68
68
 
69
- Decompress it, and run the following command in root directory of `python-negar`
69
+ Decompress it, and run the following command in the root directory of `python-negar`
70
70
 
71
71
  $ python setup.py install
72
72
 
@@ -85,7 +85,7 @@ Calling by default options:
85
85
  * جایگزینی
86
86
  + خط تیره های پیاپی نظیر (--) و (---) با معادل های استاندارد شان
87
87
  + سه نقطه ی پیاپی (...) با کاراکتر استانداردش در زبان فارسی
88
- + علایمی نظیر کتیشن فارسی با گیومه ؛ 'نگار'
88
+ + علایمی نظیر کوتیشن فارسی با گیومه ؛ 'نگار'
89
89
  + اعداد عربی '١٢٣٤٥٦٧٨٩٠' و انگلیسی '1234567890' با معادل فارسی
90
90
  + کاراکتر های غیر فارسی نظیر ',;%يةك' با معادل های فارسی
91
91
 
@@ -40,5 +40,4 @@ setup(
40
40
  "Programming Language :: Python",
41
41
  "Programming Language :: Python :: 3",
42
42
  ],
43
-
44
43
  )
@@ -11,7 +11,9 @@ class Test(unittest.TestCase):
11
11
  def wrapper(self, *args, **kwargs):
12
12
  func(self, *args, **kwargs)
13
13
  return self.assertEqual(f"{PersianEditor(self.input_)}", self.output_, message)
14
+
14
15
  return wrapper
16
+
15
17
  return decorator
16
18
 
17
19
  # @unittest.skip("")
@@ -22,8 +24,8 @@ class Test(unittest.TestCase):
22
24
 
23
25
  @_assertEqual("Fix Hamzeh")
24
26
  def test_fix_hamzeh(self):
25
- self.input_ = "کلماتی که با 'ی' پسوند همراه هستند مانند 'همه ی ' -- و البته امکان جایگزینی آن با حمزه 'ء' ( در صورت انتخاب کاربر )" # noqa: E501
26
- self.output_ = "کلماتی که با «ی» پسوند همراه هستند مانند «همه‌ی» – و البته امکان جایگزینی آن با حمزه «ء» (در صورت انتخاب کاربر)" # noqa: E501
27
+ self.input_ = "کلماتی که با 'ی' پسوند همراه هستند مانند 'همه ی ' -- و البته امکان جایگزینی آن با حمزه 'ء' ( در صورت انتخاب کاربر )" # noqa: E501
28
+ self.output_ = "کلماتی که با «ی» پسوند همراه هستند مانند «همه‌ی» – و البته امکان جایگزینی آن با حمزه «ء» (در صورت انتخاب کاربر)" # noqa: E501
27
29
 
28
30
  @_assertEqual("Numbers as a Version -- Triple Dots")
29
31
  def test_versioning_numbers_triple(self):
@@ -61,7 +63,6 @@ class Test(unittest.TestCase):
61
63
  def test_persian_quotations_ii(self):
62
64
  self.input_ = "«تاثیر نسبی داشته است. »"
63
65
  self.output_ = "«تاثیر نسبی داشته است.»"
64
-
65
66
 
66
67
  @_assertEqual("Persian Numbers")
67
68
  def test_persian_numbers(self):
@@ -102,7 +103,7 @@ class Test(unittest.TestCase):
102
103
  def test_fix_prefix_ZWNJ_iii(self):
103
104
  self.input_ = r"می ‌شود"
104
105
  self.output_ = "می‌شود"
105
-
106
+
106
107
  @_assertEqual("Fix Suffix ZWNJ I")
107
108
  def test_fix_suffix_ZWNJ_I(self):
108
109
  self.input_ = r"در پسوند کلمات با نیم‌فاصله نظیر کتابها، خوشترین -- و البته امکان عدم تنظیم (در صورت انتخاب کاربر)"
@@ -127,7 +128,7 @@ class Test(unittest.TestCase):
127
128
  def test_immutable_words_i(self):
128
129
  self.input_ = "تنها ترین خدمتگزار (تنها ترین خدمتگزار)"
129
130
  self.output_ = "تنهاترین خدمتگزار (تنهاترین خدمتگزار)"
130
-
131
+
131
132
  @_assertEqual("Immutable Words II")
132
133
  def test_immutable_words_ii(self):
133
134
  self.input_ = "تنها ترین خدمتگزار (تنها ترین خدمتگزار)"
@@ -138,6 +139,11 @@ class Test(unittest.TestCase):
138
139
  self.input_ = "بیستم ماه میلادی"
139
140
  self.output_ = "بیستم ماه میلادی"
140
141
 
142
+ @_assertEqual("Ignote Comment")
143
+ def test_ignore_comment(self):
144
+ self.input_ = "کشیـــــــــده شده اند #> می نویسد .... "
145
+ self.output_ = "کشیده شده‌اند #> می نویسد .... "
146
+
141
147
 
142
148
  if __name__ == "__main__":
143
149
  unittest.main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes