Reversible String Process Pipeline
Project description
Reversible string processing pipe. Featuring reproducibility, serializability and performance.
Installation
pip install strpipe
Usage
import strpipe as sp
p = sp.Pipe()
p.add_step_by_op_name(
op_name='Trim',
op_kwargs={'tokens': ['\n', '\r']},
)
p.add_step_by_op_name('CharTokenize')
p.add_step_by_op_name(
op_name='MapStringToIndex',
state={'你': 0, '好': 1, '早': 2}, # if provided, the p.fit won't change it
)
data = [
'你好啊\n',
'早安',
'你早上好\n',
]
p.fit(data)
result, tx_info = p.transform(data) # convention: tx => tranform
back_data = p.inverse_transform(result, tx_info)
Serialization
# Save it
p.save_json('/path/of/pipe')
# Load it
p = sp.Pipe.restore_from_json('/path/of/pipe')
result, meta = p.transform(['你好'])
Test
$ make test
Docs
$ make docs Docs will be built in the `docs/build/html` folder. (Note: this also reinstalls the package because we need Cython code to be rebuilt.)
Extend Ops
Extend the new ops with BaseOp
Define input_type, output_type
Implement op creation
Implement fit, transform, inverse_transform. If the op is stateless, the fit method should return None.
Note: It is expected that an ops’s functionality will often be able to be decomposed into several functions. These functions should be written into (or imported from) the toolkit package for easy reuse. Ops in the ops package will, for the most part, be wrappers for functions in toolkit.
Write tests
Register to op_factory
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file strpipe-0.4.2.tar.gz
.
File metadata
- Download URL: strpipe-0.4.2.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29091f0e5ab72e827632c3d3c131ab7db8365c7aa105711642724fcb3ed9ad91 |
|
MD5 | 0e48907e5eb6a74e94516a4292d8e0f0 |
|
BLAKE2b-256 | e05aff082c7828fcef54ce6b59b09d3d7355908535889f1825c0319844aab033 |