Documentation

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

NameTypeDescription
Text to MatchStringThe text to find a match for
List of ItemsListList of items to search for a match
Minimum PercentageNumberMinimum similarity percentage for a match (between 0 and 100)

Action Outputs

NameTypeDescription
SuccessBooleanWhether the function executed successfully
Best MatchStringThe item that best matches the input text
ScoreNumberThe similarity score of the best match
FoundBooleanWhether a match was found or not
ErrorStringError 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.