PgsFile 0.4.9__py3-none-any.whl → 0.5.1__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.
PgsFile/PgsFile.py CHANGED
@@ -4142,3 +4142,142 @@ def tfidf_keyword_extraction(documents, top_percent=(0.0, 0.10)):
4142
4142
 
4143
4143
  return full_list, candidates
4144
4144
 
4145
+
4146
+ from xml.dom.minidom import Document
4147
+ from datetime import datetime
4148
+ def maketmx(
4149
+ tmx_path,
4150
+ source_list,
4151
+ target_list,
4152
+ source_lang="zh-CN",
4153
+ target_lang="en-US",
4154
+ author="Petercusin",
4155
+ client_name=None,
4156
+ project_id=None,
4157
+ domain=None,
4158
+ status="Final"
4159
+ ):
4160
+ """
4161
+ Generate a TMX (Translation Memory eXchange) file for any two language pairs, with optional metadata.
4162
+
4163
+ Parameters
4164
+ ----------
4165
+ tmx_path : str
4166
+ Path to save the TMX file, e.g., "translation_memory.tmx".
4167
+ source_list : list of str
4168
+ List of source language segments, e.g., ["你好", "再见"].
4169
+ target_list : list of str
4170
+ List of target language segments, e.g., ["Hello", "Goodbye"].
4171
+ **Must have the same number of elements as `source_list`.**
4172
+ source_lang : str, optional
4173
+ Source language code, e.g., "zh-CN" (default), "fr-FR", "de-DE".
4174
+ target_lang : str, optional
4175
+ Target language code, e.g., "en-US" (default), "es-ES", "ja-JP".
4176
+ author : str, optional
4177
+ Author of the TMX file, e.g., "Petercusin" (default).
4178
+ client_name : str, optional
4179
+ Name of the client or company, e.g., "Acme Corp".
4180
+ project_id : str, optional
4181
+ Project identifier, e.g., "Project_XYZ_2025".
4182
+ domain : str, optional
4183
+ Domain or subject field, e.g., "Medical", "Legal", "Technical".
4184
+ status : str, optional
4185
+ Translation status, e.g., "Draft", "Reviewed", "Final" (default).
4186
+
4187
+ Returns
4188
+ -------
4189
+ None
4190
+ Writes the TMX file to the specified path.
4191
+
4192
+ Raises
4193
+ ------
4194
+ ValueError
4195
+ If `source_list` and `target_list` have different lengths.
4196
+
4197
+ Example
4198
+ -------
4199
+ # Chinese to English, with metadata
4200
+ maketmx(
4201
+ "zh_en.tmx",
4202
+ ["你好", "再见"],
4203
+ ["Hello", "Goodbye"],
4204
+ "zh-CN",
4205
+ "en-US",
4206
+ author="Dr. Guisheng PAN",
4207
+ client_name="Acme Corp",
4208
+ project_id="Project_XYZ_2025",
4209
+ domain="Technical",
4210
+ status="Final"
4211
+ )
4212
+ """
4213
+ if len(source_list) != len(target_list):
4214
+ raise ValueError("source_list and target_list must have the same number of elements.")
4215
+
4216
+ doc = Document()
4217
+ tmx = doc.createElement("tmx")
4218
+ tmx.setAttribute("version", "1.4")
4219
+ doc.appendChild(tmx)
4220
+
4221
+ header = doc.createElement("header")
4222
+ header.setAttribute("creationtool", "PgsFile")
4223
+ header.setAttribute("creationtoolversion", "0.5.1")
4224
+ header.setAttribute("creationtooldeveloper", author)
4225
+ header.setAttribute("creationdate", datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"))
4226
+ header.setAttribute("srclang", source_lang)
4227
+ header.setAttribute("trtlang", target_lang)
4228
+ header.setAttribute("datatype", "plaintext")
4229
+ header.setAttribute("segtype", "sentence")
4230
+ header.setAttribute("adminlang", "en-US")
4231
+ header.setAttribute("o-tmf", "PgsFile_TM")
4232
+ tmx.appendChild(header)
4233
+
4234
+ # Add optional metadata as <prop> elements
4235
+ if client_name:
4236
+ prop = doc.createElement("prop")
4237
+ prop.setAttribute("type", "x-Client")
4238
+ prop.appendChild(doc.createTextNode(client_name))
4239
+ header.appendChild(prop)
4240
+ if project_id:
4241
+ prop = doc.createElement("prop")
4242
+ prop.setAttribute("type", "x-Project")
4243
+ prop.appendChild(doc.createTextNode(project_id))
4244
+ header.appendChild(prop)
4245
+ if domain:
4246
+ prop = doc.createElement("prop")
4247
+ prop.setAttribute("type", "x-Domain")
4248
+ prop.appendChild(doc.createTextNode(domain))
4249
+ header.appendChild(prop)
4250
+ if status:
4251
+ prop = doc.createElement("prop")
4252
+ prop.setAttribute("type", "x-Status")
4253
+ prop.appendChild(doc.createTextNode(status))
4254
+ header.appendChild(prop)
4255
+
4256
+ body = doc.createElement("body")
4257
+ tmx.appendChild(body)
4258
+
4259
+ for i in range(len(source_list)):
4260
+ tu = doc.createElement("tu")
4261
+ body.appendChild(tu)
4262
+
4263
+ # Source language segment
4264
+ tuv = doc.createElement("tuv")
4265
+ tuv.setAttribute("xml:lang", source_lang)
4266
+ tu.appendChild(tuv)
4267
+ seg = doc.createElement("seg")
4268
+ seg_text = doc.createTextNode(source_list[i])
4269
+ seg.appendChild(seg_text)
4270
+ tuv.appendChild(seg)
4271
+
4272
+ # Target language segment
4273
+ tuv = doc.createElement("tuv")
4274
+ tuv.setAttribute("xml:lang", target_lang)
4275
+ tu.appendChild(tuv)
4276
+ seg = doc.createElement("seg")
4277
+ seg_text = doc.createTextNode(target_list[i])
4278
+ seg.appendChild(seg_text)
4279
+ tuv.appendChild(seg)
4280
+
4281
+ with open(tmx_path, 'w', encoding='utf-8') as f:
4282
+ doc.writexml(f, indent='\t', newl='\n', addindent='\t')
4283
+
PgsFile/__init__.py CHANGED
@@ -19,6 +19,7 @@ from .PgsFile import mhtml2html
19
19
  # 4. Text data storage
20
20
  from .PgsFile import write_to_txt, write_to_excel, write_to_json, write_to_json_lines, append_dict_to_json, save_dict_to_excel, file_to_list_of_dicts
21
21
  from .PgsFile import write_to_excel_normal
22
+ from .PgsFile import maketmx
22
23
 
23
24
  # 5. File/folder process
24
25
  from .PgsFile import FilePath, FileName, DirList
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PgsFile
3
- Version: 0.4.9
3
+ Version: 0.5.1
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, MIP analysis and Chinese-English sentence alignment. 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
@@ -31,7 +31,7 @@ Key Features:
31
31
  1. **Web Scraping:** Easily scrape data from websites and download multimedia content.
32
32
  2. **Package Management:** Install, uninstall, and manage Python packages with simple commands.
33
33
  3. **Data Retrieval:** Extract data from various file formats like text, JSON, TSV, Excel, XML, and HTML (both online and offline).
34
- 4. **Data Storage:** Write and append data to text files, Excel, JSON, and JSON lines.
34
+ 4. **Data Storage:** Write and append data to text files, Excel, JSON, TMX, 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, convert Markdown strings into Python objects, and prepare data for analysis, utilizing valuable corpora and dictionaries such as CET-4/6 vocabulary, BE21 and BNC-COCA word lists.
37
37
  7. **NLP:** Perform OCR, word tokenization, lemmatization, POS tagging, NER, dependency parsing, ATE, MDD, WSD, LIWC, MIP analysis, and Chinese-English sentence alignment using prepared LLM prompts.
@@ -1,5 +1,5 @@
1
- PgsFile/PgsFile.py,sha256=3iyfFE5THgwwz0_MtylUlMn-72gsRaCbUxdm9LcI8nQ,169903
2
- PgsFile/__init__.py,sha256=mWZ8dfTlzeCfTHFlWyHY3vCwqyM4_YQBGPd6vBoNGso,3674
1
+ PgsFile/PgsFile.py,sha256=YzdCEPFvT1jisKcihRUNyi2hqAWhStkP-yIcj_xqiLI,174646
2
+ PgsFile/__init__.py,sha256=YkDTLWtveSeN4I5ZXSmdp7YZFOHb4yEzxQB82DEHk9s,3704
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
@@ -2593,8 +2593,8 @@ PgsFile/models/prompts/5. ATE prompt.txt,sha256=5wu0gGlsV7DI0LruYM3-uAC6brppyYD0
2593
2593
  PgsFile/models/prompts/6. ATE3 prompt.txt,sha256=VnaXpPa6BgZHUcm8PxmP_qgU-8xEoTB3XcBqjwCUy_g,1254
2594
2594
  PgsFile/models/prompts/7. SentAlign prompt.txt,sha256=hXpqqC-CAgo8EytkJ0MaLhevLefALazWriY-ew39jxs,1537
2595
2595
  PgsFile/models/prompts/8. TitleCase prompt.txt,sha256=4p-LfGy0xAj2uPi9amyMm41T6Z17VNpFFsGZOgWhROs,1136
2596
- PgsFile-0.4.9.dist-info/LICENSE,sha256=cE5c-QToSkG1KTUsU8drQXz1vG0EbJWuU4ybHTRb5SE,1138
2597
- PgsFile-0.4.9.dist-info/METADATA,sha256=kz9wjDsNe156XAqCCKTveiOLPnvkOGbbjR1j8NkRNaM,3065
2598
- PgsFile-0.4.9.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
2599
- PgsFile-0.4.9.dist-info/top_level.txt,sha256=028hCfwhF3UpfD6X0rwtWpXI1RKSTeZ1ALwagWaSmX8,8
2600
- PgsFile-0.4.9.dist-info/RECORD,,
2596
+ PgsFile-0.5.1.dist-info/LICENSE,sha256=cE5c-QToSkG1KTUsU8drQXz1vG0EbJWuU4ybHTRb5SE,1138
2597
+ PgsFile-0.5.1.dist-info/METADATA,sha256=AcQetbNOrw-Celapsr7Lz5P_CzikMR1jwf6OENgyUNU,3070
2598
+ PgsFile-0.5.1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
2599
+ PgsFile-0.5.1.dist-info/top_level.txt,sha256=028hCfwhF3UpfD6X0rwtWpXI1RKSTeZ1ALwagWaSmX8,8
2600
+ PgsFile-0.5.1.dist-info/RECORD,,