Skip to content

Commit

Permalink
add github actions workflows + pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
logannc committed Sep 24, 2020
1 parent 80a7e0d commit c8b8f0b
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 18 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Cargo Check
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
check:
name: Check
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- 1.0.0
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- uses: actions-rs/cargo@v1
with:
command: check
29 changes: 29 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Clippy
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
clippy:
name: Clippy
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- 1.0.0
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
29 changes: 29 additions & 0 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Rust Format
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
fmt:
name: Rustfmt
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- 1.0.0
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Cargo Test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- 1.0.0
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- uses: actions-rs/cargo@v1
with:
command: test
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- id: check-merge-conflict
- id: detect-private-key
- id: no-commit-to-branch
- repo: https://github.com/doublify/pre-commit-rust
rev: master
hooks:
- id: fmt
- id: cargo-check
- id: clippy
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/run/current-system/sw/bin/python"
}
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Fuzzy string matching like a boss. It uses Levenshtein Distance to calculate the

**Note: This project was originally named `fuzzyrusty`. Someone else cloned and published it to crates.io https://crates.io/crates/fuzzyrusty. _We do not control that crate._ This is why we have changed the name.**

## Installation
## Installation
`fuzzywuzzy` is currently available through GitHub or crates.io.

For the latest stable releas, add this to your `Cargo.toml`:
Expand Down Expand Up @@ -34,21 +34,21 @@ assert_eq!(fuzz::partial_ratio("this is a test", "this is a test!"), 100);
```
### Token Sort Ratio
```rust
assert_eq!(fuzz::ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear"), 91);
assert_eq!(fuzz::ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear"), 91);
assert_eq!(fuzz::token_sort_ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear", true, true), 100);
```
### Token Set Ratio
```rust
assert_eq!(fuzz::ratio("fuzzy was a bear", "fuzzy fuzzy was a bear"), 84);
assert_eq!(fuzz::ratio("fuzzy was a bear", "fuzzy fuzzy was a bear"), 84);
assert_eq!(fuzz::token_set_ratio("fuzzy was a bear", "fuzzy fuzzy was a bear", true, true), 100);
```
### Process
```rust
assert_eq!(process::extract_one(
"cowboys",
&["Atlanta Falcons", "Dallas Cowboys", "New York Jets"],
&utils::full_process,
&fuzz::wratio,
0,
assert_eq!(process::extract_one(
"cowboys",
&["Atlanta Falcons", "Dallas Cowboys", "New York Jets"],
&utils::full_process,
&fuzz::wratio,
0,
), Some(("Dallas Cowboys".to_string(), 90)));
```
```
6 changes: 1 addition & 5 deletions src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ pub fn partial_ratio(s1: &str, s2: &str) -> u8 {
let blocks = utils::get_matching_blocks(&shorter, &longer);
let mut max: u8 = 0;
for (i, j, _) in blocks {
let long_start = if j > i {
j - i
} else {
0
};
let long_start = if j > i { j - i } else { 0 };
let long_end = std::cmp::min(long_start + shorter.len(), longer.len());
let long_substr = &longer[long_start..long_end];
let r = ratio(&shorter, long_substr);
Expand Down
6 changes: 3 additions & 3 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ where
I: IntoIterator<Item = T>,
T: AsRef<str>,
P: Fn(&str, bool) -> String,
S: Fn(&str, &str, bool, bool) -> u8
S: Fn(&str, &str, bool, bool) -> u8,
{
let processed_query: String = processor(query, false);
if processed_query.is_empty() {
Expand Down Expand Up @@ -54,7 +54,7 @@ where
I: IntoIterator<Item = T>,
T: AsRef<str>,
P: Fn(&str, bool) -> String,
S: Fn(&str, &str, bool, bool) -> u8
S: Fn(&str, &str, bool, bool) -> u8,
{
let best = extract_without_order(query, choices, processor, scorer, score_cutoff);
if best.is_empty() {
Expand Down Expand Up @@ -133,4 +133,4 @@ mod tests {
assert_eq!(best.as_str(), get_baseball_strings()[0])
}
}
}
}

0 comments on commit c8b8f0b

Please sign in to comment.