Skip to main content

A set of tools for testing SmokeDetector regexes

Project description

SmokeDetector Regex Testing


SmokeDetector Regex Testing (SDRT) provides functionality for testing regexes against metasmoke data and analyzing their results.

It makes heavy use of the Polars library, which it uses to store post data, test regexes, filter results, and more.

Usage

Python module

It's recommended to use the sdrt alias when importing sd_regex_testing:

import sd_regex_testing as sdrt

Any processing requires an initial call to sdrt.read_json. This function accepts the path to a metasmoke JSON file and returns a Polars DataFrame.

data = sdrt.read_json("path/to/file")

From there, the DataFrame can be tested against a regex. The sdrt polars namespace includes several testing methods:

title = data.sdrt.test_title("test")
username = data.sdrt.test_username("test")
keyword = data.sdrt.test_keyword("test")
website = data.sdrt.test_website("test")

Each of these methods also takes a case_sensitive optional parameter, which defaults to False.

case_sensitive = data.sdrt.test_keyword("test", case_sensitive=True)

The results of a given test can be filtered using the tp, fp, tn, and fn properties, which reflect the effectiveness of the just-tested regex. Each of these properties is a DataFrame containing only the target posts.

tps = keyword.sdrt.tp
fps = keyword.sdrt.fp
tns = keyword.sdrt.tn
fns = keyword.sdrt.fn

Commmand line tool

This package also creates an sdrt command line tool. It takes the path to an MS JSON file as an argument:

sdrt path/to/file

This will open an interactive regex testing session. The test command will test a given regex against the file and store the result.

>>> test (title|username|keyword|website) regex

The tp, fp, tn, and fn commands will report the number of posts with the given result.

>>> tp|fp|tn|fn

The summarize command will pretty-print the counts for all four result types, as well as reporting the last test.

>>> summarize
Regex [last regex] as a [last regex type] yielded [count] TP, [count] FP, [count] TN, and [count] FN.

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

sd_regex_testing-1.0.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

sd_regex_testing-1.0.1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file sd_regex_testing-1.0.1.tar.gz.

File metadata

  • Download URL: sd_regex_testing-1.0.1.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.2 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for sd_regex_testing-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b7ecaab8a1924a178482c4af364d6b7b6d2f6757994dca4e4bc9e130e0c50bca
MD5 22075d172c167eee3e4ed0105e7aadf8
BLAKE2b-256 24de075308b2cdc5bedb868b52aeb17efebfa8735171f152339545042872d978

See more details on using hashes here.

File details

Details for the file sd_regex_testing-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: sd_regex_testing-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.2 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for sd_regex_testing-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f381fc75ed755af3aa31d35d340436afc2829f9bea7f761c20cc47964f59aa0a
MD5 493a392da01371ac94b22b96e2b970a2
BLAKE2b-256 7975ad24756fb63667b0e8a9eb561d39c30501a41f20dbbd59db41555f16a374

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