Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysenseword-1.0.0.tar.gz (875.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysenseword-1.0.0-py3-none-any.whl (876.1 kB view details)

Uploaded Python 3

File details

Details for the file pysenseword-1.0.0.tar.gz.

File metadata

  • Download URL: pysenseword-1.0.0.tar.gz
  • Upload date:
  • Size: 875.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.2

File hashes

Hashes for pysenseword-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0ed69f9decd59c0ea0ef3f0fa1a24b9b737ca24cebef30c07e869c08053e3f15
MD5 af1de9b1441e58d4592b3ce89c52cbde
BLAKE2b-256 627725aad994326498e0a3fbd5237cb9e5dd183dffbdbe06474481c426a2fd43

See more details on using hashes here.

File details

Details for the file pysenseword-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pysenseword-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 876.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.2

File hashes

Hashes for pysenseword-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f6733d403c628d81b2c8ab3510e89dc6c73776c737b4988b07aec6057aca1b6
MD5 193a906ed77db0543299d4f63cb022ca
BLAKE2b-256 53f3fb38053f02c18949b6a0eb28354e08fdbd1fc52eb23864677cd2bd426296

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page