PgsFile 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl

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.

Potentially problematic release.


This version of PgsFile might be problematic. Click here for more details.

PgsFile/PgsFile.py CHANGED
@@ -62,53 +62,82 @@ def decimal_to_percent(decimal):
62
62
  percent_str="{:.2f}%".format(percent)
63
63
  return percent_str
64
64
 
65
+ try:
66
+ import chardet
67
+ except ImportError:
68
+ print("chardet library not found. Installing...")
69
+ install_package("chardet")
70
+ import chardet # Re-import after installation
71
+
65
72
  def get_data_text(path):
66
73
  '''
67
74
  Parameters
68
75
  ----------
69
- path : TYPE string
70
- DESCRIPTION.
71
- Using path to get data from a single txt file. eg. raw_text.txt
72
- Theoretically, it supports common text encoding formats, like utf-8, unicode, ansi, gbk etc.
76
+ path : str
77
+ The path to the text file to read.
78
+ Supports common text encoding formats, like utf-8, unicode, ansi, gbk etc.
73
79
 
74
80
  Returns
75
81
  -------
76
- text : TYPE string
77
- DESCRIPTION.
78
- It returns all the text content from the target file.
79
-
82
+ text : str
83
+ The text content from the target file.
84
+ Returns None if the file cannot be read with any of the specified encodings.
80
85
  '''
81
- for encoding in encodings:
82
- try:
83
- with open(path, 'r', encoding=encoding, errors='ignore') as f:
84
- return f.read()
85
- except UnicodeDecodeError:
86
- continue
87
- return None
88
-
86
+ # Get the size of the file
87
+ file_size = os.path.getsize(path)
88
+
89
+ # Read the file to detect encoding
90
+ with open(path, 'rb') as f:
91
+ if file_size < 1024:
92
+ raw_data = f.read() # Read the entire file if it's small
93
+ else:
94
+ raw_data = f.read(1024) # Read the first 1024 bytes
95
+
96
+ result = chardet.detect(raw_data)
97
+ encoding = result['encoding']
98
+
99
+ # Read the entire file using the detected encoding
100
+ if encoding:
101
+ with open(path, 'r', encoding=encoding, errors="ignore") as f:
102
+ return f.read()
103
+ else:
104
+ return None
105
+
89
106
  def get_data_lines(path):
90
107
  '''
91
108
  Parameters
92
109
  ----------
93
- path : TYPE string
94
- DESCRIPTION.
95
- Using path to get data from a single txt file. eg. raw_text.txt
96
- Theoretically, it supports common the text encoding formats, like utf-8, unicode, ansi, gbk etc.
110
+ path : str
111
+ The path to the text file to read.
112
+ Supports common text encoding formats, like utf-8, unicode, ansi, gbk etc.
97
113
 
98
114
  Returns
99
115
  -------
100
- lines : TYPE list
101
- DESCRIPTION.
102
- It returns a list containing all the paragraphs of the target file.
103
-
116
+ lines : list
117
+ A list containing all the non-empty paragraphs of the target file.
104
118
  '''
105
- for encoding in encodings:
106
- try:
107
- with open(path, 'r', encoding=encoding, errors='ignore') as f:
108
- return [l.strip() for l in f.readlines() if len(l.strip()) !=0]
109
- except UnicodeDecodeError:
110
- continue
111
- return None
119
+
120
+ # Get the size of the file
121
+ file_size = os.path.getsize(path)
122
+
123
+ # Read the file to detect encoding
124
+ with open(path, 'rb') as f:
125
+ if file_size < 1024:
126
+ raw_data = f.read() # Read the entire file if it's small
127
+ else:
128
+ raw_data = f.read(1024) # Read the first 1024 bytes
129
+
130
+ result = chardet.detect(raw_data)
131
+ encoding = result['encoding']
132
+
133
+ # Read the entire file using the detected encoding
134
+ if encoding:
135
+ with open(path, 'r', encoding=encoding, errors="ignore") as f:
136
+ lines = [l.strip() for l in f.readlines() if len(l.strip()) != 0]
137
+ return lines
138
+ else:
139
+ return None
140
+
112
141
 
113
142
  def write_to_txt(file_path,text,mode=None,encoding=None):
