Skip to content

Commit ee186ee

Browse files
committed
Add more crates to accuracy comparison.
1 parent a62dc6f commit ee186ee

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ serde = {version = "1", features=["derive"], optional = true}
7575
[dev-dependencies]
7676
rand = "0.8"
7777
csv = "1.1"
78-
censor_crate = {package = "censor", version = "0.3.0"}
79-
rustrict_old = {package = "rustrict", version = "0.7.24"}
78+
censor_crate = { package = "censor", version = "0.3.0" }
79+
rustrict_old = { package = "rustrict", version = "0.7.24" }
8080
serial_test = "0.5"
81+
stfu_crate = { package = "stfu", version = "0.1.0" }
82+
profane_rs_crate = { package = "profane-rs", version = "0.0.4" }
8183
bincode = "1.3.3"
8284
serde_json = "1"

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ test:
2424
compare:
2525
COMPARE=1 make test
2626

27+
table:
28+
cargo test --release -- accuracy --nocapture
29+
2730
# Skips accuracy analysis so finishes faster.
2831
test_debug:
2932
cargo test --features pii -- --nocapture

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ is used as a dataset. Positive accuracy is the percentage of profanity detected
179179
|-------|----------|-------------------|-------------------|------|
180180
| [rustrict](https://crates.io/crates/rustrict) | 79.83% | 94.00% | 76.30% | 9s |
181181
| [censor](https://crates.io/crates/censor) | 76.16% | 72.76% | 77.01% | 23s |
182+
| [stfu](https://crates.io/crates/stfu) | 91.74% | 77.69% | 95.25% | 45s |
183+
| [profane-rs](https://crates.io/crates/profane-rs) | 80.47% | 73.79% | 82.14% | 52s |
182184

183185
## Development
184186

src/censor.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,18 @@ mod tests {
11631163
filter.check(s)
11641164
}
11651165

1166+
let mut stfu_filter = stfu_crate::types::OwnedFilter::default();
1167+
use stfu_crate::word_lists::severity::{MILD, SEVERE, STRONG};
1168+
stfu_filter.add_slice(&MILD);
1169+
stfu_filter.add_slice(&STRONG);
1170+
stfu_filter.add_slice(&SEVERE);
1171+
1172+
let stfu = |s: &str| -> bool { stfu_filter.filter_string(s).is_some() };
1173+
1174+
fn profane_rs(s: &str) -> bool {
1175+
profane_rs_crate::contains_profanity(s, false)
1176+
}
1177+
11661178
println!("| Crate | Accuracy | Positive Accuracy | Negative Accuracy | Time |");
11671179
println!("|-------|----------|-------------------|-------------------|------|");
11681180
print_accuracy(
@@ -1172,12 +1184,19 @@ mod tests {
11721184
Some(rustrict_old as fn(&str) -> bool).filter(|_| std::env::var("COMPARE").is_ok()),
11731185
);
11741186
print_accuracy("https://crates.io/crates/censor", censor, false, None);
1187+
print_accuracy("https://crates.io/crates/stfu", stfu, false, None);
1188+
print_accuracy(
1189+
"https://crates.io/crates/profane-rs",
1190+
profane_rs,
1191+
false,
1192+
None,
1193+
);
11751194
}
11761195

11771196
#[allow(dead_code)]
11781197
fn print_accuracy(
11791198
link: &str,
1180-
checker: fn(&str) -> bool,
1199+
checker: impl Fn(&str) -> bool,
11811200
find_detections: bool,
11821201
compare_to: Option<fn(&str) -> bool>,
11831202
) {
@@ -1196,7 +1215,7 @@ mod tests {
11961215

11971216
#[allow(dead_code)]
11981217
fn accuracy_of(
1199-
checker: fn(&str) -> bool,
1218+
checker: impl Fn(&str) -> bool,
12001219
find_detections: bool,
12011220
compare_to: Option<fn(&str) -> bool>,
12021221
) -> (f32, f32, f32) {

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ pub(crate) type Set<V> = rustc_hash::FxHashSet<V>;
5353
#[allow(deprecated)]
5454
pub use censor::add_word;
5555

56+
#[cfg(all(feature = "context", feature = "width"))]
57+
pub use context::ContextWordBreakOptions;
5658
#[cfg(feature = "context")]
5759
pub use context::{
5860
BlockReason, Context, ContextProcessingOptions, ContextRateLimitOptions,
5961
ContextRepetitionLimitOptions,
6062
};
61-
#[cfg(all(feature = "context", feature = "width"))]
62-
pub use context::ContextWordBreakOptions;
6363

6464
#[cfg(feature = "pii")]
6565
pub use pii::censor_and_analyze_pii;

0 commit comments

Comments
 (0)