countJaro static method
Calculates the Jaro similarity score between an item and a list of search terms.
The Jaro similarity score is a measure of the similarity between two strings. This function takes an item, a list of search terms, and various options to customize the comparison. It returns the sum of the Jaro similarity scores between the item and each search term.
- The
searchTerms
parameter is an iterable of search terms to compare against the item. - The
searchOn
parameter is a function that takes the item and returns an iterable of values to search on. - The
ignoreCase
parameter specifies whether to ignore case when comparing strings (default is true). - The
ignoreDiacritics
parameter specifies whether to ignore diacritics when comparing strings (default is true). - The
ignoreWordSplitters
parameter specifies whether to ignore word splitters when comparing strings (default is true). - The
splitCamelCase
parameter specifies whether to split camel case words when comparing strings (default is true).
Returns the sum of the Jaro similarity scores between the item and each search term.
Implementation
static double countJaro({
required dynamic searchTerms,
required Iterable searchOn,
bool ignoreCase = true,
bool ignoreDiacritics = true,
bool ignoreWordSplitters = true,
bool splitCamelCase = true,
}) {
var terms = [...searchOn];
var searches = forceRecursiveList(searchTerms);
return terms
.expand((e) {
return e == null
? <double>[for (var _ in searches) 0]
: e.toString().getUniqueWords.map((keyword) {
decimal jaro = 0.0;
for (var searchTerm in searches) {
keyword = generateKeyword(
keyword,
forceLowerCase: ignoreCase,
removeDiacritics: ignoreDiacritics,
removeWordSplitters: ignoreWordSplitters,
splitCamelCase: splitCamelCase,
);
var searchword = generateKeyword(
searchTerm,
forceLowerCase: ignoreCase,
removeDiacritics: ignoreDiacritics,
removeWordSplitters: ignoreWordSplitters,
splitCamelCase: splitCamelCase,
);
jaro += searchword.getJaro(keyword, !ignoreCase);
}
return jaro;
});
})
.sum
.toDouble();
}