PgsFile 0.3.9__py3-none-any.whl → 0.4.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 +50 -1
- PgsFile/__init__.py +1 -1
- {PgsFile-0.3.9.dist-info → PgsFile-0.4.0.dist-info}/METADATA +3 -3
- {PgsFile-0.3.9.dist-info → PgsFile-0.4.0.dist-info}/RECORD +7 -7
- {PgsFile-0.3.9.dist-info → PgsFile-0.4.0.dist-info}/LICENSE +0 -0
- {PgsFile-0.3.9.dist-info → PgsFile-0.4.0.dist-info}/WHEEL +0 -0
- {PgsFile-0.3.9.dist-info → PgsFile-0.4.0.dist-info}/top_level.txt +0 -0
PgsFile/PgsFile.py
CHANGED
|
@@ -3819,7 +3819,7 @@ def calculate_log_likelihood(target_count, reference_count, total_target, total_
|
|
|
3819
3819
|
def extract_keywords_en(target_text, top_n=10):
|
|
3820
3820
|
"""Extract keywords from target text using log-likelihood with absolute reference frequencies."""
|
|
3821
3821
|
# Example usage
|
|
3822
|
-
my_dic_path = get_library_location("PgsFile")+"/PgsFile/models/dics/unigram_freq_only.json"
|
|
3822
|
+
my_dic_path = get_library_location("PgsFile")+"/PgsFile/models/dics/unigram_freq_only.json" # BNC_wordlist
|
|
3823
3823
|
reference_freq = get_data_json(my_dic_path)
|
|
3824
3824
|
# Tokenize target text and preserve original case
|
|
3825
3825
|
original_words = word_tokenize2(target_text)
|
|
@@ -3852,3 +3852,52 @@ def extract_keywords_en(target_text, top_n=10):
|
|
|
3852
3852
|
|
|
3853
3853
|
# Return top N keywords
|
|
3854
3854
|
return keyword_scores[:top_n]
|
|
3855
|
+
|
|
3856
|
+
def resize_image(input_image_path, output_image_path, max_size_kb):
|
|
3857
|
+
'''
|
|
3858
|
+
# Example 1: Resizing a JPG image
|
|
3859
|
+
input_image_path_jpg = 'example_input.jpg'
|
|
3860
|
+
output_image_path_jpg = 'example_output_resized.jpg'
|
|
3861
|
+
resize_image(input_image_path_jpg, output_image_path_jpg, max_size_kb=2048)
|
|
3862
|
+
|
|
3863
|
+
# Example 2: Resizing a PNG image
|
|
3864
|
+
input_image_path_png = 'example_input.png'
|
|
3865
|
+
output_image_path_png = 'example_output_resized.png'
|
|
3866
|
+
resize_image(input_image_path_png, output_image_path_png, max_size_kb=2048)
|
|
3867
|
+
'''
|
|
3868
|
+
# Open the image file
|
|
3869
|
+
with Image.open(input_image_path) as img:
|
|
3870
|
+
# Function to save the image and check its size
|
|
3871
|
+
def save_image(img, output_path, quality=95):
|
|
3872
|
+
if output_path.lower().endswith('.jpg'):
|
|
3873
|
+
img.save(output_path, 'JPEG', quality=quality)
|
|
3874
|
+
else:
|
|
3875
|
+
img.save(output_path, 'PNG', optimize=True)
|
|
3876
|
+
|
|
3877
|
+
# Initial save to check the size
|
|
3878
|
+
save_image(img, output_image_path)
|
|
3879
|
+
|
|
3880
|
+
# Check the size and reduce quality/dimensions if necessary
|
|
3881
|
+
size = os.path.getsize(output_image_path) // 1024 # Size in KB
|
|
3882
|
+
|
|
3883
|
+
# Reduce quality for JPG or optimize PNG
|
|
3884
|
+
quality = 95
|
|
3885
|
+
while size > max_size_kb:
|
|
3886
|
+
# Reduce dimensions
|
|
3887
|
+
width, height = img.size
|
|
3888
|
+
img = img.resize((int(width * 0.9), int(height * 0.9)), Image.LANCZOS)
|
|
3889
|
+
|
|
3890
|
+
# Save the image
|
|
3891
|
+
save_image(img, output_image_path, quality)
|
|
3892
|
+
size = os.path.getsize(output_image_path) // 1024
|
|
3893
|
+
|
|
3894
|
+
# Reduce quality for JPG
|
|
3895
|
+
if output_image_path.lower().endswith('.jpg'):
|
|
3896
|
+
quality -= 5
|
|
3897
|
+
if quality < 10: # Prevent quality from going too low
|
|
3898
|
+
break
|
|
3899
|
+
|
|
3900
|
+
if size <= max_size_kb:
|
|
3901
|
+
print(f"Image resized successfully to {size} KB.")
|
|
3902
|
+
else:
|
|
3903
|
+
print("Could not reduce the image size below 2MB.")
|
PgsFile/__init__.py
CHANGED
|
@@ -63,6 +63,6 @@ from .PgsFile import timeit
|
|
|
63
63
|
# 9. Visualization
|
|
64
64
|
from .PgsFile import replace_white_with_transparency
|
|
65
65
|
from .PgsFile import simhei_default_font_path_MacOS_Windows
|
|
66
|
-
from .PgsFile import get_font_path
|
|
66
|
+
from .PgsFile import get_font_path, resize_image
|
|
67
67
|
|
|
68
68
|
name = "PgsFile"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PgsFile
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: This module simplifies Python package management, script execution, file handling, web scraping, and multimedia downloads. The module supports (LLM-based) NLP tasks such as tokenization, lemmatization, POS tagging, NER, keywords extraction, dependency parsing, MDD, WSD, LIWC, and MIP analysis. It also generates word lists, and plots data, aiding literary students. Ideal for scraping data, cleaning text, and analyzing language, it offers user-friendly tools to streamline workflows.
|
|
5
5
|
Home-page: https://mp.weixin.qq.com/s/12-KVLfaPszoZkCxuRd-nQ?token=1589547443&lang=zh_CN
|
|
6
6
|
Author: Pan Guisheng
|
|
@@ -34,9 +34,9 @@ Key Features:
|
|
|
34
34
|
4. **Data Storage:** Write and append data to text files, Excel, JSON, and JSON lines.
|
|
35
35
|
5. **File and Folder Processing:** Manage file paths, create directories, move or copy files, and search for files with specific keywords.
|
|
36
36
|
6. **Data Cleaning:** Clean text, handle punctuation, remove stopwords, and prepare data for analysis, utilizing valuable corpora and dictionaries such as CET-4/6 vocabulary and BNC-COCA word lists.
|
|
37
|
-
7. **NLP:** Perform word tokenization, lemmatization, POS tagging, NER, dependency parsing, MDD, WSD, LIWC, and MIP analysis using prepared LLM prompts.
|
|
37
|
+
7. **NLP:** Perform word tokenization, lemmatization, POS tagging, NER, dependency parsing, keywords extraction, MDD, WSD, LIWC, and MIP analysis using prepared LLM prompts.
|
|
38
38
|
8. **Math Operations:** Format numbers, convert decimals to percentages, and validate data.
|
|
39
|
-
9. **Visualization:** Process images (e.g., make white pixels transparent) and manage fonts for rendering text.
|
|
39
|
+
9. **Visualization:** Process images (e.g., make white pixels transparent, resize images) and manage fonts for rendering text.
|
|
40
40
|
|
|
41
41
|
Author: Pan Guisheng, a PhD student at the Graduate Institute of Interpretation and Translation of Shanghai International Studies University
|
|
42
42
|
Email: 895284504@qq.com
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
PgsFile/PgsFile.py,sha256=
|
|
2
|
-
PgsFile/__init__.py,sha256=
|
|
1
|
+
PgsFile/PgsFile.py,sha256=Ko2HpUkWdNM8vAQy9wCkbFNDMuAQ2fQCCQy-IEeBWy4,161852
|
|
2
|
+
PgsFile/__init__.py,sha256=nsKnjOskNjAsmtC88W62ARm5k9OGAqpo7_si66Mw0nM,3500
|
|
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
|
|
@@ -2586,8 +2586,8 @@ PgsFile/models/fonts/博洋行书3500.TTF,sha256=VrgeHr8cgOL6JD05QyuD9ZSyw4J2aIV
|
|
|
2586
2586
|
PgsFile/models/fonts/陆柬之行书字体.ttf,sha256=Zpd4Z7E9w-Qy74yklXHk4vM7HOtHuQgllvygxZZ1Hvs,1247288
|
|
2587
2587
|
PgsFile/models/prompts/1. MIP prompt.txt,sha256=4lHlHmleayRytqr1n9jtt6vn1rQvyf4BKeThpbwI8o8,1638
|
|
2588
2588
|
PgsFile/models/prompts/2. WSD prompt.txt,sha256=o-ZFtCRUCDrXgm040WTQch9v2Y_r2SIlrZaquilJjgQ,2348
|
|
2589
|
-
PgsFile-0.
|
|
2590
|
-
PgsFile-0.
|
|
2591
|
-
PgsFile-0.
|
|
2592
|
-
PgsFile-0.
|
|
2593
|
-
PgsFile-0.
|
|
2589
|
+
PgsFile-0.4.0.dist-info/LICENSE,sha256=cE5c-QToSkG1KTUsU8drQXz1vG0EbJWuU4ybHTRb5SE,1138
|
|
2590
|
+
PgsFile-0.4.0.dist-info/METADATA,sha256=OuxX_yi0yRKRnXyqS-QL5JEBbrbALHjEXvGg2w_gikY,2985
|
|
2591
|
+
PgsFile-0.4.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
|
2592
|
+
PgsFile-0.4.0.dist-info/top_level.txt,sha256=028hCfwhF3UpfD6X0rwtWpXI1RKSTeZ1ALwagWaSmX8,8
|
|
2593
|
+
PgsFile-0.4.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|