### Install go-edlib Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Install the go-edlib package using the go get command. ```bash go get github.com/hbollon/go-edlib ``` -------------------------------- ### Get LCS Difference Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Backtracks through the LCS matrix to return the differences between two sequences. Added in v1.1.0. ```go func LCSDiff(str1, str2 string) ([]string, error) ``` -------------------------------- ### Import go-edlib Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Import the go-edlib library into your Go project. ```go import ( "github.com/hbollon/go-edlib" ) ``` -------------------------------- ### Run Unit Tests (Linux) Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Execute all unit tests for the go-edlib library on Linux systems. ```bash ./tests/tests.sh ``` -------------------------------- ### Run Unit Tests (Windows) Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Execute all unit tests for the go-edlib library on Windows systems. ```bash go test ./... ``` -------------------------------- ### Generate K-grams (Shingles) as Slice Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Finds the k-grams (shingles) of a string for a given k and returns them as a slice of strings. Returns an empty slice if the string is empty or k is 0. ```go func ShingleSlice(s string, k int) []string ``` -------------------------------- ### Generate K-grams (Shingles) as Map Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Finds the k-grams (shingles) of a string for a given k and returns them as a map of string to count. Returns an empty map if the string is empty or k is 0. ```go func Shingle(s string, k int) map[string]int ``` -------------------------------- ### StringHashMap AddAll Method Signature Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Adds all elements from a source StringHashMap to the target StringHashMap. Ensure the source map is not nil before calling. ```go func (m StringHashMap) AddAll(srcMap StringHashMap) ``` -------------------------------- ### Calculate Q-gram Similarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes a similarity index (between 0 and 1) between two strings based on their q-gram distance. Requires a split length for k-gram shingling. ```go func QgramSimilarity(str1, str2 string, splitLength int) float32 ``` -------------------------------- ### Fuzzy Search with Threshold Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Finds strings in a list that match a query string above a specified similarity threshold. Demonstrates usage with different thresholds. ```go strList := []string{"test", "tester", "tests", "testers", "testing", "tsting", "sting"} res, err := edlib.FuzzySearchSetThreshold("testnig", strList, 3, 0.5, edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Result for 'testnig' with '0.5' threshold: %s", strings.Join(res, " ")) } res, err = edlib.FuzzySearchSetThreshold("testnig", strList, 3, 0.7, edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Result for 'testnig' with '0.7' threshold: %s", strings.Join(res, " ")) } ``` -------------------------------- ### Shingle Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Finds the k-grams (shingles) of a string for a given k. It takes a string and an integer k as parameters and returns a map where keys are k-grams and values are their frequencies. Returns an empty map if the string is empty or k is 0. ```APIDOC ## func Shingle ### Description Find the k-gram of a string for a given k. ### Parameters - `s` (string) - The input string. - `k` (int) - The k-gram size. ``` -------------------------------- ### LCSBacktrackAll Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Returns an array containing all common substrings between two strings by backtracking through the LCS process. ```APIDOC ## LCSBacktrackAll ### Description Returns an array containing all common substrings between two strings by backtracking through the LCS process. ### Function Signature ```go func LCSBacktrackAll(str1, str2 string) ([]string, error) ``` ``` -------------------------------- ### Fuzzy Search with Set Threshold Source: https://pkg.go.dev/github.com/hbollon/go-edlib Finds strings in a list that meet a minimum similarity threshold. Adjusting the threshold changes the inclusivity of results. ```go strList := []string{"test", "tester", "tests", "testers", "testing", "tsting", "sting"} res, err := edlib.FuzzySearchSetThreshold("testnig", strList, 3, 0.5, edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Result for 'testnig' with '0.5' threshold: %s", strings.Join(res, " ")) } res, err = edlib.FuzzySearchSetThreshold("testnig", strList, 3, 0.7, edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Result for 'testnig' with '0.7' threshold: %s", strings.Join(res, " ")) } ``` -------------------------------- ### Equal Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/utils Compares two rune slices and returns true if they are equal, false otherwise. ```APIDOC ## Equal ### Description Compares two rune slices and returns true if they are equal, false otherwise. ### Signature ``` func Equal(a, b []rune) bool ``` ``` -------------------------------- ### StringHashMap Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/utils Represents a HashMap substitute for strings. ```APIDOC ## StringHashMap ### Description StringHashMap is a HashMap substitute for string. ### Type Definition ``` type StringHashMap map[string]struct{} ``` ``` -------------------------------- ### Fuzzy Search with Similarity Threshold Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Searches a string list for strings similar to the input, returning a specified quantity above a minimum similarity threshold. Added in v1.2.0. ```go func FuzzySearchSetThreshold(str string, strList []string, quantity int, minSim float32, algo Algorithm) ([]string, error) ``` -------------------------------- ### Calculate Q-gram Distance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the q-gram similarity between two strings using a specified split length for k-grams. ```go func QgramDistance(str1, str2 string, splitLength int) int ``` -------------------------------- ### Calculate String Similarity with Levenshtein Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Calculate the similarity index between two strings using the Levenshtein algorithm. Handles potential errors during calculation. ```go res, err := edlib.StringsSimilarity("string1", "string2", edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Similarity: %f", res) } ``` -------------------------------- ### Equal Function Signature Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Compares two rune arrays for equality. Use this function to check if two sequences of runes are identical. ```go func Equal(a, b []rune) bool ``` -------------------------------- ### Calculate Q-gram Distance with Custom Ngrams Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the q-gram similarity between two pre-computed sets of n-grams represented as maps. ```go func QgramDistanceCustomNgram(splittedStr1, splittedStr2 map[string]int) int ``` -------------------------------- ### QgramDistanceCustomNgram Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the q-gram similarity between two custom sets of n-grams. It takes two maps, where keys are n-grams and values are their frequencies, and returns an integer distance. ```APIDOC ## func QgramDistanceCustomNgram ### Description Computes the q-gram similarity between two custom set of individuals. ### Parameters - `splittedStr1` (map[string]int) - The first map of n-grams and their frequencies. - `splittedStr2` (map[string]int) - The second map of n-grams and their frequencies. ``` -------------------------------- ### Min Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/utils Returns the smallest integer among the two provided integers. ```APIDOC ## Min ### Description Returns the smallest integer among the two provided integers. ### Signature ``` func Min(a int, b int) int ``` ``` -------------------------------- ### LCSBacktrackAll Source: https://pkg.go.dev/github.com/hbollon/go-edlib Backtracks to find all possible Longest Common Subsequences (LCS) between two strings. ```APIDOC ## LCSBacktrackAll ### Description Backtracks to find all possible Longest Common Subsequences (LCS) between two strings. ### Function Signature ```go func LCSBacktrackAll(str1, str2 string) ([]string, error) ``` ### Parameters #### Path Parameters This function does not have path parameters. #### Query Parameters This function does not have query parameters. #### Request Body This function does not have a request body. ### Request Example ```go res, err := edlib.LCSBacktrackAll("ABCD", "ACBAD") if err != nil { fmt.Println(err) } else { fmt.Printf("LCS: %s", strings.Join(res, ", ")) } ``` ### Response #### Success Response Returns a slice of strings representing all LCS and nil error. #### Response Example ``` LCS: ABD, ACD ``` #### Error Response Returns an error if backtracking fails. ``` -------------------------------- ### OrderedMap Methods Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/orderedmap This section details the methods available for the OrderedMap type, including Len, Less, SortByValues, Swap, and ToArray. ```APIDOC ## type OrderedMap ``` type OrderedMap []pair ``` OrderedMap is a slice of pairs type with string keys and float values. It implement sorting methods by values. ### Methods #### Len ``` func (p OrderedMap) Len() int ``` Len return length of a given OrderedMap. #### Less ``` func (p OrderedMap) Less(i, j int) bool ``` Less return if a element of an OrderedMap is smaller than another. #### SortByValues ``` func (p OrderedMap) SortByValues() ``` SortByValues sort by values an OrderedMap in decreasing order. #### Swap ``` func (p OrderedMap) Swap(i, j int) ``` Swap two members of an OrderedMap. #### ToArray ``` func (p OrderedMap) ToArray() []string ``` ToArray export keys of an OrderedMap into a slice. ``` -------------------------------- ### OrderedMap Methods Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/orderedmap This section details the methods available for the OrderedMap type, including Len, Less, SortByValues, Swap, and ToArray. ```APIDOC ## type OrderedMap ``` type OrderedMap []pair ``` OrderedMap is a slice of pairs type with string keys and float values. It implement sorting methods by values. ### func (OrderedMap) Len ``` func (p OrderedMap) Len() int ``` Len return length of a given OrderedMap ### func (OrderedMap) Less ``` func (p OrderedMap) Less(i, j int) bool ``` Less return if a element of an OrderedMap is smaller than another ### func (OrderedMap) SortByValues ``` func (p OrderedMap) SortByValues() ``` SortByValues sort by values an OrderedMap in decreasing order ### func (OrderedMap) Swap ``` func (p OrderedMap) Swap(i, j int) ``` Swap two members of an OrderedMap ### func (OrderedMap) ToArray ``` func (p OrderedMap) ToArray() []string ``` ToArray export keys of an OrderedMap into a slice ``` -------------------------------- ### ShingleSlice Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Finds the k-grams (shingles) of a string for a given k and returns them as a slice of strings. It takes a string and an integer k as parameters. Returns an empty slice if the string is empty or k is 0. ```APIDOC ## func ShingleSlice ### Description Find the k-gram of a string for a given k. ### Parameters - `s` (string) - The input string. - `k` (int) - The k-gram size. ``` -------------------------------- ### StringHashMap.AddAll Method Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Adds all elements from a source StringHashMap to the current one. ```APIDOC ## func (StringHashMap) AddAll ### Description Adds all elements from one StringHashMap to another. ### Signature ``` func (m StringHashMap) AddAll(srcMap StringHashMap) ``` ``` -------------------------------- ### Min Function Signature Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Returns the smallest integer between two integer parameters. Use this to find the minimum of two numbers. ```go func Min(a int, b int) int ``` -------------------------------- ### StringHashMap.AddAll Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/utils Adds all elements from a source StringHashMap to the target StringHashMap. ```APIDOC ## AddAll ### Description Adds all elements from one StringHashMap to another. ### Signature ``` func (m StringHashMap) AddAll(srcMap StringHashMap) ``` ``` -------------------------------- ### Equal Function Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Compares two rune arrays for equality. Returns true if they are identical, false otherwise. ```APIDOC ## func Equal ### Description Compares two rune arrays and returns whether they are equal. ### Signature ``` func Equal(a, b []rune) bool ``` ``` -------------------------------- ### Find All Common Substrings via LCS Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Returns an array containing all common substrings between two strings using LCS backtracking. Added in v1.1.0. ```go func LCSBacktrackAll(str1, str2 string) ([]string, error) ``` -------------------------------- ### QgramSimilarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes a similarity index (between 0 and 1) between two strings using Q-gram distance. It takes two strings and a split length (k-gram shingle length) as input. ```APIDOC ## func QgramSimilarity ### Description Computes a similarity index (between 0 and 1) between two strings from a Qgram distance. ### Parameters - `str1` (string) - The first string. - `str2` (string) - The second string. - `splitLength` (int) - The k-gram shingle length. ``` -------------------------------- ### LCSBacktrack Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Backtracks through the LCS process to return the sequence of choices made. ```APIDOC ## LCSBacktrack ### Description Backtracks through the LCS process to return the sequence of choices made. ### Function Signature ```go func LCSBacktrack(str1, str2 string) (string, error) ``` ``` -------------------------------- ### Algorithm Constants Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Defines constants for various edit distance algorithms that can be used with the Algorithm type. ```go const ( Levenshtein Algorithm = iota DamerauLevenshtein OSADamerauLevenshtein Lcs Hamming Jaro JaroWinkler Cosine Jaccard SorensenDice Qgram ) ``` -------------------------------- ### Backtrack All LCS Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Finds all possible Longest Common Subsequences (LCS) between two strings by backtracking. Returns a slice of LCS strings. ```go res, err := edlib.LCSBacktrackAll("ABCD", "ACBAD") if err != nil { fmt.Println(err) } else { fmt.Printf("LCS: %s", strings.Join(res, ", ")) } ``` -------------------------------- ### JaroSimilarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Returns a Jaro similarity index (between 0 and 1) for two strings. This algorithm allows only transposition operations. ```APIDOC ## JaroSimilarity ### Description Returns a Jaro similarity index (between 0 and 1) for two strings. This algorithm allows only transposition operations. ### Function Signature ```go func JaroSimilarity(str1, str2 string) float32 ``` ``` -------------------------------- ### StringHashMap Type Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Represents a HashMap substitute for string keys. ```APIDOC ## type StringHashMap ### Description StringHashMap is a HashMap substitute for string keys. ### Definition ``` type StringHashMap map[string]struct{} ``` ``` -------------------------------- ### Fuzzy Search with Minimum Similarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Finds the closest string in a list to the input string, provided it meets a minimum similarity threshold. Added in v1.2.0. ```go func FuzzySearchThreshold(str string, strList []string, minSim float32, algo Algorithm) (string, error) ``` -------------------------------- ### QgramDistance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the q-gram distance between two strings. It takes two strings and a split length (k-gram shingle length) as input and returns an integer representing the distance. ```APIDOC ## func QgramDistance ### Description Computes the q-gram distance between two strings. ### Parameters - `str1` (string) - The first string. - `str2` (string) - The second string. - `splitLength` (int) - The k-gram shingle length. ``` -------------------------------- ### Calculate Jaro Similarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Returns a similarity index between 0 and 1 using the Jaro distance algorithm, which allows only transposition operations. Added in v1.1.0. ```go func JaroSimilarity(str1, str2 string) float32 ``` -------------------------------- ### Calculate Jaro-Winkler Similarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Returns a similarity index between 0 and 1, using Jaro similarity and considering a common prefix up to length 4. Added in v1.1.0. ```go func JaroWinklerSimilarity(str1, str2 string) float32 ``` -------------------------------- ### Backtrack LCS Choices Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Returns all choices made during the Longest Common Subsequence (LCS) process. Added in v1.1.0. ```go func LCSBacktrack(str1, str2 string) (string, error) ``` -------------------------------- ### Min Function Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Returns the smallest of two integer values. ```APIDOC ## func Min ### Description Returns the smallest integer among the two provided parameters. ### Signature ``` func Min(a int, b int) int ``` ``` -------------------------------- ### Len Method for OrderedMap Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/orderedmap Returns the number of elements in an OrderedMap. ```go func (p OrderedMap) Len() int ``` -------------------------------- ### Fuzzy Search: Most Matching Result Set Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Retrieve a specified quantity of the most similar strings from a list compared to a target string using the Levenshtein algorithm. Results are returned as a slice of strings. ```go strList := []string{"test", "tester", "tests", "testers", "testing", "tsting", "sting"} res, err := edlib.FuzzySearchSet("testnig", strList, 3, edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Results: %s", strings.Join(res, ", ")) } ``` -------------------------------- ### Fuzzy Search for Closest String Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Performs an approximate search on a list of strings and returns the one closest to the input string using a specified algorithm. Added in v1.2.0. ```go func FuzzySearch(str string, strList []string, algo Algorithm) (string, error) ``` -------------------------------- ### Less Method for OrderedMap Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/orderedmap Compares two elements of an OrderedMap to determine if the first is smaller than the second. ```go func (p OrderedMap) Less(i, j int) bool ``` -------------------------------- ### Calculate String Similarity with Algorithm Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Returns a similarity index [0..1] between two strings based on a specified edit distance algorithm. Cosine and Jaccard algorithms use a default Shingle split length of 2. ```go func StringsSimilarity(str1 string, str2 string, algo Algorithm) (float32, error) ``` -------------------------------- ### Fuzzy Search for a Set of Strings Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Finds a set of strings from a list that are most similar to the input string, returning a specified quantity. Added in v1.2.0. ```go func FuzzySearchSet(str string, strList []string, quantity int, algo Algorithm) ([]string, error) ``` -------------------------------- ### LCSDiff Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Backtracks through the LCS matrix to return the differences between two sequences. ```APIDOC ## LCSDiff ### Description Backtracks through the LCS matrix to return the differences between two sequences. ### Function Signature ```go func LCSDiff(str1, str2 string) ([]string, error) ``` ``` -------------------------------- ### FuzzySearchSetThreshold Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Performs an approximate search on a list of strings, returning a set of `quantity` strings that meet a minimum similarity threshold (`minSim`) compared to the input string. Uses a specified algorithm. ```APIDOC ## FuzzySearchSetThreshold ### Description Performs an approximate search on a list of strings, returning a set of `quantity` strings that meet a minimum similarity threshold (`minSim`) compared to the input string. Uses a specified algorithm. ### Function Signature ```go func FuzzySearchSetThreshold(str string, strList []string, quantity int, minSim float32, algo Algorithm) ([]string, error) ``` ``` -------------------------------- ### StringHashMap ToArray Method Signature Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Converts a StringHashMap into a string array. The order of elements in the returned array is not guaranteed. ```go func (m StringHashMap) ToArray() []string ``` -------------------------------- ### Fuzzy Search: Most Matching Unique Result with Threshold Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Find the most similar unique string in a list that meets a minimum similarity threshold using the Levenshtein algorithm. Returns an empty string if no match is found. ```go strList := []string{"test", "tester", "tests", "testers", "testing", "tsting", "sting"} res, err := edlib.FuzzySearchThreshold("testnig", strList, 0.7, edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Result for 'testnig': %s", res) } res, err = edlib.FuzzySearchThreshold("hello", strList, 0.7, edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Result for 'hello': %s", res) } ``` -------------------------------- ### LCSBacktrack Source: https://pkg.go.dev/github.com/hbollon/go-edlib Backtracks to find one of the Longest Common Subsequences (LCS) between two strings. ```APIDOC ## LCSBacktrack ### Description Backtracks to find one of the Longest Common Subsequences (LCS) between two strings. ### Function Signature ```go func LCSBacktrack(str1, str2 string) (string, error) ``` ### Parameters #### Path Parameters This function does not have path parameters. #### Query Parameters This function does not have query parameters. #### Request Body This function does not have a request body. ### Request Example ```go res, err := edlib.LCSBacktrack("ABCD", "ACBAD") if err != nil { fmt.Println(err) } else { fmt.Printf("LCS: %s", res) } ``` ### Response #### Success Response Returns a string representing one LCS and nil error. #### Response Example ``` LCS: ABD ``` #### Error Response Returns an error if backtracking fails. ``` -------------------------------- ### Algorithm Type Definition Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Defines an unsigned 8-bit integer type used to identify different edit distance algorithms. ```go type Algorithm uint8 ``` -------------------------------- ### FuzzySearchThreshold Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Performs an approximate search on a list of strings and returns the closest one to the input string that meets a minimum similarity threshold (`minSim`). Uses a specified algorithm. ```APIDOC ## FuzzySearchThreshold ### Description Performs an approximate search on a list of strings and returns the closest one to the input string that meets a minimum similarity threshold (`minSim`). Uses a specified algorithm. ### Function Signature ```go func FuzzySearchThreshold(str string, strList []string, minSim float32, algo Algorithm) (string, error) ``` ``` -------------------------------- ### LCS Diff Calculation Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Calculates the difference between two strings based on their Longest Common Subsequence (LCS). Shows insertions and deletions. ```go res, err := edlib.LCSDiff("computer", "houseboat") if err != nil { fmt.Println(err) } else { fmt.Printf("LCS: \n%s\n%s", res[0], res[1]) } ``` -------------------------------- ### Swap Method for OrderedMap Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/orderedmap Exchanges the positions of two elements within an OrderedMap. ```go func (p OrderedMap) Swap(i, j int) ``` -------------------------------- ### JaccardSimilarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the Jaccard similarity coefficient between two strings. Takes the strings and a `splitLength` for k-gram length (0 splits on whitespaces) as parameters, returning a float32 similarity index. ```APIDOC ## JaccardSimilarity ### Description Computes the Jaccard similarity coefficient between two strings. Takes the strings and a `splitLength` for k-gram length (0 splits on whitespaces) as parameters, returning a float32 similarity index. ### Function Signature ```go func JaccardSimilarity(str1, str2 string, splitLength int) float32 ``` ``` -------------------------------- ### Compute Longest Common Subsequence (LCS) Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Calculates the length of the Longest Common Subsequence between two strings. ```go func LCS(str1, str2 string) int ``` -------------------------------- ### Max Function Signature Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Returns the largest integer between two integer parameters. Use this to find the maximum of two numbers. ```go func Max(a int, b int) int ``` -------------------------------- ### StringsSimilarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib Calculates the similarity between two strings using a specified algorithm. Supports various algorithms like Levenshtein, Jaro-Winkler, etc. ```APIDOC ## StringsSimilarity ### Description Calculates the similarity between two strings using a specified algorithm. Supports various algorithms like Levenshtein, Jaro-Winkler, etc. ### Function Signature ```go func StringsSimilarity(str1 string, str2 string, algo Algorithm) (float32, error) ``` ### Parameters #### Path Parameters This function does not have path parameters. #### Query Parameters This function does not have query parameters. #### Request Body This function does not have a request body. ### Request Example ```go similarity, err := edlib.StringsSimilarity("test", "test", edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Similarity: %.2f", similarity) } ``` ### Response #### Success Response Returns a float32 representing the similarity score and nil error. #### Response Example ``` Similarity: 1.00 ``` #### Error Response Returns an error if the specified algorithm is not supported or calculation fails. ``` -------------------------------- ### ToArray Method for OrderedMap Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/orderedmap Exports the keys of an OrderedMap into a string slice. ```go func (p OrderedMap) ToArray() []string ``` -------------------------------- ### FuzzySearchSet Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Performs an approximate search on a list of strings and returns a set of the `quantity` closest strings to the input string, sorted by similarity. Uses a specified algorithm. ```APIDOC ## FuzzySearchSet ### Description Performs an approximate search on a list of strings and returns a set of the `quantity` closest strings to the input string, sorted by similarity. Uses a specified algorithm. ### Function Signature ```go func FuzzySearchSet(str string, strList []string, quantity int, algo Algorithm) ([]string, error) ``` ``` -------------------------------- ### JaroWinklerSimilarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Returns a Jaro-Winkler similarity index (between 0 and 1) for two strings. It uses Jaro similarity and then considers a common prefix of up to 4 characters. ```APIDOC ## JaroWinklerSimilarity ### Description Returns a Jaro-Winkler similarity index (between 0 and 1) for two strings. It uses Jaro similarity and then considers a common prefix of up to 4 characters. ### Function Signature ```go func JaroWinklerSimilarity(str1, str2 string) float32 ``` ``` -------------------------------- ### Calculate Sorensen-Dice Coefficient Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the Sorensen-Dice coefficient between two strings using a specified split length for k-gram shingling. ```go func SorensenDiceCoefficient(str1, str2 string, splitLength int) float32 ``` -------------------------------- ### Backtrack LCS Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Finds one of the Longest Common Subsequences (LCS) between two strings by backtracking. Returns the subsequence string. ```go res, err := edlib.LCSBacktrack("ABCD", "ACBAD") if err != nil { fmt.Println(err) } else { fmt.Printf("LCS: %s", res) } ``` -------------------------------- ### Fuzzy Search: Most Matching Unique Result Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Find the most similar unique string in a list compared to a target string using the Levenshtein algorithm. No similarity threshold is applied. ```go strList := []string{"test", "tester", "tests", "testers", "testing", "tsting", "sting"} res, err := edlib.FuzzySearch("testnig", strList, edlib.Levenshtein) if err != nil { fmt.Println(err) } else { fmt.Printf("Result: %s", res) } ``` -------------------------------- ### Calculate Hamming Distance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the edit distance between two strings using only substitutions. Returns the distance and an error. Compatible with non-ASCII characters. ```go func HammingDistance(str1, str2 string) (int, error) ``` -------------------------------- ### Max Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/utils Returns the largest integer among the two provided integers. ```APIDOC ## Max ### Description Returns the largest integer among the two provided integers. ### Signature ``` func Max(a int, b int) int ``` ``` -------------------------------- ### Calculate Optimal String Alignment Damerau-Levenshtein Distance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the Optimal String Alignment (OSA) Damerau-Levenshtein distance. This variant uses an extension of the Wagner-Fisher algorithm and does not allow multiple transformations on the same substring. Compatible with non-ASCII characters. ```go func OSADamerauLevenshteinDistance(str1, str2 string) int ``` -------------------------------- ### StringsSimilarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Returns a similarity index (between 0 and 1) between two strings based on a specified edit distance algorithm. It uses the Algorithm type to define the method. Cosine and Jaccard algorithms are used with a Shingle split method of length 2 by default when this function is used with those algorithms. ```APIDOC ## func StringsSimilarity ### Description Return a similarity index [0..1] between two strings based on given edit distance algorithm in parameter. ### Parameters - `str1` (string) - The first string. - `str2` (string) - The second string. - `algo` (Algorithm) - The algorithm to use for similarity calculation. ``` -------------------------------- ### SortByValues Method for OrderedMap Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/orderedmap Sorts the elements of an OrderedMap in decreasing order based on their values. ```go func (p OrderedMap) SortByValues() ``` -------------------------------- ### Define OrderedMap Type Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/orderedmap Defines OrderedMap as a slice of pairs, intended for string keys and float values. ```go type OrderedMap []pair ``` -------------------------------- ### LCSDiff Source: https://pkg.go.dev/github.com/hbollon/go-edlib Computes the Longest Common Subsequence (LCS) difference between two strings, highlighting insertions and deletions. ```APIDOC ## LCSDiff ### Description Computes the Longest Common Subsequence (LCS) difference between two strings, highlighting insertions and deletions. ### Function Signature ```go func LCSDiff(str1, str2 string) ([]string, error) ``` ### Parameters #### Path Parameters This function does not have path parameters. #### Query Parameters This function does not have query parameters. #### Request Body This function does not have a request body. ### Request Example ```go res, err := edlib.LCSDiff("computer", "houseboat") if err != nil { fmt.Println(err) } else { fmt.Printf("LCS: \n%s\n%s", res[0], res[1]) } ``` ### Response #### Success Response Returns a slice of two strings representing the LCS difference and nil error. #### Response Example ``` LCS Diff: h c o m p u s e b o a t e r + - - - + + + + + - - ``` #### Error Response Returns an error if the LCS difference calculation fails. ``` -------------------------------- ### StringHashMap.ToArray Method Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Converts and returns the StringHashMap as a string array. ```APIDOC ## func (StringHashMap) ToArray ### Description Converts and returns an StringHashMap to a string array. ### Signature ``` func (m StringHashMap) ToArray() []string ``` ``` -------------------------------- ### Levenshtein Distance Calculation Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Calculates the Levenshtein edit distance between two strings. This is a fundamental measure of string dissimilarity. ```go res := edlib.LevenshteinDistance("kitten", "sitting") fmt.Printf("Result: %d", res) ``` -------------------------------- ### FuzzySearch Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Performs an approximate search on a list of strings and returns the one closest to the input string, using a specified algorithm. ```APIDOC ## FuzzySearch ### Description Performs an approximate search on a list of strings and returns the one closest to the input string, using a specified algorithm. ### Function Signature ```go func FuzzySearch(str string, strList []string, algo Algorithm) (string, error) ``` ``` -------------------------------- ### Longest Common Subsequence (LCS) Length Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the length of the Longest Common Subsequence (LCS) between two strings. Useful for identifying shared sequences. ```go lcs := edlib.LCS("ABCD", "ACBAD") fmt.Printf("Length of their LCS: %d", lcs) ``` -------------------------------- ### Calculate Levenshtein Distance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the Levenshtein distance between two strings, allowing insertions, deletions, and substitutions. Compatible with non-ASCII characters. ```go func LevenshteinDistance(str1, str2 string) int ``` -------------------------------- ### CosineSimilarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib Calculates the Cosine Similarity between two strings using a specified split length for k-gram vectorization. If split length is zero, strings are split on whitespaces. ```APIDOC ## CosineSimilarity ### Description Calculates the Cosine Similarity between two strings using a specified split length for k-gram vectorization. If split length is zero, strings are split on whitespaces. ### Function Signature ```go func CosineSimilarity(str1, str2 string, splitLength int) float32 ``` ### Parameters #### Path Parameters This function does not have path parameters. #### Query Parameters This function does not have query parameters. #### Request Body This function does not have a request body. ### Request Example ```go similarity := edlib.CosineSimilarity("hello world", "world hello", 1) fmt.Printf("Cosine Similarity: %.2f", similarity) ``` ### Response #### Success Response Returns a float32 representing the Cosine Similarity index. #### Response Example ``` Cosine Similarity: 0.80 ``` ``` -------------------------------- ### OSADamerauLevenshteinDistance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Calculates the Optimal String Alignment (OSA) Damerau-Levenshtein distance. This variant uses an extension of the Wagner-Fisher algorithm and allows insertions, deletions, substitutions, and transpositions, but not multiple transformations on the same substring. Compatible with non-ASCII characters. ```APIDOC ## OSADamerauLevenshteinDistance ### Description Calculates the Optimal String Alignment (OSA) Damerau-Levenshtein distance. This variant uses an extension of the Wagner-Fisher algorithm and allows insertions, deletions, substitutions, and transpositions, but not multiple transformations on the same substring. Compatible with non-ASCII characters. ### Function Signature ```go func OSADamerauLevenshteinDistance(str1, str2 string) int ``` ``` -------------------------------- ### StringHashMap.ToArray Source: https://pkg.go.dev/github.com/hbollon/go-edlib/internal/utils Converts and returns a StringHashMap as a string slice. ```APIDOC ## ToArray ### Description Converts and returns an StringHashMap to a string slice. ### Signature ``` func (m StringHashMap) ToArray() []string ``` ``` -------------------------------- ### Calculate Damerau-Levenshtein Distance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the true Damerau–Levenshtein distance between two strings, allowing insertions, deletions, substitutions, and transpositions. Compatible with non-ASCII characters. ```go func DamerauLevenshteinDistance(str1, str2 string) int ``` -------------------------------- ### Compute Jaccard Similarity Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Calculates the Jaccard similarity coefficient between two strings. Allows specifying a k-gram split length. Added in v1.4.0. ```go func JaccardSimilarity(str1, str2 string, splitLength int) float32 ``` -------------------------------- ### LCS Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the Longest Common Subsequence (LCS) length between two strings. ```APIDOC ## LCS ### Description Computes the Longest Common Subsequence (LCS) length between two strings. ### Function Signature ```go func LCS(str1, str2 string) int ``` ``` -------------------------------- ### Max Function Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Returns the largest of two integer values. ```APIDOC ## func Max ### Description Returns the largest integer among the two provided parameters. ### Signature ``` func Max(a int, b int) int ``` ``` -------------------------------- ### HammingDistance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Calculates the Hamming distance between two strings, which counts only substitutions. Returns the edit distance as an integer and an error if applicable. ```APIDOC ## HammingDistance ### Description Calculates the Hamming distance between two strings, which counts only substitutions. Returns the edit distance as an integer and an error if applicable. ### Function Signature ```go func HammingDistance(str1, str2 string) (int, error) ``` ``` -------------------------------- ### LevenshteinDistance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Calculates the Levenshtein distance between two strings, allowing insertions, deletions, and substitutions. Compatible with non-ASCII characters. ```APIDOC ## LevenshteinDistance ### Description Calculates the Levenshtein distance between two strings, allowing insertions, deletions, and substitutions. Compatible with non-ASCII characters. ### Function Signature ```go func LevenshteinDistance(str1, str2 string) int ``` ``` -------------------------------- ### StringHashMap Type Definition Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0/internal/utils Defines StringHashMap as a map substitute for strings, using struct{} for memory efficiency. Use this type when you need a set-like behavior for strings. ```go type StringHashMap map[string]struct{} ``` -------------------------------- ### HammingDistance Source: https://pkg.go.dev/github.com/hbollon/go-edlib Calculates the Hamming distance between two strings of equal length. This is the number of positions at which the corresponding symbols are different. ```APIDOC ## HammingDistance ### Description Calculates the Hamming distance between two strings of equal length. This is the number of positions at which the corresponding symbols are different. ### Function Signature ```go func HammingDistance(str1, str2 string) (int, error) ``` ### Parameters #### Path Parameters This function does not have path parameters. #### Query Parameters This function does not have query parameters. #### Request Body This function does not have a request body. ### Request Example ```go res, err := edlib.HammingDistance("karolin", "kathrin") if err != nil { fmt.Println(err) } else { fmt.Printf("Result: %d", res) } ``` ### Response #### Success Response Returns an integer representing the Hamming distance and nil error. #### Response Example ``` Result: 3 ``` #### Error Response Returns an error if the strings are not of equal length. ``` -------------------------------- ### Calculate LCS Edit Distance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Determines the edit distance between two strings using the LCS function, allowing only insert and delete operations. ```go func LCSEditDistance(str1, str2 string) int ``` -------------------------------- ### DamerauLevenshteinDistance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Calculates the true Damerau–Levenshtein distance between two strings, allowing insertions, deletions, substitutions, and adjacent transpositions. Compatible with non-ASCII characters. ```APIDOC ## DamerauLevenshteinDistance ### Description Calculates the true Damerau–Levenshtein distance between two strings, allowing insertions, deletions, substitutions, and adjacent transpositions. Compatible with non-ASCII characters. ### Function Signature ```go func DamerauLevenshteinDistance(str1, str2 string) int ``` ``` -------------------------------- ### SorensenDiceCoefficient Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Computes the Sorensen-Dice coefficient between two strings. It takes two strings and a split length (k-gram shingle length) as input and returns a float32 similarity index. ```APIDOC ## func SorensenDiceCoefficient ### Description Computes the Sorensen-Dice coefficient between two strings. ### Parameters - `str1` (string) - The first string. - `str2` (string) - The second string. - `splitLength` (int) - The k-gram shingle length. ``` -------------------------------- ### LCSEditDistance Source: https://pkg.go.dev/github.com/hbollon/go-edlib%40v1.7.0 Determines the edit distance between two strings using the LCS function, allowing only insert and delete operations. ```APIDOC ## LCSEditDistance ### Description Determines the edit distance between two strings using the LCS function, allowing only insert and delete operations. ### Function Signature ```go func LCSEditDistance(str1, str2 string) int ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.