From a7e70223e979ec5b44bd2d8b5e2da83746207f91 Mon Sep 17 00:00:00 2001 From: Rangertaha Date: Mon, 25 Nov 2024 20:50:22 -0500 Subject: [PATCH] created helper functions --- pkg/typo/helper.go | 236 ++++++++++++++++++++++----------------------- 1 file changed, 118 insertions(+), 118 deletions(-) diff --git a/pkg/typo/helper.go b/pkg/typo/helper.go index 3b19d22..ed8297d 100644 --- a/pkg/typo/helper.go +++ b/pkg/typo/helper.go @@ -14,134 +14,134 @@ // along with this program. If not, see . package typo -import ( - "strings" -) +// import ( +// "strings" +// ) -func numeralMap(data map[string][]string, pos int) (words map[string]string) { - words = make(map[string]string) +// func numeralMap(data map[string][]string, pos int) (words map[string]string) { +// words = make(map[string]string) - for num, tokens := range data { - for i, token := range tokens { - if i == pos { - words[num] = token - // words[token] = num - } - } - } +// for num, tokens := range data { +// for i, token := range tokens { +// if i == pos { +// words[num] = token +// // words[token] = num +// } +// } +// } - return -} +// return +// } -// Adjacent returns adjacent characters on a given keyboard -func adjacentCharacters(char string, layout ...string) (chars []string) { - chars = []string{} - for r, row := range layout { - for c := range row { - var top, bottom, left, right string - if char == string(layout[r][c]) { - if r > 0 { - top = string(layout[r-1][c]) - if top != " " { - chars = append(chars, top) - } - } - if r < len(layout)-1 { - bottom = string(layout[r+1][c]) - if bottom != " " { - chars = append(chars, bottom) - } - } - if c > 0 { - left = string(layout[r][c-1]) - if left != " " { - chars = append(chars, left) - } - } - if c < len(row)-1 { - right = string(layout[r][c+1]) - if right != " " { - chars = append(chars, right) - } - } - } - } - } - return chars -} +// // Adjacent returns adjacent characters on a given keyboard +// func adjacentCharacters(char string, layout ...string) (chars []string) { +// chars = []string{} +// for r, row := range layout { +// for c := range row { +// var top, bottom, left, right string +// if char == string(layout[r][c]) { +// if r > 0 { +// top = string(layout[r-1][c]) +// if top != " " { +// chars = append(chars, top) +// } +// } +// if r < len(layout)-1 { +// bottom = string(layout[r+1][c]) +// if bottom != " " { +// chars = append(chars, bottom) +// } +// } +// if c > 0 { +// left = string(layout[r][c-1]) +// if left != " " { +// chars = append(chars, left) +// } +// } +// if c < len(row)-1 { +// right = string(layout[r][c+1]) +// if right != " " { +// chars = append(chars, right) +// } +// } +// } +// } +// } +// return chars +// } -// similarChars returns homoglyphs, characters that look alike from other languages -func similarChars(key string, data map[string][]string) (chars []string) { - chars = []string{} - char, ok := data[key] - if ok { - chars = append(chars, char...) - } - return chars -} +// // similarChars returns homoglyphs, characters that look alike from other languages +// func similarChars(key string, data map[string][]string) (chars []string) { +// chars = []string{} +// char, ok := data[key] +// if ok { +// chars = append(chars, char...) +// } +// return chars +// } -// similarSounds returns common homophones, words that sound alike -func similarSounds(str string, data ...[]string) (words []string) { - words = []string{} - for _, wordset := range data { - for _, word := range wordset { - if strings.Contains(str, word) { - for _, w := range wordset { - if w != word { - words = append(words, strings.Replace(str, word, w, -1)) - } - } +// // similarSounds returns common homophones, words that sound alike +// func similarSounds(str string, data ...[]string) (words []string) { +// words = []string{} +// for _, wordset := range data { +// for _, word := range wordset { +// if strings.Contains(str, word) { +// for _, w := range wordset { +// if w != word { +// words = append(words, strings.Replace(str, word, w, -1)) +// } +// } - } - } - } - return -} +// } +// } +// } +// return +// } -func characterDeletion(token string, character string) (tokens []string) { - var nmap = map[string]bool{} +// func characterDeletion(token string, character string) (tokens []string) { +// var nmap = map[string]bool{} - for i, char := range token { - if character == string(char) { - nmap[token[:i]+token[i+1:]] = true - // tokens = append(tokens, token[:i]+token[i+1:]) - } - } - nmap[strings.Replace(token, character, "", -1)] = true +// for i, char := range token { +// if character == string(char) { +// nmap[token[:i]+token[i+1:]] = true +// // tokens = append(tokens, token[:i]+token[i+1:]) +// } +// } +// nmap[strings.Replace(token, character, "", -1)] = true - for n := range nmap { - tokens = append(tokens, n) - } +// for n := range nmap { +// tokens = append(tokens, n) +// } - return -} +// return +// } -// PrefixInsertion creates tokens by prepending each prefix from the given -// list to the specified token. Example: -// Inputs: -// -// prefixes = ["www", "ftp", "shop"] -// token = "example" -// -// Outputs: ["wwwexample", "ftpexample", "shopexample"] -func PrefixInsertion(token string, prefixes ...string) (tokens []string) { - for _, prefix := range prefixes { - tokens = append(tokens, prefix+token) - } - return -} +// // PrefixInsertion creates tokens by prepending each prefix from the given +// // list to the specified token. Example: +// // Inputs: +// // +// // prefixes = ["www", "ftp", "shop"] +// // token = "example" +// // +// // Outputs: ["wwwexample", "ftpexample", "shopexample"] +// func PrefixInsertion(token string, prefixes ...string) (tokens []string) { +// for _, prefix := range prefixes { +// tokens = append(tokens, prefix+token) +// } +// return +// } -// SuffixInsertion creates tokens by appending each suffix from the provided -// list to the end (right side) of the given token. Example: -// Inputs: -// -// suffixes = ["com", "net", "io"] -// token = "example" -// -// Outputs: ["examplecom", "examplenet", "exampleio"] -func SuffixInsertion(token string, suffixes ...string) (tokens []string) { - for _, suffix := range suffixes { - tokens = append(tokens, token+suffix) - } - return -} +// // SuffixInsertion creates tokens by appending each suffix from the provided +// // list to the end (right side) of the given token. Example: +// // Inputs: +// // +// // suffixes = ["com", "net", "io"] +// // token = "example" +// // +// // Outputs: ["examplecom", "examplenet", "exampleio"] +// func SuffixInsertion(token string, suffixes ...string) (tokens []string) { +// for _, suffix := range suffixes { +// tokens = append(tokens, token+suffix) +// } +// return +// }