pybox-nlp 0.1.0__tar.gz
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.
- pybox_nlp-0.1.0/LICENSE +21 -0
- pybox_nlp-0.1.0/PKG-INFO +357 -0
- pybox_nlp-0.1.0/README.md +325 -0
- pybox_nlp-0.1.0/pyproject.toml +57 -0
- pybox_nlp-0.1.0/setup.cfg +4 -0
- pybox_nlp-0.1.0/src/pybox/__init__.py +57 -0
- pybox_nlp-0.1.0/src/pybox/core.py +163 -0
- pybox_nlp-0.1.0/src/pybox/programs/__init__.py +6 -0
- pybox_nlp-0.1.0/src/pybox/programs/eight.py +27 -0
- pybox_nlp-0.1.0/src/pybox/programs/eleven.py +36 -0
- pybox_nlp-0.1.0/src/pybox/programs/five.py +30 -0
- pybox_nlp-0.1.0/src/pybox/programs/four.py +40 -0
- pybox_nlp-0.1.0/src/pybox/programs/nine.py +41 -0
- pybox_nlp-0.1.0/src/pybox/programs/one.py +27 -0
- pybox_nlp-0.1.0/src/pybox/programs/seven.py +37 -0
- pybox_nlp-0.1.0/src/pybox/programs/six.py +59 -0
- pybox_nlp-0.1.0/src/pybox/programs/ten.py +29 -0
- pybox_nlp-0.1.0/src/pybox/programs/three.py +30 -0
- pybox_nlp-0.1.0/src/pybox/programs/two.py +23 -0
- pybox_nlp-0.1.0/src/pybox/py.typed +1 -0
- pybox_nlp-0.1.0/src/pybox_nlp.egg-info/PKG-INFO +357 -0
- pybox_nlp-0.1.0/src/pybox_nlp.egg-info/SOURCES.txt +28 -0
- pybox_nlp-0.1.0/src/pybox_nlp.egg-info/dependency_links.txt +1 -0
- pybox_nlp-0.1.0/src/pybox_nlp.egg-info/requires.txt +5 -0
- pybox_nlp-0.1.0/src/pybox_nlp.egg-info/top_level.txt +1 -0
- pybox_nlp-0.1.0/tests/test_errors.py +50 -0
- pybox_nlp-0.1.0/tests/test_export.py +92 -0
- pybox_nlp-0.1.0/tests/test_packaging.py +36 -0
- pybox_nlp-0.1.0/tests/test_printing.py +34 -0
- pybox_nlp-0.1.0/tests/test_program_access.py +73 -0
pybox_nlp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PyBox Authors and Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pybox_nlp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pybox-nlp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A production-ready Python library bundling 11 standalone NLP programs with source inspection and export capabilities.
|
|
5
|
+
Author: PyBox Maintainers
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pybox-dev/pybox
|
|
8
|
+
Project-URL: Repository, https://github.com/pybox-dev/pybox
|
|
9
|
+
Project-URL: Issues, https://github.com/pybox-dev/pybox/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/pybox-dev/pybox/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: pybox,bundle,programs,source-code,exporter
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.8
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
29
|
+
Requires-Dist: build>=0.10.0; extra == "dev"
|
|
30
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# PyBox (`pybox`)
|
|
34
|
+
|
|
35
|
+
A production-ready Python library bundling 11 standalone Python programs into one installable package. Access each program via intuitive top-level attributes, inspect its original source code directly, and safely export it into standalone `.py` scripts.
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/pybox/)
|
|
38
|
+
[](https://pypi.org/project/pybox/)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Table of Contents
|
|
44
|
+
|
|
45
|
+
- [Overview](#overview)
|
|
46
|
+
- [Key Distinction: Inspection vs. Execution](#key-distinction-inspection-vs-execution)
|
|
47
|
+
- [Installation](#installation)
|
|
48
|
+
- [Quick Start](#quick-start)
|
|
49
|
+
- [Program Identifiers](#program-identifiers)
|
|
50
|
+
- [Features and Usage](#features-and-usage)
|
|
51
|
+
- [1. Viewing Source Code](#1-viewing-source-code)
|
|
52
|
+
- [2. Accessing Raw Source String](#2-accessing-raw-source-string)
|
|
53
|
+
- [3. Exporting to Standalone Files](#3-exporting-to-standalone-files)
|
|
54
|
+
- [4. Custom Export Destinations](#4-custom-export-destinations)
|
|
55
|
+
- [5. Overwrite Protection](#5-overwrite-protection)
|
|
56
|
+
- [6. Developer Representation](#6-developer-representation)
|
|
57
|
+
- [Individual Program Dependencies](#individual-program-dependencies)
|
|
58
|
+
- [Safety and Security](#safety-and-security)
|
|
59
|
+
- [Compatibility](#compatibility)
|
|
60
|
+
- [Development and Testing](#development-and-testing)
|
|
61
|
+
- [Publishing to PyPI](#publishing-to-pypi)
|
|
62
|
+
- [Contributing](#contributing)
|
|
63
|
+
- [License](#license)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Overview
|
|
68
|
+
|
|
69
|
+
`pybox` bundles 11 standalone Python programs into a unified package. Instead of copying and pasting code snippets, developers can:
|
|
70
|
+
- Import `pybox` and inspect any bundled program's complete source code in Python interactive shells, logging, or scripts.
|
|
71
|
+
- Export bundled programs into standalone `.py` files on demand with atomic write safety and directory creation.
|
|
72
|
+
- Keep source code intact: all comments, imports, functions, classes, and logic are preserved identically.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Key Distinction: Inspection vs. Execution
|
|
77
|
+
|
|
78
|
+
> [!IMPORTANT]
|
|
79
|
+
> **`pybox` does NOT execute bundled programs when you import the library, inspect their source code, or export them to disk.**
|
|
80
|
+
|
|
81
|
+
`pybox` acts as a curated code distribution and extraction engine. When you access `pybox.one` or invoke `pybox.one.save()`, `pybox` reads the packaged source assets as UTF-8 text.
|
|
82
|
+
|
|
83
|
+
To **run** an exported program after saving it, execute it in Python directly using your terminal:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
python one.py
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Ensure any third-party dependencies required by that specific program are installed in your Python environment before running it.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Installation
|
|
94
|
+
|
|
95
|
+
### From PyPI
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
python -m pip install pybox
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### From Local Source (Editable Mode)
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
git clone https://github.com/pybox-dev/pybox.git
|
|
105
|
+
cd pybox
|
|
106
|
+
python -m pip install -e ".[dev]"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Quick Start
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import pybox
|
|
115
|
+
|
|
116
|
+
# 1. Print the complete source code of a program
|
|
117
|
+
print(pybox.one)
|
|
118
|
+
|
|
119
|
+
# 2. Get the raw source code string
|
|
120
|
+
code = pybox.two.code
|
|
121
|
+
print(f"Total lines: {len(code.splitlines())}")
|
|
122
|
+
|
|
123
|
+
# 3. Export to a standalone Python script
|
|
124
|
+
saved_path = pybox.one.save()
|
|
125
|
+
print(f"Exported to: {saved_path}")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Program Identifiers & Bundled Programs
|
|
131
|
+
|
|
132
|
+
The package exposes 11 curated NLP programs as attributes on the top-level `pybox` module:
|
|
133
|
+
|
|
134
|
+
| Attribute | Default Export | Description | Dependencies |
|
|
135
|
+
| :--- | :--- | :--- | :--- |
|
|
136
|
+
| `pybox.one` | `one.py` | **Word Frequency & Punctuation Stripper**: Counts word frequencies after stripping punctuation and normalizing case. | Standard Library (`string`) |
|
|
137
|
+
| `pybox.two` | `two.py` | **Regex Demonstrator**: Demonstrates pattern matching, searching, extracting, and substitution using regex. | Standard Library (`re`) |
|
|
138
|
+
| `pybox.three` | `three.py` | **Morphological Analyzer & Stopwords Filter**: Lemmatizes tokens and filters English stopwords. | `nltk` |
|
|
139
|
+
| `pybox.four` | `four.py` | **N-Gram Generator & Probability Calculator**: Generates N-grams and calculates sentence probabilities. | `nltk` |
|
|
140
|
+
| `pybox.five` | `five.py` | **Penn Treebank Component Analyzer**: Inspects and parses sentential constituents using Penn Treebank trees. | `nltk` |
|
|
141
|
+
| `pybox.six` | `six.py` | **Vectorization & Feature Extraction Pipeline**: Preprocesses text with stemming/lemmatization and extracts Count/TF-IDF vectors. | `nltk`, `scikit-learn` |
|
|
142
|
+
| `pybox.seven` | `seven.py` | **Context-Free Grammar (CFG) Generator**: Generates sentences adhering to formal phrase structure grammar rules. | `nltk` |
|
|
143
|
+
| `pybox.eight` | `eight.py` | **Word Sense Disambiguation (WSD)**: Resolves word senses in context using the Lesk algorithm and WordNet. | `nltk` |
|
|
144
|
+
| `pybox.nine` | `nine.py` | **Semantic Role & Feature Structure Identifier**: Maps syntactic tokens and POS tags to thematic roles and feature structures. | `nltk` |
|
|
145
|
+
| `pybox.ten` | `ten.py` | **First-Order Logic (FOL) Translator**: Translates quantified formal logic expressions into natural language sentences. | Standard Library (`re`) |
|
|
146
|
+
| `pybox.eleven` | `eleven.py` | **Selectional Restrictions & Anomaly Checker**: Evaluates semantic predicate-argument compatibility using feature structures. | `nltk` |
|
|
147
|
+
|
|
148
|
+
You can iterate over all programs programmatically:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
import pybox
|
|
152
|
+
|
|
153
|
+
for name, prog in pybox.PROGRAMS.items():
|
|
154
|
+
print(f"Loaded {prog.identifier}: {prog.filename}")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Features and Usage
|
|
160
|
+
|
|
161
|
+
### 1. Viewing Source Code
|
|
162
|
+
|
|
163
|
+
Converting any program object to `str` (or passing it to `print()`) renders its complete source code:
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
import pybox
|
|
167
|
+
|
|
168
|
+
print(pybox.one)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 2. Accessing Raw Source String
|
|
172
|
+
|
|
173
|
+
Access the `.code` property on any program object to obtain the unmodified source code as a Python `str`:
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
import pybox
|
|
177
|
+
|
|
178
|
+
source = pybox.one.code
|
|
179
|
+
assert isinstance(source, str)
|
|
180
|
+
print(f"Total lines: {len(source.splitlines())}")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 3. Exporting to Standalone Files
|
|
184
|
+
|
|
185
|
+
Call `.save()` without arguments to export the program to the current working directory under its default filename (e.g., `one.py`):
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
import pybox
|
|
189
|
+
|
|
190
|
+
path = pybox.one.save()
|
|
191
|
+
print(path) # /path/to/cwd/one.py
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### 4. Custom Export Destinations
|
|
195
|
+
|
|
196
|
+
Specify a custom file name or path. If intermediate parent directories do not exist, `pybox` creates them automatically:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
import pybox
|
|
200
|
+
|
|
201
|
+
# Export to a custom filename in the current directory
|
|
202
|
+
pybox.one.save("my_program.py")
|
|
203
|
+
|
|
204
|
+
# Export to a nested subdirectory (directories created automatically)
|
|
205
|
+
pybox.two.save("exports/tools/run_two.py")
|
|
206
|
+
|
|
207
|
+
# Export into an existing directory (uses default filename 'three.py')
|
|
208
|
+
pybox.three.save("exports/")
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### 5. Overwrite Protection
|
|
212
|
+
|
|
213
|
+
To protect existing scripts from accidental loss, `pybox` **refuses to overwrite existing files by default**:
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
import pybox
|
|
217
|
+
|
|
218
|
+
# First export succeeds
|
|
219
|
+
pybox.one.save("script.py")
|
|
220
|
+
|
|
221
|
+
# Second export raises FileExistsError
|
|
222
|
+
try:
|
|
223
|
+
pybox.one.save("script.py")
|
|
224
|
+
except FileExistsError as e:
|
|
225
|
+
print("Caught expected protection error:", e)
|
|
226
|
+
|
|
227
|
+
# Explicitly authorize overwriting
|
|
228
|
+
pybox.one.save("script.py", overwrite=True)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Export writes use atomic temporary file replacement (`os.replace`) to ensure a partially written file is never left on disk in the event of an interruption.
|
|
232
|
+
|
|
233
|
+
### 6. Developer Representation
|
|
234
|
+
|
|
235
|
+
In interactive environments, `repr()` provides clear identification:
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
import pybox
|
|
239
|
+
|
|
240
|
+
print(repr(pybox.one))
|
|
241
|
+
# Output: Program('one')
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Individual Program Dependencies
|
|
247
|
+
|
|
248
|
+
`pybox` itself has **zero runtime third-party dependencies**. It relies strictly on Python standard library modules (`pathlib`, `tempfile`, `os`, `importlib.resources`).
|
|
249
|
+
|
|
250
|
+
Exporting a program writes its standalone source code to disk. Before executing the exported scripts, install any required third-party libraries:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# To run all exported NLP programs:
|
|
254
|
+
pip install nltk scikit-learn
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
| Program | Standard Library Modules | External Dependencies | NLTK Corpora Required (Auto-downloaded on run) |
|
|
258
|
+
| :--- | :--- | :--- | :--- |
|
|
259
|
+
| `one.py` | `string` | None | None |
|
|
260
|
+
| `two.py` | `re` | None | None |
|
|
261
|
+
| `three.py` | Standard library | `nltk` | `punkt`, `wordnet`, `stopwords` |
|
|
262
|
+
| `four.py` | `collections`, `math` | `nltk` | `punkt` |
|
|
263
|
+
| `five.py` | Standard library | `nltk` | `treebank`, `punkt` |
|
|
264
|
+
| `six.py` | Standard library | `nltk`, `scikit-learn` | `punkt`, `stopwords`, `wordnet` |
|
|
265
|
+
| `seven.py` | Standard library | `nltk` | None |
|
|
266
|
+
| `eight.py` | Standard library | `nltk` | `wordnet`, `punkt`, `omw-1.4` |
|
|
267
|
+
| `nine.py` | Standard library | `nltk` | `punkt`, `averaged_perceptron_tagger`, `wordnet` |
|
|
268
|
+
| `ten.py` | `re` | None | None |
|
|
269
|
+
| `eleven.py` | Standard library | `nltk` | None |
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Safety and Security
|
|
274
|
+
|
|
275
|
+
- **No Execution on Import**: Bundled code is never imported, evaluated, or executed by `pybox`.
|
|
276
|
+
- **Atomic Writes**: Export files are written to a temporary file before being atomically moved into destination path.
|
|
277
|
+
- **Directory Traversal & Overwrite Guards**: Prevents accidental directory replacement and unintended data destruction.
|
|
278
|
+
- **Zero Secrets**: Bundled programs must never contain API tokens, passwords, or personal credentials.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Compatibility
|
|
283
|
+
|
|
284
|
+
- **Python**: `>= 3.8` (fully tested across Python 3.8, 3.9, 3.10, 3.11, 3.12, and 3.13)
|
|
285
|
+
- **Platforms**: Windows, macOS, and Linux
|
|
286
|
+
- **Packaging Standard**: PEP 517 / PEP 518 / PEP 621 compliant build
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Development and Testing
|
|
291
|
+
|
|
292
|
+
### Setup Environment
|
|
293
|
+
|
|
294
|
+
```powershell
|
|
295
|
+
# Windows PowerShell
|
|
296
|
+
python -m venv .venv
|
|
297
|
+
.\.venv\Scripts\Activate.ps1
|
|
298
|
+
python -m pip install --upgrade pip
|
|
299
|
+
python -m pip install -e ".[dev]"
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# Linux / macOS
|
|
304
|
+
python3 -m venv .venv
|
|
305
|
+
source .venv/bin/activate
|
|
306
|
+
python -m pip install --upgrade pip
|
|
307
|
+
python -m pip install -e ".[dev]"
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Run Tests
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
pytest -v
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Build Distribution Artifacts
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
python -m build
|
|
320
|
+
python -m twine check dist/*
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Publishing to PyPI
|
|
326
|
+
|
|
327
|
+
> [!NOTE]
|
|
328
|
+
> PyPI distribution names are globally unique. Before publishing, verify name availability on [PyPI](https://pypi.org/). If `pybox` is already registered, set an alternative name (such as `pybox-lib` or `pybox-bundle`) in `pyproject.toml`.
|
|
329
|
+
|
|
330
|
+
### Option A: PyPI Trusted Publishing (Recommended)
|
|
331
|
+
|
|
332
|
+
1. Connect your GitHub repository to PyPI at [PyPI Manage Account > Publishing](https://pypi.org/manage/account/publishing/).
|
|
333
|
+
2. Push a release tag or trigger the included `.github/workflows/publish.yml` workflow.
|
|
334
|
+
3. GitHub Actions authenticates via short-lived OIDC tokens without requiring static API keys.
|
|
335
|
+
|
|
336
|
+
### Option B: Manual Publishing via Twine
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
python -m twine upload --repository testpypi dist/* # Test on TestPyPI first
|
|
340
|
+
python -m twine upload dist/* # Publish to production PyPI
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## Contributing
|
|
346
|
+
|
|
347
|
+
1. Fork the repository.
|
|
348
|
+
2. Create a feature branch (`git checkout -b feature/my-feature`).
|
|
349
|
+
3. Commit your changes (`git commit -m "Add feature"`).
|
|
350
|
+
4. Run the test suite (`pytest -v`).
|
|
351
|
+
5. Open a Pull Request.
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## License
|
|
356
|
+
|
|
357
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# PyBox (`pybox`)
|
|
2
|
+
|
|
3
|
+
A production-ready Python library bundling 11 standalone Python programs into one installable package. Access each program via intuitive top-level attributes, inspect its original source code directly, and safely export it into standalone `.py` scripts.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/pybox/)
|
|
6
|
+
[](https://pypi.org/project/pybox/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
- [Overview](#overview)
|
|
14
|
+
- [Key Distinction: Inspection vs. Execution](#key-distinction-inspection-vs-execution)
|
|
15
|
+
- [Installation](#installation)
|
|
16
|
+
- [Quick Start](#quick-start)
|
|
17
|
+
- [Program Identifiers](#program-identifiers)
|
|
18
|
+
- [Features and Usage](#features-and-usage)
|
|
19
|
+
- [1. Viewing Source Code](#1-viewing-source-code)
|
|
20
|
+
- [2. Accessing Raw Source String](#2-accessing-raw-source-string)
|
|
21
|
+
- [3. Exporting to Standalone Files](#3-exporting-to-standalone-files)
|
|
22
|
+
- [4. Custom Export Destinations](#4-custom-export-destinations)
|
|
23
|
+
- [5. Overwrite Protection](#5-overwrite-protection)
|
|
24
|
+
- [6. Developer Representation](#6-developer-representation)
|
|
25
|
+
- [Individual Program Dependencies](#individual-program-dependencies)
|
|
26
|
+
- [Safety and Security](#safety-and-security)
|
|
27
|
+
- [Compatibility](#compatibility)
|
|
28
|
+
- [Development and Testing](#development-and-testing)
|
|
29
|
+
- [Publishing to PyPI](#publishing-to-pypi)
|
|
30
|
+
- [Contributing](#contributing)
|
|
31
|
+
- [License](#license)
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Overview
|
|
36
|
+
|
|
37
|
+
`pybox` bundles 11 standalone Python programs into a unified package. Instead of copying and pasting code snippets, developers can:
|
|
38
|
+
- Import `pybox` and inspect any bundled program's complete source code in Python interactive shells, logging, or scripts.
|
|
39
|
+
- Export bundled programs into standalone `.py` files on demand with atomic write safety and directory creation.
|
|
40
|
+
- Keep source code intact: all comments, imports, functions, classes, and logic are preserved identically.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Key Distinction: Inspection vs. Execution
|
|
45
|
+
|
|
46
|
+
> [!IMPORTANT]
|
|
47
|
+
> **`pybox` does NOT execute bundled programs when you import the library, inspect their source code, or export them to disk.**
|
|
48
|
+
|
|
49
|
+
`pybox` acts as a curated code distribution and extraction engine. When you access `pybox.one` or invoke `pybox.one.save()`, `pybox` reads the packaged source assets as UTF-8 text.
|
|
50
|
+
|
|
51
|
+
To **run** an exported program after saving it, execute it in Python directly using your terminal:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python one.py
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Ensure any third-party dependencies required by that specific program are installed in your Python environment before running it.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
### From PyPI
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
python -m pip install pybox
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### From Local Source (Editable Mode)
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git clone https://github.com/pybox-dev/pybox.git
|
|
73
|
+
cd pybox
|
|
74
|
+
python -m pip install -e ".[dev]"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import pybox
|
|
83
|
+
|
|
84
|
+
# 1. Print the complete source code of a program
|
|
85
|
+
print(pybox.one)
|
|
86
|
+
|
|
87
|
+
# 2. Get the raw source code string
|
|
88
|
+
code = pybox.two.code
|
|
89
|
+
print(f"Total lines: {len(code.splitlines())}")
|
|
90
|
+
|
|
91
|
+
# 3. Export to a standalone Python script
|
|
92
|
+
saved_path = pybox.one.save()
|
|
93
|
+
print(f"Exported to: {saved_path}")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Program Identifiers & Bundled Programs
|
|
99
|
+
|
|
100
|
+
The package exposes 11 curated NLP programs as attributes on the top-level `pybox` module:
|
|
101
|
+
|
|
102
|
+
| Attribute | Default Export | Description | Dependencies |
|
|
103
|
+
| :--- | :--- | :--- | :--- |
|
|
104
|
+
| `pybox.one` | `one.py` | **Word Frequency & Punctuation Stripper**: Counts word frequencies after stripping punctuation and normalizing case. | Standard Library (`string`) |
|
|
105
|
+
| `pybox.two` | `two.py` | **Regex Demonstrator**: Demonstrates pattern matching, searching, extracting, and substitution using regex. | Standard Library (`re`) |
|
|
106
|
+
| `pybox.three` | `three.py` | **Morphological Analyzer & Stopwords Filter**: Lemmatizes tokens and filters English stopwords. | `nltk` |
|
|
107
|
+
| `pybox.four` | `four.py` | **N-Gram Generator & Probability Calculator**: Generates N-grams and calculates sentence probabilities. | `nltk` |
|
|
108
|
+
| `pybox.five` | `five.py` | **Penn Treebank Component Analyzer**: Inspects and parses sentential constituents using Penn Treebank trees. | `nltk` |
|
|
109
|
+
| `pybox.six` | `six.py` | **Vectorization & Feature Extraction Pipeline**: Preprocesses text with stemming/lemmatization and extracts Count/TF-IDF vectors. | `nltk`, `scikit-learn` |
|
|
110
|
+
| `pybox.seven` | `seven.py` | **Context-Free Grammar (CFG) Generator**: Generates sentences adhering to formal phrase structure grammar rules. | `nltk` |
|
|
111
|
+
| `pybox.eight` | `eight.py` | **Word Sense Disambiguation (WSD)**: Resolves word senses in context using the Lesk algorithm and WordNet. | `nltk` |
|
|
112
|
+
| `pybox.nine` | `nine.py` | **Semantic Role & Feature Structure Identifier**: Maps syntactic tokens and POS tags to thematic roles and feature structures. | `nltk` |
|
|
113
|
+
| `pybox.ten` | `ten.py` | **First-Order Logic (FOL) Translator**: Translates quantified formal logic expressions into natural language sentences. | Standard Library (`re`) |
|
|
114
|
+
| `pybox.eleven` | `eleven.py` | **Selectional Restrictions & Anomaly Checker**: Evaluates semantic predicate-argument compatibility using feature structures. | `nltk` |
|
|
115
|
+
|
|
116
|
+
You can iterate over all programs programmatically:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
import pybox
|
|
120
|
+
|
|
121
|
+
for name, prog in pybox.PROGRAMS.items():
|
|
122
|
+
print(f"Loaded {prog.identifier}: {prog.filename}")
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Features and Usage
|
|
128
|
+
|
|
129
|
+
### 1. Viewing Source Code
|
|
130
|
+
|
|
131
|
+
Converting any program object to `str` (or passing it to `print()`) renders its complete source code:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
import pybox
|
|
135
|
+
|
|
136
|
+
print(pybox.one)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 2. Accessing Raw Source String
|
|
140
|
+
|
|
141
|
+
Access the `.code` property on any program object to obtain the unmodified source code as a Python `str`:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
import pybox
|
|
145
|
+
|
|
146
|
+
source = pybox.one.code
|
|
147
|
+
assert isinstance(source, str)
|
|
148
|
+
print(f"Total lines: {len(source.splitlines())}")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 3. Exporting to Standalone Files
|
|
152
|
+
|
|
153
|
+
Call `.save()` without arguments to export the program to the current working directory under its default filename (e.g., `one.py`):
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
import pybox
|
|
157
|
+
|
|
158
|
+
path = pybox.one.save()
|
|
159
|
+
print(path) # /path/to/cwd/one.py
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 4. Custom Export Destinations
|
|
163
|
+
|
|
164
|
+
Specify a custom file name or path. If intermediate parent directories do not exist, `pybox` creates them automatically:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
import pybox
|
|
168
|
+
|
|
169
|
+
# Export to a custom filename in the current directory
|
|
170
|
+
pybox.one.save("my_program.py")
|
|
171
|
+
|
|
172
|
+
# Export to a nested subdirectory (directories created automatically)
|
|
173
|
+
pybox.two.save("exports/tools/run_two.py")
|
|
174
|
+
|
|
175
|
+
# Export into an existing directory (uses default filename 'three.py')
|
|
176
|
+
pybox.three.save("exports/")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 5. Overwrite Protection
|
|
180
|
+
|
|
181
|
+
To protect existing scripts from accidental loss, `pybox` **refuses to overwrite existing files by default**:
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
import pybox
|
|
185
|
+
|
|
186
|
+
# First export succeeds
|
|
187
|
+
pybox.one.save("script.py")
|
|
188
|
+
|
|
189
|
+
# Second export raises FileExistsError
|
|
190
|
+
try:
|
|
191
|
+
pybox.one.save("script.py")
|
|
192
|
+
except FileExistsError as e:
|
|
193
|
+
print("Caught expected protection error:", e)
|
|
194
|
+
|
|
195
|
+
# Explicitly authorize overwriting
|
|
196
|
+
pybox.one.save("script.py", overwrite=True)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Export writes use atomic temporary file replacement (`os.replace`) to ensure a partially written file is never left on disk in the event of an interruption.
|
|
200
|
+
|
|
201
|
+
### 6. Developer Representation
|
|
202
|
+
|
|
203
|
+
In interactive environments, `repr()` provides clear identification:
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
import pybox
|
|
207
|
+
|
|
208
|
+
print(repr(pybox.one))
|
|
209
|
+
# Output: Program('one')
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Individual Program Dependencies
|
|
215
|
+
|
|
216
|
+
`pybox` itself has **zero runtime third-party dependencies**. It relies strictly on Python standard library modules (`pathlib`, `tempfile`, `os`, `importlib.resources`).
|
|
217
|
+
|
|
218
|
+
Exporting a program writes its standalone source code to disk. Before executing the exported scripts, install any required third-party libraries:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# To run all exported NLP programs:
|
|
222
|
+
pip install nltk scikit-learn
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
| Program | Standard Library Modules | External Dependencies | NLTK Corpora Required (Auto-downloaded on run) |
|
|
226
|
+
| :--- | :--- | :--- | :--- |
|
|
227
|
+
| `one.py` | `string` | None | None |
|
|
228
|
+
| `two.py` | `re` | None | None |
|
|
229
|
+
| `three.py` | Standard library | `nltk` | `punkt`, `wordnet`, `stopwords` |
|
|
230
|
+
| `four.py` | `collections`, `math` | `nltk` | `punkt` |
|
|
231
|
+
| `five.py` | Standard library | `nltk` | `treebank`, `punkt` |
|
|
232
|
+
| `six.py` | Standard library | `nltk`, `scikit-learn` | `punkt`, `stopwords`, `wordnet` |
|
|
233
|
+
| `seven.py` | Standard library | `nltk` | None |
|
|
234
|
+
| `eight.py` | Standard library | `nltk` | `wordnet`, `punkt`, `omw-1.4` |
|
|
235
|
+
| `nine.py` | Standard library | `nltk` | `punkt`, `averaged_perceptron_tagger`, `wordnet` |
|
|
236
|
+
| `ten.py` | `re` | None | None |
|
|
237
|
+
| `eleven.py` | Standard library | `nltk` | None |
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Safety and Security
|
|
242
|
+
|
|
243
|
+
- **No Execution on Import**: Bundled code is never imported, evaluated, or executed by `pybox`.
|
|
244
|
+
- **Atomic Writes**: Export files are written to a temporary file before being atomically moved into destination path.
|
|
245
|
+
- **Directory Traversal & Overwrite Guards**: Prevents accidental directory replacement and unintended data destruction.
|
|
246
|
+
- **Zero Secrets**: Bundled programs must never contain API tokens, passwords, or personal credentials.
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Compatibility
|
|
251
|
+
|
|
252
|
+
- **Python**: `>= 3.8` (fully tested across Python 3.8, 3.9, 3.10, 3.11, 3.12, and 3.13)
|
|
253
|
+
- **Platforms**: Windows, macOS, and Linux
|
|
254
|
+
- **Packaging Standard**: PEP 517 / PEP 518 / PEP 621 compliant build
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Development and Testing
|
|
259
|
+
|
|
260
|
+
### Setup Environment
|
|
261
|
+
|
|
262
|
+
```powershell
|
|
263
|
+
# Windows PowerShell
|
|
264
|
+
python -m venv .venv
|
|
265
|
+
.\.venv\Scripts\Activate.ps1
|
|
266
|
+
python -m pip install --upgrade pip
|
|
267
|
+
python -m pip install -e ".[dev]"
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Linux / macOS
|
|
272
|
+
python3 -m venv .venv
|
|
273
|
+
source .venv/bin/activate
|
|
274
|
+
python -m pip install --upgrade pip
|
|
275
|
+
python -m pip install -e ".[dev]"
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Run Tests
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
pytest -v
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Build Distribution Artifacts
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
python -m build
|
|
288
|
+
python -m twine check dist/*
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## Publishing to PyPI
|
|
294
|
+
|
|
295
|
+
> [!NOTE]
|
|
296
|
+
> PyPI distribution names are globally unique. Before publishing, verify name availability on [PyPI](https://pypi.org/). If `pybox` is already registered, set an alternative name (such as `pybox-lib` or `pybox-bundle`) in `pyproject.toml`.
|
|
297
|
+
|
|
298
|
+
### Option A: PyPI Trusted Publishing (Recommended)
|
|
299
|
+
|
|
300
|
+
1. Connect your GitHub repository to PyPI at [PyPI Manage Account > Publishing](https://pypi.org/manage/account/publishing/).
|
|
301
|
+
2. Push a release tag or trigger the included `.github/workflows/publish.yml` workflow.
|
|
302
|
+
3. GitHub Actions authenticates via short-lived OIDC tokens without requiring static API keys.
|
|
303
|
+
|
|
304
|
+
### Option B: Manual Publishing via Twine
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
python -m twine upload --repository testpypi dist/* # Test on TestPyPI first
|
|
308
|
+
python -m twine upload dist/* # Publish to production PyPI
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Contributing
|
|
314
|
+
|
|
315
|
+
1. Fork the repository.
|
|
316
|
+
2. Create a feature branch (`git checkout -b feature/my-feature`).
|
|
317
|
+
3. Commit your changes (`git commit -m "Add feature"`).
|
|
318
|
+
4. Run the test suite (`pytest -v`).
|
|
319
|
+
5. Open a Pull Request.
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## License
|
|
324
|
+
|
|
325
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|