PgsFile 0.4.6__py3-none-any.whl → 0.4.7__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 +52 -1
- PgsFile/__init__.py +1 -0
- {PgsFile-0.4.6.dist-info → PgsFile-0.4.7.dist-info}/METADATA +1 -1
- {PgsFile-0.4.6.dist-info → PgsFile-0.4.7.dist-info}/RECORD +7 -7
- {PgsFile-0.4.6.dist-info → PgsFile-0.4.7.dist-info}/LICENSE +0 -0
- {PgsFile-0.4.6.dist-info → PgsFile-0.4.7.dist-info}/WHEEL +0 -0
- {PgsFile-0.4.6.dist-info → PgsFile-0.4.7.dist-info}/top_level.txt +0 -0
PgsFile/PgsFile.py
CHANGED
|
@@ -4090,4 +4090,55 @@ def markdown_to_python_object(data):
|
|
|
4090
4090
|
return ast.literal_eval(code_str)
|
|
4091
4091
|
except Exception:
|
|
4092
4092
|
return code_str.strip()
|
|
4093
|
-
|
|
4093
|
+
|
|
4094
|
+
|
|
4095
|
+
import math
|
|
4096
|
+
from collections import defaultdict, Counter
|
|
4097
|
+
|
|
4098
|
+
def tfidf_keyword_extraction(documents, top_percent=(0.0, 0.10)):
|
|
4099
|
+
"""
|
|
4100
|
+
Extract keywords from a small set of tokenized documents using TF-IDF.
|
|
4101
|
+
|
|
4102
|
+
Parameters
|
|
4103
|
+
----------
|
|
4104
|
+
documents : list of list of str
|
|
4105
|
+
Corpus represented as tokenized documents.
|
|
4106
|
+
top_percent : tuple of float
|
|
4107
|
+
Range of percentage (low, high) to select top keyword candidates.
|
|
4108
|
+
|
|
4109
|
+
Returns
|
|
4110
|
+
-------
|
|
4111
|
+
full_list : list of tuple
|
|
4112
|
+
All (term, tf-idf_score) sorted by score in descending order.
|
|
4113
|
+
candidates : list of tuple
|
|
4114
|
+
Keyword candidates from top_10% range.
|
|
4115
|
+
"""
|
|
4116
|
+
log = math.log # local reference for speed
|
|
4117
|
+
|
|
4118
|
+
# Step 1: Compute IDF
|
|
4119
|
+
total_docs = len(documents)
|
|
4120
|
+
doc_freq = defaultdict(int)
|
|
4121
|
+
for doc in documents:
|
|
4122
|
+
for term in set(doc):
|
|
4123
|
+
doc_freq[term] += 1
|
|
4124
|
+
idf = {term: log((total_docs + 1) / (df + 1)) + 1 for term, df in doc_freq.items()}
|
|
4125
|
+
|
|
4126
|
+
# Step 2: Compute TF-IDF
|
|
4127
|
+
tfidf_scores = {}
|
|
4128
|
+
for doc in documents:
|
|
4129
|
+
total_terms = len(doc)
|
|
4130
|
+
term_counts = Counter(doc)
|
|
4131
|
+
for term, count in term_counts.items():
|
|
4132
|
+
tfidf_scores[term] = (count / total_terms) * idf[term] # overwrite as before
|
|
4133
|
+
|
|
4134
|
+
# Step 3: Sort full list
|
|
4135
|
+
full_list = sorted(tfidf_scores.items(), key=lambda x: x[1], reverse=True)
|
|
4136
|
+
|
|
4137
|
+
# Step 4: Extract candidates based on percentage range
|
|
4138
|
+
n_terms = len(full_list)
|
|
4139
|
+
low_cut = int(n_terms * top_percent[0])
|
|
4140
|
+
high_cut = int(n_terms * top_percent[1])
|
|
4141
|
+
candidates = full_list[low_cut:high_cut] # slice range
|
|
4142
|
+
|
|
4143
|
+
return full_list, candidates
|
|
4144
|
+
|
PgsFile/__init__.py
CHANGED
|
@@ -53,6 +53,7 @@ from .PgsFile import word_lemmatize, word_POS, word_NER
|
|
|
53
53
|
from .PgsFile import extract_noun_phrases, get_LLMs_prompt, extract_keywords_en, extract_keywords_en_be21
|
|
54
54
|
from .PgsFile import extract_dependency_relations, extract_dependency_relations_full
|
|
55
55
|
from .PgsFile import predict_category
|
|
56
|
+
from .PgsFile import tfidf_keyword_extraction
|
|
56
57
|
|
|
57
58
|
# 8. Maths
|
|
58
59
|
from .PgsFile import len_rows, check_empty_cells
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PgsFile
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.7
|
|
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 OCR, tokenization, lemmatization, POS tagging, NER, ATE, 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/lWMkYDWQMjBJNKY2vMYTpw
|
|
6
6
|
Author: Pan Guisheng
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
PgsFile/PgsFile.py,sha256=
|
|
2
|
-
PgsFile/__init__.py,sha256=
|
|
1
|
+
PgsFile/PgsFile.py,sha256=3iyfFE5THgwwz0_MtylUlMn-72gsRaCbUxdm9LcI8nQ,169903
|
|
2
|
+
PgsFile/__init__.py,sha256=mWZ8dfTlzeCfTHFlWyHY3vCwqyM4_YQBGPd6vBoNGso,3674
|
|
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
|
|
@@ -2591,8 +2591,8 @@ PgsFile/models/prompts/3. ICTCLAS Prompt.txt,sha256=VFn6N_JViAbyy9NazA8gjX6SGo5m
|
|
|
2591
2591
|
PgsFile/models/prompts/4. OCR prompt.txt,sha256=YxUQ2IlE52k0fcBnGsuOHqWAmfiEmIu6iRz5zecQ8dk,260
|
|
2592
2592
|
PgsFile/models/prompts/5. ATE prompt.txt,sha256=5wu0gGlsV7DI0LruYM3-uAC6brppyYD0IoiFVjMqm5Y,1553
|
|
2593
2593
|
PgsFile/models/prompts/6. ATE3 prompt.txt,sha256=VnaXpPa6BgZHUcm8PxmP_qgU-8xEoTB3XcBqjwCUy_g,1254
|
|
2594
|
-
PgsFile-0.4.
|
|
2595
|
-
PgsFile-0.4.
|
|
2596
|
-
PgsFile-0.4.
|
|
2597
|
-
PgsFile-0.4.
|
|
2598
|
-
PgsFile-0.4.
|
|
2594
|
+
PgsFile-0.4.7.dist-info/LICENSE,sha256=cE5c-QToSkG1KTUsU8drQXz1vG0EbJWuU4ybHTRb5SE,1138
|
|
2595
|
+
PgsFile-0.4.7.dist-info/METADATA,sha256=AUDP0QL-_-2YKDZyH6i5dz7DrFmJO50TuGr5QqnkQhw,2994
|
|
2596
|
+
PgsFile-0.4.7.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
|
2597
|
+
PgsFile-0.4.7.dist-info/top_level.txt,sha256=028hCfwhF3UpfD6X0rwtWpXI1RKSTeZ1ALwagWaSmX8,8
|
|
2598
|
+
PgsFile-0.4.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|