PgsFile 0.1.8__py3-none-any.whl → 0.2.0__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
@@ -69,7 +69,7 @@ def get_data_text(path):
69
69
  path : TYPE string
70
70
  DESCRIPTION.
71
71
  Using path to get data from a single txt file. eg. raw_text.txt
72
- Theoretically, it supports all the text encoding formats, like utf-8, unicode, ansi, gbk etc.
72
+ Theoretically, it supports common text encoding formats, like utf-8, unicode, ansi, gbk etc.
73
73
 
74
74
  Returns
75
75
  -------
@@ -78,16 +78,13 @@ def get_data_text(path):
78
78
  It returns all the text content from the target file.
79
79
 
80
80
  '''
81
- import chardet
82
- path=path.replace("\n","")
83
- f=open(path,'rb')
84
- data=f.read()
85
- f.close()
86
- file_encoding=chardet.detect(data).get('encoding')
87
- f1=open(path,'r', encoding=file_encoding, errors='ignore')
88
- text=f1.read().replace("’","'")
89
- f1.close()
90
- return text
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
91
88
 
92
89
  def get_data_lines(path):
93
90
  '''
@@ -96,7 +93,7 @@ def get_data_lines(path):
96
93
  path : TYPE string
97
94
  DESCRIPTION.
98
95
  Using path to get data from a single txt file. eg. raw_text.txt
99
- Theoretically, it supports all the text encoding formats, like utf-8, unicode, ansi, gbk etc.
96
+ Theoretically, it supports common the text encoding formats, like utf-8, unicode, ansi, gbk etc.
100
97
 
101
98
  Returns
102
99
  -------
@@ -105,17 +102,13 @@ def get_data_lines(path):
105
102
  It returns a list containing all the paragraphs of the target file.
106
103
 
107
104
  '''
108
- import chardet
109
- path=path.replace("\n","")
110
- f=open(path,'rb')
111
- data=f.read()
112
- f.close()
113
- file_encoding=chardet.detect(data).get('encoding')
114
- f1=open(path,'r', encoding=file_encoding, errors='ignore')
115
- lines=f1.readlines()
116
- lines=[l.replace("’","'") for l in lines if len(l.strip()) !=0]
117
- f1.close()
118
- return lines
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
112
 
120
113
  def write_to_txt(file_path,text,mode=None,encoding=None):
121
114
  '''
@@ -464,6 +457,7 @@ BigPunctuation="""!"#$&\'()*+,-/:;<=>?@[\\]^_`{|}.%~"#$%&'?。()
464
457
  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 / #?/ --/""" #用来停用词性标注
465
458
  Special="""∶ ■ ● ① ② ③ × ℃ Ⅲ ④ ⑤ ◆ ⑥ ± ⑦ ⑧ → ⑨ ▲ ⑩ ─ ÷ μ γ β Ⅱ Ⅰ ‰ □ 〇 ○ Ⅴ Ⅳ ★ ﹐ ° ※ ︰ α ― ≠ █ о θ ω ⒈ ⒉ ⒊ н ≤ ì ǎ ≥ р т с к й а и Ⅵ é è ﹢ ﹝ ﹞  ā ⒋ ù π ◇ Ω Ф ы Я п К в у м ǒ ü á ǔ ⒌ ⒍ 䦆 Ⅹ Ⅶ ← """
466
459
  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']
467
461
  EnPunctuation="""!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~"""
468
462
  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'}
469
463
  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'}
@@ -1165,6 +1159,14 @@ def run_command(command: str) -> str:
1165
1159
 
1166
1160
  return output_str
1167
1161
 
1162
+ # Import the urllib.parse module to handle URL encoding
1163
+ import urllib.parse
1164
+ # Define a function to URL-encode a Chinese keyword
1165
+ def encode_chinese_keyword_for_url(chinese_keyword):
1166
+ # Use urllib.parse.quote to encode the Chinese keyword
1167
+ encoded_keyword = urllib.parse.quote(chinese_keyword)
1168
+ # Return the encoded keyword
1169
+ return encoded_keyword
1168
1170
 
1169
1171
  import random
1170
1172
  import requests
@@ -1679,4 +1681,30 @@ def get_data_table_html_string(html_string, output_file, most_rows=True):
1679
1681
  print(f"Data has been saved to {output_file}")
1680
1682
  except Exception as err:
1681
1683
  print(f"Errors found! {err}")