114
143
  '''
@@ -457,7 +486,7 @@ BigPunctuation="""!"#$&\'()*+,-/:;<=>?@[\\]^_`{|}.%~"#$%&'?。()
457
486
  StopTags="""◆: 、/ 。/ ---/ -/ --/ -- :/ ;/ ?/ ??/ ?┖ @/ [/ ]/ ^/ ‘/ ’/ "/ "/ 〈/ 〉/ 《/ 》/ 【/ 】/ >/ ∶/ ■/ ●/ ·/ …/ !/ #/ %,/ %/ \'/ (/ )/ */ +/ ,/ -/ // np v n w m a x t q j ni ns d i f u p g nz c r id s k h o e / #?/ --/""" #用来停用词性标注
458
487
  Special="""∶ ■ ● ① ② ③ × ℃ Ⅲ ④ ⑤ ◆ ⑥ ± ⑦ ⑧ → ⑨ ▲ ⑩ ─ ÷ μ γ β Ⅱ Ⅰ ‰ □ 〇 ○ Ⅴ Ⅳ ★ ﹐ ° ※ ︰ α ― ≠ █ о θ ω ⒈ ⒉ ⒊ н ≤ ì ǎ ≥ р т с к й а и Ⅵ é è ﹢ ﹝ ﹞  ā ⒋ ù π ◇ Ω Ф ы Я п К в у м ǒ ü á ǔ ⒌ ⒍ 䦆 Ⅹ Ⅶ ← """
459
488
  ZhStopWords="""——— 》), )÷(1- ”, )、 =( : → ℃ & * 一一 ~~~~ ’ . 『 .一 ./ -- 』 =″ 【 [*] }> [⑤]] [①D] c] ng昉 * // [ ] [②e] [②g] ={ } ,也 ‘ A [①⑥] [②B] [①a] [④a] [①③] [③h] ③] 1. -- [②b] ’‘ ××× [①⑧] 0:2 =[ [⑤b] [②c] [④b] [②③] [③a] [④c] [①⑤] [①⑦] [①g] ∈[ [①⑨] [①④] [①c] [②f] [②⑧] [②①] [①C] [③c] [③g] [②⑤] [②②] 一. [①h] .数 [] [①B] 数/ [①i] [③e] [①①] [④d] [④e] [③b] [⑤a] [①A] [②⑧] [②⑦] [①d] [②j] 〕〔 ][ :// ′∈ [②④ [⑤e] 12% b] ... ................... …………………………………………………③ ZXFITL [③F] 」 [①o] ]∧′=[ ∪φ∈ ′| {- ②c } [③①] R.L. [①E] Ψ -[*]- ↑ .日 [②d] [② [②⑦] [②②] [③e] [①i] [①B] [①h] [①d] [①g] [①②] [②a] f] [⑩] a] [①e] [②h] [②⑥] [③d] [②⑩] e] 〉 】 元/吨 [②⑩] 2.3% 5:0 [①] :: [②] [③] [④] [⑤] [⑥] [⑦] [⑧] [⑨] …… —— ? 、 。 “ ” 《 》 ! , : ; ? . , . ' ? · ——— ── ? — < > ( ) 〔 〕 [ ] ( ) - + ~ × / / ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ Ⅲ В " ; # @ γ μ φ φ. × Δ ■ ▲ sub exp sup sub Lex # % & ' + +ξ ++ - -β < <± <Δ <λ <φ <<== =☆ =- > >λ _ ~± ~+ [⑤f] [⑤d] [②i] ≈ [②G] [①f] LI ㈧ [- ...... 〉 [③⑩] 第二 一番 一直 一个 一些 许多 种 有的是 也就是说 末##末 啊 阿 哎 哎呀 哎哟 唉 俺 俺们 按 按照 吧 吧哒 把 罢了 被 本 本着 比 比方 比如 鄙人 彼 彼此 边 别 别的 别说 并 并且 不比 不成 不单 不但 不独 不管 不光 不过 不仅 不拘 不论 不怕 不然 不如 不特 不惟 不问 不只 朝 朝着 趁 趁着 乘 冲 除 除此之外 除非 除了 此 此间 此外 从 从而 打 待 但 但是 当 当着 到 得 的 的话 等 等等 地 第 叮咚 对 对于 多 多少 而 而况 而且 而是 而外 而言 而已 尔后 反过来 反过来说 反之 非但 非徒 否则 嘎 嘎登 该 赶 个 各 各个 各位 各种 各自 给 根据 跟 故 故此 固然 关于 管 归 果然 果真 过 哈 哈哈 呵 和 何 何处 何况 何时 嘿 哼 哼唷 呼哧 乎 哗 还是 还有 换句话说 换言之 或 或是 或者 极了 及 及其 及至 即 即便 即或 即令 即若 即使 几 几时 己 既 既然 既是 继而 加之 假如 假若 假使 鉴于 将 较 较之 叫 接着 结果 借 紧接着 进而 尽 尽管 经 经过 就 就是 就是说 据 具体地说 具体说来 开始 开外 靠 咳 可 可见 可是 可以 况且 啦 来 来着 离 例如 哩 连 连同 两者 了 临 另 另外 另一方面 论 嘛 吗 慢说 漫说 冒 么 每 每当 们 莫若 某 某个 某些 拿 哪 哪边 哪儿 哪个 哪里 哪年 哪怕 哪天 哪些 哪样 那 那边 那儿 那个 那会儿 那里 那么 那么些 那么样 那时 那些 那样 乃 乃至 呢 能 你 你们 您 宁 宁可 宁肯 宁愿 哦 呕 啪达 旁人 呸 凭 凭借 其 其次 其二 其他 其它 其一 其余 其中 起 起见 起见 岂但 恰恰相反 前后 前者 且 然而 然后 然则 让 人家 任 任何 任凭 如 如此 如果 如何 如其 如若 如上所述 若 若非 若是 啥 上下 尚且 设若 设使 甚而 甚么 甚至 省得 时候 什么 什么样 使得 是 是的 首先 谁 谁知 顺 顺着 似的 虽 虽然 虽说 虽则 随 随着 所 所以 他 他们 他人 它 它们 她 她们 倘 倘或 倘然 倘若 倘使 腾 替 通过 同 同时 哇 万一 往 望 为 为何 为了 为什么 为着 喂 嗡嗡 我 我们 呜 呜呼 乌乎 无论 无宁 毋宁 嘻 吓 相对而言 像 向 向着 嘘 呀 焉 沿 沿着 要 要不 要不然 要不是 要么 要是 也 也罢 也好 一 一般 一旦 一方面 一来 一切 一样 一则 依 依照 矣 以 以便 以及 以免 以至 以至于 以致 抑或 因 因此 因而 因为 哟 用 由 由此可见 由于 有 有的 有关 有些 又 于 于是 于是乎 与 与此同时 与否 与其 越是 云云 哉 再说 再者 在 在下 咱 咱们 则 怎 怎么 怎么办 怎么样 怎样 咋 照 照着 者 这 这边 这儿 这个 这会儿 这就是说 这里 这么 这么点儿 这么些 这么样 这时 这些 这样 正如 吱 之 之类 之所以 之一 只是 只限 只要 只有 至 至于 诸位 着 着呢 自 自从 自个儿 自各儿 自己 自家 自身 综上所述 总的来看 总的来说 总的说来 总而言之 总之 纵 纵令 纵然 纵使 遵照 作为 兮 呃 呗 咚 咦 喏 啐 喔唷 嗬 嗯 嗳"""
460
- encodings = ['utf-8', 'utf-16', 'gbk', 'big5', 'shift_jis', 'euc-jp', 'windows-1252', 'iso-8859-1', 'koi8-r', 'macroman', 'utf-32', 'ascii']
489
+
461
490
  EnPunctuation="""!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~"""
462
491
  nltk_en_tags={'CC': '并列连词', 'CD': '基数词', 'DT': '限定符', 'EX': '存在词', 'FW': '外来词', 'IN': '介词或从属连词', 'JJ': '形容词', 'JJR': '比较级的形容词', 'JJS': '最高级的形容词', 'LS': '列表项标记', 'MD': '情态动词', 'NN': '名词单数', 'NNS': '名词复数', 'NNP': '专有名词', 'NNPS': '专有名词复数', 'PDT': '前置限定词', 'POS': '所有格结尾', 'PRP': '人称代词', 'PRP$': '所有格代词', 'RB': '副词', 'RBR': '副词比较级', 'RBS': '副词最高级', 'RP': '小品词', 'SYM': '符号', 'UH': '感叹词', 'VB': '动词原型', 'VBD': '动词过去式', 'VBG': '动名词或现在分词', 'VBN': '动词过去分词', 'VBP': '非第三人称单数的现在时', 'VBZ': '第三人称单数的现在时', 'WDT': '以wh开头的限定词', 'WP': '以wh开头的代词', 'WP$': '以wh开头的所有格代词', 'WRB': '以wh开头的副词', 'TO': 'to'}
463
492
  nltk_tag_mapping={'NN': 'Noun', 'NNS': 'Noun', 'NNP': 'Noun', 'NNPS': 'Noun', 'VB': 'Verb', 'VBD': 'Verb', 'VBG': 'Verb', 'VBN': 'Verb', 'VBP': 'Verb', 'VBZ': 'Verb', 'JJ': 'Adjective', 'JJR': 'Adjective', 'JJS': 'Adjective', 'RB': 'Adverb', 'RBR': 'Adverb', 'RBS': 'Adverb', 'IN': 'Preposition', 'PRP': 'Pronoun', 'PRP$': 'Pronoun', 'DT': 'Determiner', 'CC': 'Conjunction', 'CD': 'Numeral', 'UH': 'Interjection', 'FW': 'Foreign Word', 'TO': 'Particle', 'EX': 'Existential "there"', 'MD': 'Modal Auxiliary', 'WDT': 'Wh-determiner', 'WP': 'Wh-pronoun', 'WP$': 'Possessive wh-pronoun', 'WRB': 'Wh-adverb', 'SYM': 'Symbol', 'RP': 'Particle', 'POS': 'Possessive ending', 'PDT': 'Predeterminer', 'LS': 'List item marker', 'NIL': 'Missing tag'}
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PgsFile
3
- Version: 0.2.1
4
- Summary: This module aims to simplify Python package management, script execution, file handling, web scraping, multimedia download, data cleaning, NLP tasks, and word list generation for literary students, making it more accessible and convenient to use.
3
+ Version: 0.2.2
4
+ Summary: This module aims to simplify Python package management, script execution, file handling, web scraping, multimedia download, data cleaning, NLP tasks like Chinese word tokenization and POS tagging, and word list generation for literary students, making it more accessible and convenient to use.
5
5
  Home-page: https://mp.weixin.qq.com/s/12-KVLfaPszoZkCxuRd-nQ?token=1589547443&lang=zh_CN
6
6
  Author: Pan Guisheng
7
7
  Author-email: 895284504@qq.com
@@ -12,6 +12,7 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.8
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
+ Requires-Dist: chardet
15
16
  Requires-Dist: pandas
16
17
  Requires-Dist: python-docx
17
18
  Requires-Dist: pip
@@ -1,4 +1,4 @@
1
- PgsFile/PgsFile.py,sha256=o6J3tipdCBkA0JvUz6vckZH_YlAgQmlAGQOMKdXb95M,82975
1
+ PgsFile/PgsFile.py,sha256=BQNZBrBYgyB_4TVxD0CJ6cMpiaaDzL9b7c7kcYtxmwQ,83682
2
2
  PgsFile/__init__.py,sha256=-Vy1SIh-BYopiEan-EjBtwqZsNteNrOqkws7hUj1d2w,2378
3
3
  PgsFile/Corpora/Idioms/English_Idioms_8774.txt,sha256=qlsP0yI_XGECBRiPZuLkGZpdasc77sWSKexANu7v8_M,175905
4
4
  PgsFile/Corpora/Monolingual/Chinese/People's Daily 20130605/Raw/00000000.txt,sha256=SLGGSMSb7Ff1RoBstsTW3yX2wNZpqEUchFNpcI-mrR4,1513
@@ -2618,8 +2618,8 @@ PgsFile/models/slovene.pickle,sha256=faxlAhKzeHs5mWwBvSCEEVST5vbsOQurYfdnUlsIuOo
2618
2618
  PgsFile/models/spanish.pickle,sha256=Jx3GAnxKrgVvcqm_q1ZFz2fhmL9PlyiVhE5A9ZiczcM,597831
2619
2619
  PgsFile/models/swedish.pickle,sha256=QNUOva1sqodxXy4wCxIX7JLELeIFpUPMSlaQO9LJrPo,1034496
2620
2620
  PgsFile/models/turkish.pickle,sha256=065H12UB0CdpiAnRLnUpLJw5KRBIhUM0KAL5Xbl2XMw,1225013
2621
- PgsFile-0.2.1.dist-info/LICENSE,sha256=cE5c-QToSkG1KTUsU8drQXz1vG0EbJWuU4ybHTRb5SE,1138
2622
- PgsFile-0.2.1.dist-info/METADATA,sha256=PCrjMATNQrsqPfsVVC15cmOinp-o3HYR88kLMcsn2lA,4999
2623
- PgsFile-0.2.1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
2624
- PgsFile-0.2.1.dist-info/top_level.txt,sha256=028hCfwhF3UpfD6X0rwtWpXI1RKSTeZ1ALwagWaSmX8,8
2625
- PgsFile-0.2.1.dist-info/RECORD,,
2621
+ PgsFile-0.2.2.dist-info/LICENSE,sha256=cE5c-QToSkG1KTUsU8drQXz1vG0EbJWuU4ybHTRb5SE,1138
2622
+ PgsFile-0.2.2.dist-info/METADATA,sha256=1fm2uh-uYKgDe26DvUGCmj2LbMcjwDum113nbmW-MIA,5070
2623
+ PgsFile-0.2.2.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
2624
+ PgsFile-0.2.2.dist-info/top_level.txt,sha256=028hCfwhF3UpfD6X0rwtWpXI1RKSTeZ1ALwagWaSmX8,8
2625
+ PgsFile-0.2.2.dist-info/RECORD,,