-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] String normalize expression (#2450)
Adds an expression to normalize strings, for preprocessing for deduplication. Offers four options: removing punctuation, lowercasing, removing extra whitespace, and Unicode normalization.
- Loading branch information
Showing
16 changed files
with
399 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use daft_core::{ | ||
datatypes::{DataType, Field}, | ||
schema::Schema, | ||
series::Series, | ||
}; | ||
|
||
use crate::functions::FunctionExpr; | ||
use crate::ExprRef; | ||
use common_error::{DaftError, DaftResult}; | ||
|
||
use super::{super::FunctionEvaluator, Utf8Expr}; | ||
|
||
pub(super) struct NormalizeEvaluator {} | ||
|
||
impl FunctionEvaluator for NormalizeEvaluator { | ||
fn fn_name(&self) -> &'static str { | ||
"normalize" | ||
} | ||
|
||
fn to_field(&self, inputs: &[ExprRef], schema: &Schema, _: &FunctionExpr) -> DaftResult<Field> { | ||
match inputs { | ||
[data] => match data.to_field(schema) { | ||
Ok(data_field) => match &data_field.dtype { | ||
DataType::Utf8 => Ok(Field::new(data_field.name, DataType::Utf8)), | ||
_ => Err(DaftError::TypeError(format!( | ||
"Expects input to normalize to be utf8, but received {data_field}", | ||
))), | ||
}, | ||
Err(e) => Err(e), | ||
}, | ||
_ => Err(DaftError::SchemaMismatch(format!( | ||
"Expected 1 input args, got {}", | ||
inputs.len() | ||
))), | ||
} | ||
} | ||
|
||
fn evaluate(&self, inputs: &[Series], expr: &FunctionExpr) -> DaftResult<Series> { | ||
match inputs { | ||
[data] => { | ||
let opts = match expr { | ||
FunctionExpr::Utf8(Utf8Expr::Normalize(opts)) => opts, | ||
_ => panic!("Expected Utf8 Normalize Expr, got {expr}"), | ||
}; | ||
data.utf8_normalize(*opts) | ||
} | ||
_ => Err(DaftError::ValueError(format!( | ||
"Expected 1 input args, got {}", | ||
inputs.len() | ||
))), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.