A module to detect sense words
Project description
pysenseword
A module for detecting sensitive words in text using different algorithms.
Available algorithms:
- DFA (Deterministic Finite Automaton)
- Aho-Corasick algorithm
- Regular expression
- String find
Example usage:
DFA:
from pysenseword import search
text = "This is a test text without a sensitivetest word."
results = search(text, method='dfa')
print(results)
Output:
{'find': True, 'word': 'sensivetest', 'dict': {'line': 7348, 'index': 30}}
or
{'find': False, 'word': '', 'dict': {'line': 0, 'index': 0}}
Other algorithms:
from pysenseword import search
text = "This is a test text without a sensitivetest word."
results = search(text, method='ac')
print(results)
Output:
{'find': True, 'words': {('sensitivetest', 30)}}
or
{'find': False, 'words': set()}
from pysenseword import search
text = "This is a test text without a sensitivetest word."
results = search(text, method='re')
print(results)
Output:
{'find': True, 'words': {('sensitivetest', 30)}}
from pysenseword import search
text = "This is a test text without a sensitivetest word."
results = search(text, method='str')
print(results)
Output:
The `search` function takes three arguments:
- `text`: the text to search for sensitive words
- `method`: the algorithm to use for detecting sensitive words. Available options are:
- `dfa`: DFA algorithm
- `ac`: Aho-Corasick algorithm
- `re`: Regular expression
- `str`: String find
Advanced usage:
You can customize the algorithm by passing additional arguments to the `search_advanced` function.
```search_advanced(text,method='dfa',dictionary='default',method_function=None, run_before=None, run_after=None):```
text: the text to search for sensitive words
method: the algorithm to use for detecting sensitive words. Usage is same as in `search` function.
dictionary: the dictionary to use for detecting sensitive words. Usage is same as in `search` function.
method_function: a function that takes the text and returns a list of sensitive words. If not provided, the default function is used.
run_before: a function that takes the text and returns the modified text before running the algorithm. If not provided, the default function is used.
run_after: a function that takes the text and the result of the algorithm and returns the modified result. If not provided, the default function is used.
Example usage:
```python
from pysenseword import search_advanced
text = "This is a test text without a sensitivetest word."
results = search_advanced(text, method='dfa', dictionary='default', method_function=None, run_before=None, run_after=None)
print(results)
Output:
{'find': True, 'word': 'sensivetest', 'dict': {'line': 7348, 'index': 30}}
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
pysenseword-0.1.1.tar.gz
(6.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pysenseword-0.1.1.tar.gz.
File metadata
- Download URL: pysenseword-0.1.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60d99963b0c2f5d2927d62228d8c41634fc833551378392079084366411b7f15
|
|
| MD5 |
9ab1b3b1669ca7ea8838196df0063917
|
|
| BLAKE2b-256 |
97747b6c97ec8394d242a647815fe8970fd7eceb9edf163c72c54946fab228ff
|
File details
Details for the file pysenseword-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pysenseword-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
516d24ddd6559547bd19893cec263b7a8dbc35147a4007e30ccbef46226b6531
|
|
| MD5 |
543baaf57d8e671e29e1cfb34ab5ff5f
|
|
| BLAKE2b-256 |
4368cc39909d1aea121e75aa463c8009b8f21c0ce053e88321131cd6f2b416bf
|