1682
- return None
1684
+ return None
1685
+
1686
+ import importlib.metadata
1687
+ def get_library_location(library_name):
1688
+ distribution = importlib.metadata.distribution(library_name)
1689
+ return str(distribution.locate_file(''))
1690
+
1691
+ def get_stopwords(language=None):
1692
+ '''
1693
+ Parameters
1694
+ ----------
1695
+ language : TYPE, string: like 'english', 'chinese', etc.
1696
+ DESCRIPTION. The default is None.
1697
+
1698
+ Returns
1699
+ -------
1700
+ TYPE, list: like ["'ll", "'tis", "'twas", "'ve", '10', '39', 'a', "a's", 'able', 'ableabout', 'about', 'above', 'abroad', 'abst']
1701
+ DESCRIPTION. The default will return a list of English stopwords.
1702
+
1703
+ '''
1704
+ stopwords_path=get_library_location("PgsFile")+"/PgsFile/Corpora/Stopwords"
1705
+ if language is None:
1706
+ en_stopwords=get_data_lines(find_txt_files_with_keyword(stopwords_path, "english")[0])
1707
+ return en_stopwords
1708
+ else:
1709
+ lang_stopwords=get_data_lines(find_txt_files_with_keyword(stopwords_path, language)[0])
1710
+ return lang_stopwords
PgsFile/__init__.py CHANGED
@@ -1,11 +1,12 @@
1
1
  # 1. Web scraping
2
2
  from .PgsFile import PGScraper
3
3
  from .PgsFile import audiovisual_downloader
4
- from .PgsFile import headers
4
+ from .PgsFile import headers, encode_chinese_keyword_for_url
5
5
 
6
6
  # 2. Package/library management
7
7
  from .PgsFile import install_package, uninstall_package
8
8
  from .PgsFile import run_script, run_command
9
+ from .PgsFile import get_library_location
9
10
 
10
11
  # 3. Text data retrieval
11
12
  from .PgsFile import get_data_text, get_data_lines, get_json_lines, get_tsv_lines
@@ -25,7 +26,7 @@ from .PgsFile import remove_empty_folders, remove_empty_txts, remove_empty_lines
25
26
 
26
27
  # 6. Data cleaning
27
28
  from .PgsFile import BigPunctuation, StopTags, Special, yhd
28
- from .PgsFile import ZhStopWords, EnPunctuation
29
+ from .PgsFile import ZhStopWords, EnPunctuation, get_stopwords
29
30
  from .PgsFile import nltk_en_tags, nltk_tag_mapping, thulac_tags, ICTCLAS2008, LangCodes, pgs_abbres_words
30
31
  from .PgsFile import check_contain_chinese, check_contain_number
31
32
  from .PgsFile import replace_chinese_punctuation_with_english
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PgsFile
3
- Version: 0.1.8
3
+ Version: 0.2.0
4
4
  Summary: This module aims to simplify Python package management, script execution, file handling, web scraping, multimedia download, data cleaning, and word list generation for literary students, making it more accessible and convenient to use.
5
- Home-page: https://mp.weixin.qq.com/s/F94jyCBOQ3VmiPmSjv6ZAw
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
8
8
  License: Educational free
@@ -12,7 +12,6 @@ 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
16
15
  Requires-Dist: pandas
17
16
  Requires-Dist: python-docx
18
17
  Requires-Dist: pip
@@ -1,5 +1,5 @@
1
- PgsFile/PgsFile.py,sha256=70VLJybFPPbaxPxb5z_vnbEZG9fVgkO7nxcxI77auUI,79354
2
- PgsFile/__init__.py,sha256=vJqj1rfxK-2UrS4m3nCg0yglqsF_8P-DPAnDgxTdAj8,2227
1
+ PgsFile/PgsFile.py,sha256=1-PR4NO2FF7lO8_lQmSP_VLVs6pV8jC_5_nOdGvwuhk,80684
2
+ PgsFile/__init__.py,sha256=Tbr3MaFP7ZqhwVaYAnBJx7UBJhM4c884F8sFMQjfzXU,2317
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
5
5
  PgsFile/Corpora/Monolingual/Chinese/People's Daily 20130605/Raw/00000001.txt,sha256=imOa6UoCOIZoPXT4_HNHgCUJtd4FTIdk2FZNHNBgJyg,3372
@@ -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.1.8.dist-info/LICENSE,sha256=cE5c-QToSkG1KTUsU8drQXz1vG0EbJWuU4ybHTRb5SE,1138
2622
- PgsFile-0.1.8.dist-info/METADATA,sha256=oSsVQL9ZZBLhk83DN22SrtrSh3r_V8D7ILYfHv1SJbo,4955
2623
- PgsFile-0.1.8.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
2624
- PgsFile-0.1.8.dist-info/top_level.txt,sha256=028hCfwhF3UpfD6X0rwtWpXI1RKSTeZ1ALwagWaSmX8,8
2625
- PgsFile-0.1.8.dist-info/RECORD,,
2621
+ PgsFile-0.2.0.dist-info/LICENSE,sha256=cE5c-QToSkG1KTUsU8drQXz1vG0EbJWuU4ybHTRb5SE,1138
2622
+ PgsFile-0.2.0.dist-info/METADATA,sha256=u-nzDLhOIJYZ-nOp9FpE5EFWsjW3683viOehOfqQIvs,4959
2623
+ PgsFile-0.2.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
2624
+ PgsFile-0.2.0.dist-info/top_level.txt,sha256=028hCfwhF3UpfD6X0rwtWpXI1RKSTeZ1ALwagWaSmX8,8
2625
+ PgsFile-0.2.0.dist-info/RECORD,,