From c13d8366e33db316063d122b0570797f5ef7ace3 Mon Sep 17 00:00:00 2001 From: kauri Date: Wed, 15 Sep 2021 02:13:42 +0300 Subject: [PATCH 01/14] Premiere #01 --- main.go | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..da29a2c --- /dev/null +++ b/main.go @@ -0,0 +1,4 @@ +package main + +func main() { +} From fd222b1e0cb9b057f8c717e7d4db08e0e13f3f31 Mon Sep 17 00:00:00 2001 From: kauri Date: Thu, 16 Sep 2021 15:11:16 +0300 Subject: [PATCH 02/14] pool koodi --- main.go | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/main.go b/main.go index da29a2c..45ea7ff 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,156 @@ package main +import ( + "fmt" + "io/ioutil" + "os" + "strconv" + "strings" +) + func main() { + file_name := string(os.Args[1]) + input_text, err_01 := ioutil.ReadFile(file_name) + + if err_01 != nil { + fmt.Println("ebaõnnestus") + os.Exit(1) + } + + text_slice := SplitBySpace(string(input_text)) + + text_slice = FindTriggers(text_slice) + + output_text := strings.Join(text_slice, " ") + + output_text = FixPunctuation(output_text) + + // os.WriteFile(os.Args[2], output_text, os.ModePerm) + + fmt.Println(string(output_text)) +} + +func FixPunctuation(text string) string { + apostrophe_pair := true + + for i := 0; i < len(text); i++ { + + if strings.ContainsAny(string(text[i]), ".,!?:;") && i > 0 && i > len(text)-1 { + fmt.Println("found sth") + text = strings.TrimPrefix(text[i-1:i+1], " ") // removes single space before punctuation + + if strings.ContainsAny(string(text[i+1]), ".,!?:;") { + continue + } + if string(text[i+1]) != " " { + text = text[:i+1] + " " + text[i+1:] + } + } + + if string(text[i]) == "'" && apostrophe_pair && i > len(text)-1 { + fmt.Println("found first apostrophe") + text = strings.TrimSuffix(text[i:i+2], " ") + apostrophe_pair = false + } + if string(text[i]) == "'" && !apostrophe_pair { + fmt.Println("found second apostrophe") + text = strings.TrimPrefix(text[i-1:i+1], " ") + apostrophe_pair = true + } + } + return text +} + +func FindTriggers(slice []string) []string { + var x int + for i := range slice { + + if slice[i] == "(bin)" || slice[i] == "(hex)" { // ok, except one additional space added + x = Converter(slice[i-1], slice[i]) + slice[i-1] = strconv.Itoa(x) + slice[i] = "" + } + if slice[i] == "(up)" { + slice[i-1] = strings.ToUpper(slice[i-1]) + slice[i] = "" + } + if slice[i] == "(low)" { + slice[i-1] = strings.ToLower(slice[i-1]) + slice[i] = "" + } + if slice[i] == "(cap)" { + slice[i-1] = strings.ToUpper(string(slice[i-1][0])) + slice[i-1][1:] + slice[i] = "" + } + if i+1 != len(slice) && (slice[i] == "a" || slice[i] == "A") { // ok + if strings.ContainsAny(string(slice[i+1][0]), "aeiouh") { + slice[i] += "n" + } + } + + } + return slice +} + +func SplitBySpace(text string) []string { + separator := " " + str_temp := "" // temporary string + text_slice := make([]string, 0) + + for i := 0; i < len(text); i++ { + + if string(text[i]) != separator { + str_temp += string(text[i]) + } else if str_temp == "(low," || str_temp == "(up," || str_temp == "(cap," { + continue + } else { + text_slice = append(text_slice, str_temp) + str_temp = "" + } + if i == len(text)-1 { + text_slice = append(text_slice, str_temp) + } + } + return text_slice +} + +func Converter(str, system string) int { + var x int + var base string + + if system == "(hex)" { + base = "0123456789ABCDEF" + } + if system == "(bin)" { + base = "01" + } + + temp_result := 0 + result := 0 + + for id, digit := range str { + + for base_id, base_nr := range base { + if digit == base_nr { + x = base_id + } + } + z := len(str) - 1 - id + y := len(base) + yVar := y + if z == 0 { + temp_result = x + } else if z == 1 { + temp_result = x * y + } else { + for i := 1; i < z; i++ { + yVar *= y + } + temp_result = x * yVar + } + result += temp_result + y = 0 + z = 0 + } + return result } From 75e3e35ff8b14a8eda39dc5f17d945baef25a7b8 Mon Sep 17 00:00:00 2001 From: kauri Date: Thu, 16 Sep 2021 22:50:56 +0300 Subject: [PATCH 03/14] =?UTF-8?q?l=C3=B5petatud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 127 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 102 insertions(+), 25 deletions(-) diff --git a/main.go b/main.go index 45ea7ff..795d4de 100644 --- a/main.go +++ b/main.go @@ -17,36 +17,87 @@ func main() { os.Exit(1) } - text_slice := SplitBySpace(string(input_text)) + // fmt.Println(string(input_text)) - text_slice = FindTriggers(text_slice) + input_text = []byte(FixPunctuation(string(input_text))) // initial punctuation edits - output_text := strings.Join(text_slice, " ") + text_slice := SplitBySpace(string(input_text)) // string to slice of strings - output_text = FixPunctuation(output_text) + text_slice = FindTriggers(text_slice) // find and correct formatting/converting - // os.WriteFile(os.Args[2], output_text, os.ModePerm) + output_text := RemoveDoubleSpaces(strings.Join(text_slice, " ")) // slice back to single string - fmt.Println(string(output_text)) + output_text = FixApostrophes(output_text) // function dealing with apostrophes + + output_text = FixPunctuation(output_text) // final punctuation control + + os.WriteFile(string(os.Args[2]), []byte(string(output_text)), os.ModePerm) + + // fmt.Println(string(output_text)) +} + +func RemoveDoubleSpaces(text string) string { + for x := 0; x < len(text)-1; x++ { + if x < len(text)-1 && rune(text[x]) == 32 && rune(text[x+1]) == 32 { + text = text[:x] + text[x+1:] + x = 0 + } + } + return text } func FixPunctuation(text string) string { - apostrophe_pair := true + text = RemoveDoubleSpaces(text) for i := 0; i < len(text); i++ { + if string(text[i]) == "." || string(text[i]) == "," || string(text[i]) == "!" || + string(text[i]) == "?" || string(text[i]) == ":" || string(text[i]) == ";" { - if strings.ContainsAny(string(text[i]), ".,!?:;") && i > 0 && i > len(text)-1 { - fmt.Println("found sth") - text = strings.TrimPrefix(text[i-1:i+1], " ") // removes single space before punctuation + if i > 0 && string(text[i-1]) == " " { + text = text[:(i-1)] + text[i:] + } + } else if string(text[i]) != " " { + if i > 0 && (string(text[i-1]) == "." || string(text[i-1]) == "," || string(text[i-1]) == "!" || + string(text[i-1]) == "?" || string(text[i-1]) == ":" || string(text[i-1]) == ";") { + text = text[:i] + " " + text[i:] + } + } + } + return text +} + +func FixApostrophes(text string) string { + pair_count := true // after finding first apostrophe will turn false, after second back to true + + for i := 0; i < len(text); i++ { + if string(text[i]) == "'" { - if strings.ContainsAny(string(text[i+1]), ".,!?:;") { + if i > 0 && i < len(text)-1 && string(text[i-1]) != " " && string(text[i+1]) != " " { continue } - if string(text[i+1]) != " " { - text = text[:i+1] + " " + text[i+1:] + + if i < len(text)-2 && string(text[i+1]) == " " && pair_count { + text = text[:i+1] + text[i+2:] + pair_count = false + continue + } + if pair_count { + pair_count = false + continue } + if i > 1 && string(text[i-1]) == " " && !pair_count { + text = text[:i-1] + text[i:] + pair_count = true + } + if !pair_count { + pair_count = true + } + } + } + // if string(text[i]) == "'" && + /* if string(text[i]) == "'" && apostrophe_pair && i > len(text)-1 { fmt.Println("found first apostrophe") text = strings.TrimSuffix(text[i:i+2], " ") @@ -56,33 +107,58 @@ func FixPunctuation(text string) string { fmt.Println("found second apostrophe") text = strings.TrimPrefix(text[i-1:i+1], " ") apostrophe_pair = true - } - } + }*/ return text } -func FindTriggers(slice []string) []string { +func FindTriggers(slice []string) []string { // all of those add extra space when completed (fix implemented) var x int + var z int // how many words to modify for i := range slice { - if slice[i] == "(bin)" || slice[i] == "(hex)" { // ok, except one additional space added + if slice[i] == "(bin)" || slice[i] == "(hex)" { x = Converter(slice[i-1], slice[i]) slice[i-1] = strconv.Itoa(x) slice[i] = "" } - if slice[i] == "(up)" { + + if strings.Contains(string(slice[i]), "(up)") { slice[i-1] = strings.ToUpper(slice[i-1]) - slice[i] = "" + slice[i] = strings.TrimPrefix(slice[i], "(up)") + } + if strings.Contains(string(slice[i]), "(up,") { + z = int(slice[i][5]) - 48 + for a := i - z; a < i; a++ { + slice[a] = strings.ToUpper(slice[a]) + } + slice[i] = slice[i][7:] } - if slice[i] == "(low)" { + + if strings.Contains(string(slice[i]), "(low)") { slice[i-1] = strings.ToLower(slice[i-1]) - slice[i] = "" + slice[i] = strings.TrimPrefix(slice[i], "(low)") } - if slice[i] == "(cap)" { + if strings.Contains(string(slice[i]), "(low,") { + z = int(slice[i][6]) - 48 + for b := i - z; b < i; b++ { + slice[b] = strings.ToLower(slice[b]) + } + slice[i] = slice[i][8:] + } + + if strings.Contains(string(slice[i]), "(cap)") { slice[i-1] = strings.ToUpper(string(slice[i-1][0])) + slice[i-1][1:] - slice[i] = "" + slice[i] = strings.TrimPrefix(slice[i], "(cap)") + } + if strings.Contains(string(slice[i]), "(cap,") { + z = int(slice[i][6]) - 48 + for c := i - z; c < i; c++ { + slice[c] = strings.ToUpper(string(slice[c][0])) + slice[c][1:] + } + slice[i] = slice[i][8:] } - if i+1 != len(slice) && (slice[i] == "a" || slice[i] == "A") { // ok + + if i+1 != len(slice) && (slice[i] == "a" || slice[i] == "A") { if strings.ContainsAny(string(slice[i+1][0]), "aeiouh") { slice[i] += "n" } @@ -102,6 +178,7 @@ func SplitBySpace(text string) []string { if string(text[i]) != separator { str_temp += string(text[i]) } else if str_temp == "(low," || str_temp == "(up," || str_temp == "(cap," { + str_temp += string(text[i]) continue } else { text_slice = append(text_slice, str_temp) @@ -114,7 +191,7 @@ func SplitBySpace(text string) []string { return text_slice } -func Converter(str, system string) int { +func Converter(str, system string) int { // converting ok (input check missing) var x int var base string From dbbe07ce2ace26e9e7f8cc1fef698a7fe7ad4cca Mon Sep 17 00:00:00 2001 From: kauri Date: Thu, 16 Sep 2021 22:53:41 +0300 Subject: [PATCH 04/14] final - commented section removed --- main.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/main.go b/main.go index 795d4de..d2edaee 100644 --- a/main.go +++ b/main.go @@ -95,19 +95,6 @@ func FixApostrophes(text string) string { } } - // if string(text[i]) == "'" && - - /* - if string(text[i]) == "'" && apostrophe_pair && i > len(text)-1 { - fmt.Println("found first apostrophe") - text = strings.TrimSuffix(text[i:i+2], " ") - apostrophe_pair = false - } - if string(text[i]) == "'" && !apostrophe_pair { - fmt.Println("found second apostrophe") - text = strings.TrimPrefix(text[i-1:i+1], " ") - apostrophe_pair = true - }*/ return text } From cf33151df5790aee26ae687953afd381b6f04567 Mon Sep 17 00:00:00 2001 From: kauri Date: Thu, 16 Sep 2021 23:05:03 +0300 Subject: [PATCH 05/14] finalized --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index d2edaee..fdfe868 100644 --- a/main.go +++ b/main.go @@ -27,10 +27,10 @@ func main() { output_text := RemoveDoubleSpaces(strings.Join(text_slice, " ")) // slice back to single string - output_text = FixApostrophes(output_text) // function dealing with apostrophes - output_text = FixPunctuation(output_text) // final punctuation control + output_text = FixApostrophes(output_text) // function dealing with apostrophes + os.WriteFile(string(os.Args[2]), []byte(string(output_text)), os.ModePerm) // fmt.Println(string(output_text)) From ce78e00434d95380fc031be33850d92e85b2d48e Mon Sep 17 00:00:00 2001 From: kauri Date: Thu, 16 Sep 2021 23:46:40 +0300 Subject: [PATCH 06/14] final optimized --- main.go | 59 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/main.go b/main.go index fdfe868..3522be0 100644 --- a/main.go +++ b/main.go @@ -19,17 +19,23 @@ func main() { // fmt.Println(string(input_text)) - input_text = []byte(FixPunctuation(string(input_text))) // initial punctuation edits + text_slice := SplitBySpace(string(input_text)) - text_slice := SplitBySpace(string(input_text)) // string to slice of strings + text_slice = FindHexBinArticles(text_slice) // convert nr systems - text_slice = FindTriggers(text_slice) // find and correct formatting/converting + text := RemoveDoubleSpaces(strings.Join(text_slice, " ")) // empty slice units removed - output_text := RemoveDoubleSpaces(strings.Join(text_slice, " ")) // slice back to single string + text = FixPunctuation(text) // first punctuation check + + next_slice := SplitBySpace(text) + + next_slice = FindTriggers(next_slice) // upper lower capitalize + + output_text := RemoveDoubleSpaces(strings.Join(next_slice, " ")) // slice back to single string output_text = FixPunctuation(output_text) // final punctuation control - output_text = FixApostrophes(output_text) // function dealing with apostrophes + output_text = FixApostrophes(output_text) // apostrophes being checked os.WriteFile(string(os.Args[2]), []byte(string(output_text)), os.ModePerm) @@ -98,24 +104,37 @@ func FixApostrophes(text string) string { return text } -func FindTriggers(slice []string) []string { // all of those add extra space when completed (fix implemented) +func FindHexBinArticles(slice []string) []string { var x int - var z int // how many words to modify for i := range slice { - - if slice[i] == "(bin)" || slice[i] == "(hex)" { - x = Converter(slice[i-1], slice[i]) + if strings.Contains(string(slice[i]), "(bin)") || strings.Contains(string(slice[i]), "(hex)") { + x = Converter(slice[i-1], slice[i][:5]) slice[i-1] = strconv.Itoa(x) - slice[i] = "" + + slice[i] = strings.TrimPrefix(slice[i], "(bin)") + slice[i] = strings.TrimPrefix(slice[i], "(hex)") } + if i+1 != len(slice) && (slice[i] == "a" || slice[i] == "A") { + if strings.ContainsAny(string(slice[i+1][0]), "aeiouh") { + slice[i] += "n" + } + } + } + return slice +} + +func FindTriggers(slice []string) []string { // all of those add extra space when completed (fix implemented) + + var x int // how many words to modify + for i := range slice { if strings.Contains(string(slice[i]), "(up)") { slice[i-1] = strings.ToUpper(slice[i-1]) slice[i] = strings.TrimPrefix(slice[i], "(up)") } if strings.Contains(string(slice[i]), "(up,") { - z = int(slice[i][5]) - 48 - for a := i - z; a < i; a++ { + x = int(slice[i][5]) - 48 + for a := i - x; a < i; a++ { slice[a] = strings.ToUpper(slice[a]) } slice[i] = slice[i][7:] @@ -126,8 +145,8 @@ func FindTriggers(slice []string) []string { // all of those add extra space whe slice[i] = strings.TrimPrefix(slice[i], "(low)") } if strings.Contains(string(slice[i]), "(low,") { - z = int(slice[i][6]) - 48 - for b := i - z; b < i; b++ { + x = int(slice[i][6]) - 48 + for b := i - x; b < i; b++ { slice[b] = strings.ToLower(slice[b]) } slice[i] = slice[i][8:] @@ -138,19 +157,13 @@ func FindTriggers(slice []string) []string { // all of those add extra space whe slice[i] = strings.TrimPrefix(slice[i], "(cap)") } if strings.Contains(string(slice[i]), "(cap,") { - z = int(slice[i][6]) - 48 - for c := i - z; c < i; c++ { + x = int(slice[i][6]) - 48 + for c := i - x; c < i; c++ { slice[c] = strings.ToUpper(string(slice[c][0])) + slice[c][1:] } slice[i] = slice[i][8:] } - if i+1 != len(slice) && (slice[i] == "a" || slice[i] == "A") { - if strings.ContainsAny(string(slice[i+1][0]), "aeiouh") { - slice[i] += "n" - } - } - } return slice } From efeab4c0682ee1c2830dd2cede150bc5173ce4c7 Mon Sep 17 00:00:00 2001 From: kauri Date: Fri, 17 Sep 2021 14:28:29 +0300 Subject: [PATCH 07/14] final hex more reliable --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 3522be0..9d6933d 100644 --- a/main.go +++ b/main.go @@ -109,7 +109,7 @@ func FindHexBinArticles(slice []string) []string { for i := range slice { if strings.Contains(string(slice[i]), "(bin)") || strings.Contains(string(slice[i]), "(hex)") { x = Converter(slice[i-1], slice[i][:5]) - slice[i-1] = strconv.Itoa(x) + slice[i-1] = strings.ToUpper(strconv.Itoa(x)) slice[i] = strings.TrimPrefix(slice[i], "(bin)") slice[i] = strings.TrimPrefix(slice[i], "(hex)") From 18284b9eafecb0f7fae86301d32f6b0a91290f1f Mon Sep 17 00:00:00 2001 From: kauri Date: Fri, 17 Sep 2021 14:58:47 +0300 Subject: [PATCH 08/14] final hex fixed --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 9d6933d..eefbc42 100644 --- a/main.go +++ b/main.go @@ -108,8 +108,8 @@ func FindHexBinArticles(slice []string) []string { var x int for i := range slice { if strings.Contains(string(slice[i]), "(bin)") || strings.Contains(string(slice[i]), "(hex)") { - x = Converter(slice[i-1], slice[i][:5]) - slice[i-1] = strings.ToUpper(strconv.Itoa(x)) + x = Converter(strings.ToUpper(slice[i-1]), slice[i][:5]) + slice[i-1] = strconv.Itoa(x) slice[i] = strings.TrimPrefix(slice[i], "(bin)") slice[i] = strings.TrimPrefix(slice[i], "(hex)") From 77ffa39cb3c7832b487c5134d6246876f3a21427 Mon Sep 17 00:00:00 2001 From: kauri Date: Sat, 18 Sep 2021 15:34:30 +0300 Subject: [PATCH 09/14] final - apostrophes new #01 --- main.go | 88 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/main.go b/main.go index eefbc42..dc21881 100644 --- a/main.go +++ b/main.go @@ -21,10 +21,14 @@ func main() { text_slice := SplitBySpace(string(input_text)) + // fmt.Println(text_slice) + text_slice = FindHexBinArticles(text_slice) // convert nr systems text := RemoveDoubleSpaces(strings.Join(text_slice, " ")) // empty slice units removed + // fmt.Println(text) + text = FixPunctuation(text) // first punctuation check next_slice := SplitBySpace(text) @@ -37,9 +41,9 @@ func main() { output_text = FixApostrophes(output_text) // apostrophes being checked - os.WriteFile(string(os.Args[2]), []byte(string(output_text)), os.ModePerm) + fmt.Println(string(output_text)) - // fmt.Println(string(output_text)) + os.WriteFile(string(os.Args[2]), []byte(string(output_text)), os.ModePerm) } func RemoveDoubleSpaces(text string) string { @@ -74,34 +78,74 @@ func FixPunctuation(text string) string { func FixApostrophes(text string) string { pair_count := true // after finding first apostrophe will turn false, after second back to true - - for i := 0; i < len(text); i++ { - if string(text[i]) == "'" { - - if i > 0 && i < len(text)-1 && string(text[i-1]) != " " && string(text[i+1]) != " " { + runes := []rune(text) + mark1 := '‘' // rune('\'') + mark2 := '’' // rune('\'') + for i, letter := range runes { + + if letter == mark2 { + if i > 0 && i < len(runes)-1 && runes[i-1] != 32 && runes[i+1] != 32 { + fmt.Println("check: mark 2 detected") continue } + } - if i < len(text)-2 && string(text[i+1]) == " " && pair_count { - text = text[:i+1] + text[i+2:] - pair_count = false + if letter == mark1 { + if i > 0 && i < len(runes)-1 && runes[i-1] != 32 && runes[i+1] != 32 { + fmt.Println("check: mark 1 detected ") continue } + } + + if letter == mark1 || letter == mark2 { + if pair_count { - pair_count = false - continue - } - if i > 1 && string(text[i-1]) == " " && !pair_count { - text = text[:i-1] + text[i:] - pair_count = true + if i < (len(runes)-2) && runes[i+1] == 32 { // somewhy will not enter into this if + // text = text[:i] + "‘" + text[i+2:] + runes = append(runes[:i], runes[i+2:]...) + pair_count = false + continue + } } if !pair_count { - pair_count = true - } + if (i > 1) && runes[i-1] == 32 { + // text = text[:i-1] + "’" + text[i+1:] + runes = append(runes[:i-1], runes[i:]...) + pair_count = true + // a = append(a[:i], append([]T{x}, a[i:]...)...) --to insert + } + } } } return text + /* + for i := 0; i < len(text); i++ { //initial apostrophe check for " ' " markings (functional) + if string(text[i]) == "'" { + + if i > 0 && i < len(text)-1 && string(text[i-1]) != " " && string(text[i+1]) != " " { + continue + } + + if i < len(text)-2 && string(text[i+1]) == " " && pair_count { + text = text[:i+1] + text[i+2:] + pair_count = false + continue + } + if pair_count { + pair_count = false + continue + } + if i > 1 && string(text[i-1]) == " " && !pair_count { + text = text[:i-1] + text[i:] + pair_count = true + } + if !pair_count { + pair_count = true + } + } + } + */ } func FindHexBinArticles(slice []string) []string { @@ -173,12 +217,12 @@ func SplitBySpace(text string) []string { str_temp := "" // temporary string text_slice := make([]string, 0) - for i := 0; i < len(text); i++ { + for i, char := range text { - if string(text[i]) != separator { - str_temp += string(text[i]) + if string(char) != separator { + str_temp += string(char) } else if str_temp == "(low," || str_temp == "(up," || str_temp == "(cap," { - str_temp += string(text[i]) + str_temp += string(char) continue } else { text_slice = append(text_slice, str_temp) From 7b843c5353838575eafb688d7842e111b6d32c0e Mon Sep 17 00:00:00 2001 From: kauri Date: Sat, 18 Sep 2021 18:44:15 +0300 Subject: [PATCH 10/14] final - apostrophes detections works #02 --- main.go | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index dc21881..f81efb6 100644 --- a/main.go +++ b/main.go @@ -41,7 +41,7 @@ func main() { output_text = FixApostrophes(output_text) // apostrophes being checked - fmt.Println(string(output_text)) + // fmt.Println(string(output_text)) os.WriteFile(string(os.Args[2]), []byte(string(output_text)), os.ModePerm) } @@ -84,36 +84,48 @@ func FixApostrophes(text string) string { for i, letter := range runes { if letter == mark2 { + // fmt.Println("mark2 detected") if i > 0 && i < len(runes)-1 && runes[i-1] != 32 && runes[i+1] != 32 { - fmt.Println("check: mark 2 detected") + // fmt.Println("check: mark 2 in text") continue } } - if letter == mark1 { + if letter == mark1 { // separate if for troubleshooting only; will be joined with previous if + // fmt.Println("mark1 detected") if i > 0 && i < len(runes)-1 && runes[i-1] != 32 && runes[i+1] != 32 { - fmt.Println("check: mark 1 detected ") + // fmt.Println("check: mark 1 in text") continue } } + // runes = append(runes[:i], runes[i+2:]...) + // runes = append(runes[:i-1], runes[i:]...) if letter == mark1 || letter == mark2 { if pair_count { - if i < (len(runes)-2) && runes[i+1] == 32 { // somewhy will not enter into this if - // text = text[:i] + "‘" + text[i+2:] - runes = append(runes[:i], runes[i+2:]...) + if i < len(runes)-2 && runes[i+1] == rune(32) { + runes = append(runes[:i], runes[i+2:]...) // suspected reason for malfunction pair_count = false + // fmt.Println("first_...") + continue + } else { + pair_count = false + // fmt.Println("first...") continue } } + if !pair_count { - if (i > 1) && runes[i-1] == 32 { - // text = text[:i-1] + "’" + text[i+1:] - runes = append(runes[:i-1], runes[i:]...) + if i > 1 && runes[i-1] == rune(32) { + runes = append(runes[:i-1], runes[i:]...) // suspected reason for malfunction pair_count = true - - // a = append(a[:i], append([]T{x}, a[i:]...)...) --to insert + // fmt.Println("..._second") + continue + } else { + pair_count = true + // fmt.Println("...second") + continue } } } From b27ece477e96d190fb4466f0175e39a8bde9d20b Mon Sep 17 00:00:00 2001 From: kauri Date: Sat, 18 Sep 2021 19:01:36 +0300 Subject: [PATCH 11/14] final - now it is completed #03 --- main.go | 66 ++++++++++++--------------------------------------------- 1 file changed, 13 insertions(+), 53 deletions(-) diff --git a/main.go b/main.go index f81efb6..b0e28cc 100644 --- a/main.go +++ b/main.go @@ -21,8 +21,6 @@ func main() { text_slice := SplitBySpace(string(input_text)) - // fmt.Println(text_slice) - text_slice = FindHexBinArticles(text_slice) // convert nr systems text := RemoveDoubleSpaces(strings.Join(text_slice, " ")) // empty slice units removed @@ -79,85 +77,47 @@ func FixPunctuation(text string) string { func FixApostrophes(text string) string { pair_count := true // after finding first apostrophe will turn false, after second back to true runes := []rune(text) - mark1 := '‘' // rune('\'') - mark2 := '’' // rune('\'') + mark1 := '‘' + mark2 := '’' for i, letter := range runes { + if letter == mark1 || letter == mark2 { - if letter == mark2 { - // fmt.Println("mark2 detected") - if i > 0 && i < len(runes)-1 && runes[i-1] != 32 && runes[i+1] != 32 { - // fmt.Println("check: mark 2 in text") - continue - } - } - - if letter == mark1 { // separate if for troubleshooting only; will be joined with previous if - // fmt.Println("mark1 detected") if i > 0 && i < len(runes)-1 && runes[i-1] != 32 && runes[i+1] != 32 { - // fmt.Println("check: mark 1 in text") + runes[i] = mark2 continue } - } - // runes = append(runes[:i], runes[i+2:]...) - // runes = append(runes[:i-1], runes[i:]...) - - if letter == mark1 || letter == mark2 { if pair_count { if i < len(runes)-2 && runes[i+1] == rune(32) { - runes = append(runes[:i], runes[i+2:]...) // suspected reason for malfunction + runes[i] = mark1 + runes = append(runes[:i+1], runes[i+2:]...) pair_count = false - // fmt.Println("first_...") continue } else { pair_count = false - // fmt.Println("first...") continue } } if !pair_count { if i > 1 && runes[i-1] == rune(32) { - runes = append(runes[:i-1], runes[i:]...) // suspected reason for malfunction + runes[i] = mark2 + runes = append(runes[:i-1], runes[i:]...) pair_count = true - // fmt.Println("..._second") continue } else { pair_count = true - // fmt.Println("...second") continue } } } } - return text - /* - for i := 0; i < len(text); i++ { //initial apostrophe check for " ' " markings (functional) - if string(text[i]) == "'" { - - if i > 0 && i < len(text)-1 && string(text[i-1]) != " " && string(text[i+1]) != " " { - continue - } - if i < len(text)-2 && string(text[i+1]) == " " && pair_count { - text = text[:i+1] + text[i+2:] - pair_count = false - continue - } - if pair_count { - pair_count = false - continue - } - if i > 1 && string(text[i-1]) == " " && !pair_count { - text = text[:i-1] + text[i:] - pair_count = true - } - if !pair_count { - pair_count = true - } - } - } - */ + text = "" + for _, char := range runes { + text += string(char) + } + return text } func FindHexBinArticles(slice []string) []string { From 399c225492460fe8cba609a292493139cd54195f Mon Sep 17 00:00:00 2001 From: kauri Date: Sat, 18 Sep 2021 21:01:24 +0300 Subject: [PATCH 12/14] final - mark1 mark1 added #04 --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b0e28cc..408ef73 100644 --- a/main.go +++ b/main.go @@ -94,6 +94,7 @@ func FixApostrophes(text string) string { pair_count = false continue } else { + runes[i] = mark1 pair_count = false continue } @@ -106,6 +107,7 @@ func FixApostrophes(text string) string { pair_count = true continue } else { + runes[i] = mark2 pair_count = true continue } @@ -130,7 +132,7 @@ func FindHexBinArticles(slice []string) []string { slice[i] = strings.TrimPrefix(slice[i], "(bin)") slice[i] = strings.TrimPrefix(slice[i], "(hex)") } - if i+1 != len(slice) && (slice[i] == "a" || slice[i] == "A") { + if i+1 != len(slice) && (slice[i] == "a" || slice[i] == "A") && len(slice[i+1]) != 0 { if strings.ContainsAny(string(slice[i+1][0]), "aeiouh") { slice[i] += "n" } From 575ec50cd001b6164e12ba4f09d1264759dac523 Mon Sep 17 00:00:00 2001 From: kauri Date: Sat, 18 Sep 2021 22:09:49 +0300 Subject: [PATCH 13/14] final - last char included #05 --- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 408ef73..867172a 100644 --- a/main.go +++ b/main.go @@ -17,10 +17,12 @@ func main() { os.Exit(1) } - // fmt.Println(string(input_text)) + fmt.Println(string(input_text)) text_slice := SplitBySpace(string(input_text)) + fmt.Println(text_slice) + text_slice = FindHexBinArticles(text_slice) // convert nr systems text := RemoveDoubleSpaces(strings.Join(text_slice, " ")) // empty slice units removed @@ -31,12 +33,16 @@ func main() { next_slice := SplitBySpace(text) + // strings.Fields(sisesta_string) + next_slice = FindTriggers(next_slice) // upper lower capitalize output_text := RemoveDoubleSpaces(strings.Join(next_slice, " ")) // slice back to single string output_text = FixPunctuation(output_text) // final punctuation control + fmt.Println(string(output_text)) + output_text = FixApostrophes(output_text) // apostrophes being checked // fmt.Println(string(output_text)) @@ -113,8 +119,8 @@ func FixApostrophes(text string) string { } } } + // fmt.Println(runes[(len(runes) - 1)]) } - text = "" for _, char := range runes { text += string(char) @@ -193,7 +199,7 @@ func SplitBySpace(text string) []string { for i, char := range text { - if string(char) != separator { + if string(char) != separator && i != len(text)-1 { str_temp += string(char) } else if str_temp == "(low," || str_temp == "(up," || str_temp == "(cap," { str_temp += string(char) @@ -202,9 +208,11 @@ func SplitBySpace(text string) []string { text_slice = append(text_slice, str_temp) str_temp = "" } + if i == len(text)-1 { text_slice = append(text_slice, str_temp) } + } return text_slice } From 3ca3755f16fefd079cb862ae8a564039238519bc Mon Sep 17 00:00:00 2001 From: kauri Date: Wed, 20 Oct 2021 10:17:40 +0300 Subject: [PATCH 14/14] final again for review - #06 --- main.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 867172a..d7aa29d 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,8 @@ import ( "strings" ) +// 20OCT21 review commit verison + func main() { file_name := string(os.Args[1]) input_text, err_01 := ioutil.ReadFile(file_name) @@ -17,11 +19,11 @@ func main() { os.Exit(1) } - fmt.Println(string(input_text)) + // fmt.Println(string(input_text)) text_slice := SplitBySpace(string(input_text)) - fmt.Println(text_slice) + // fmt.Println(text_slice) text_slice = FindHexBinArticles(text_slice) // convert nr systems @@ -41,7 +43,7 @@ func main() { output_text = FixPunctuation(output_text) // final punctuation control - fmt.Println(string(output_text)) + // fmt.Println(string(output_text)) output_text = FixApostrophes(output_text) // apostrophes being checked @@ -115,11 +117,19 @@ func FixApostrophes(text string) string { } else { runes[i] = mark2 pair_count = true + /* + if i < len(runes)-1 { + if rune(runes[i+1]) != ' ' { + helper := runes + runes = append(runes[:i+1], rune(32)) + runes = append(runes, helper[i+1:]...) + } + } + */ continue } } } - // fmt.Println(runes[(len(runes) - 1)]) } text = "" for _, char := range runes {