Split compound words on soft hyphens
This commit is contained in:
1 parent
adeab23665
commit
a114271432
1 file changed
+13
-1
@@ -139,7 +139,7 @@ fn get_discrete_words<S: AsRef<str>>(s: S) -> (String, Option<Vec<String>>) {
|
|||||||
|
|
||||||
let words = s
|
let words = s
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.replace(|c: char| c.is_ascii_punctuation(), " ")
|
.replace(|c: char| c.is_ascii_punctuation() || c == '\u{AD}', " ")
|
||||||
.to_case(Case::Lower)
|
.to_case(Case::Lower)
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
@@ -210,10 +210,13 @@ mod tests {
|
|||||||
let camel_results = get_indexable_words("ThreeAntelopes", stemmer.as_ref(), &[]);
|
let camel_results = get_indexable_words("ThreeAntelopes", stemmer.as_ref(), &[]);
|
||||||
let kebab_results = get_indexable_words("three-antelopes", stemmer.as_ref(), &[]);
|
let kebab_results = get_indexable_words("three-antelopes", stemmer.as_ref(), &[]);
|
||||||
let snake_results = get_indexable_words("three_antelopes", stemmer.as_ref(), &[]);
|
let snake_results = get_indexable_words("three_antelopes", stemmer.as_ref(), &[]);
|
||||||
|
let soft_hyphen_results =
|
||||||
|
get_indexable_words("three\u{AD}antelopes", stemmer.as_ref(), &[]);
|
||||||
|
|
||||||
assert_eq!(camel_results, expected);
|
assert_eq!(camel_results, expected);
|
||||||
assert_eq!(kebab_results, expected);
|
assert_eq!(kebab_results, expected);
|
||||||
assert_eq!(snake_results, expected);
|
assert_eq!(snake_results, expected);
|
||||||
|
assert_eq!(soft_hyphen_results, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -258,6 +261,15 @@ mod tests {
|
|||||||
assert_eq!(get_discrete_words(input), ("array structures".into(), None));
|
assert_eq!(get_discrete_words(input), ("array structures".into(), None));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn soft_hyphenated_words() {
|
||||||
|
let input = "Hochspannungs\u{AD}netz\u{AD}teil";
|
||||||
|
assert_eq!(
|
||||||
|
get_discrete_words(input),
|
||||||
|
("hochspannungs netz teil".into(), None)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn camel_words() {
|
fn camel_words() {
|
||||||
let input = "WKWebVIEWComponent";
|
let input = "WKWebVIEWComponent";
|
||||||
|
|||||||
Reference in new issue
Block a user