Levenshtein String Matching Percentile
Find the best match for a string from a list of items using Levenshtein distance and a minimum similarity percentage.
For example:
Using the text "applee" and a list of items ["apple", "banana", "cherry", "date", "elderberry"] with a minimum percentage of 40, the function would return "apple" as the best match with a similarity score of 83%.
Action Inputs
Name | Type | Description |
---|---|---|
Text to Match | String | The text to find a match for |
List of Items | List | List of items to search for a match |
Minimum Percentage | Number | Minimum similarity percentage for a match (between 0 and 100) |
Action Outputs
Name | Type | Description |
---|---|---|
Success | Boolean | Whether the function executed successfully |
Best Match | String | The item that best matches the input text |
Score | Number | The similarity score of the best match |
Found | Boolean | Whether a match was found or not |
Error | String | Error message if an error occurred (null if no error) |
Example
Input:
const testEvent = {
text: "applee",
list_items: ["apple", "banana", "cherry", "date", "elderberry"],
minimum_percentage: 40
};
Execution Logs:
Filtering result: { item: 'apple', similarityPercentage: 83 } Pass: true
Filtering result: { item: 'banana', similarityPercentage: 0 } Pass: false
Filtering result: { item: 'cherry', similarityPercentage: 0 } Pass: false
Filtering result: { item: 'date', similarityPercentage: 17 } Pass: false
Filtering result: { item: 'elderberry', similarityPercentage: 10 } Pass: false
Filtered results: [ { item: 'apple', similarityPercentage: 83 } ]
Best match found: { item: 'apple', similarityPercentage: 83 }
Final result: { best_match: 'apple', score: 83, found: true }
Final Return:
{
success: true,
best_match: 'apple',
score: 83,
found: true,
error: null
}
In this example, the function successfully found a match. The input "applee" best matches with "apple" from the list, with a similarity score of 83%, which is above the minimum percentage of 40%. The function executed successfully, so success
is true, and error
is null.
Updated 2 months ago