Constructor for the QGramSimilarity class.
Initializes the q-Gram similarity metric with two input strings or arrays of strings and optional options.
Metric is symmetrical.
First input string or array of strings
Second input string or array of strings
Optionalopt: MetricOptions = {}Options for the metric computation
Protected ReadonlyoptionsOptions for the metric computation, such as performance tracking
Protected ReadonlyoptProtected ReadonlysymmetricIndicates whether the metric is symmetric (same result for inputs in any order)
Private_Converts a string into a set of q-grams (substrings of length q).
The input string
The length of each q-gram
Clear the cached results of the metric.
This method resets the results property to undefined, effectively clearing
any previously computed results. It can be useful for re-running the metric
with new inputs or options.
ProtectedcomputeCalculates the q-Gram similarity between two strings.
First string
Second string
Get the name of the metric.
Get the result of the metric computation.
Check if the inputs are in batch mode.
This method checks if either a or b contains more than one string,
indicating that the metric is being run in batch mode.
Check if the inputs are in pairwise mode.
This method checks if both a and b are arrays of the same length,
indicating that the metric is being run on corresponding pairs of strings.
Optionalsafe: boolean = falseIf true, does not throw an error if lengths are not equal
Check if the inputs are in single mode.
This method checks if both a and b are single strings (not arrays),
indicating that the metric is being run on a single pair of strings.
Check if the metric is symmetrical.
This method returns whether the metric is symmetric, meaning it produces the same result regardless of the order of inputs (e.g., Levenshtein distance).
ProtectedprePre-compute the metric for two strings. This method is called before the actual computation to handle trivial cases.
First string
Second string
Length of the first string
Length of the second string
Run the metric computation based on the specified mode.
Optionalmode: MetricModeThe mode to run the metric in (optional)
Optionalclear: boolean = trueWhether to clear previous results before running
Run the metric computation based on the specified mode asynchronously.
Optionalmode: MetricModeThe mode to run the metric in (optional)
Optionalclear: boolean = trueWhether to clear previous results before running
Set the original inputs to which the results of the metric calculation will refer.
Optionala: MetricInputoriginal input(s) for a
Optionalb: MetricInputoriginal input(s) for b
Determine which mode to run the metric in.
This method checks the provided mode or defaults to the mode specified in options. If no mode is specified, it defaults to 'default'.
Optionalmode: MetricModeThe mode to run the metric in (optional)
Protected StaticclampClamps the similarity result between 0 and 1.
The input similarity to clamp
StaticclearStatic method to clear the cache of metric computations.
Protected StaticswapSwaps two strings and their lengths if the first is longer than the second.
First string
Second string
Length of the first string
Length of the second string
QGramSimilarity class extends the Metric class to implement the q-Gram similarity algorithm.