Browse Source

final - now it is completed #03

master
kauri 3 years ago
parent
commit
b27ece477e
  1. 66
      main.go

66
main.go

@ -21,8 +21,6 @@ func main() {
text_slice := SplitBySpace(string(input_text)) text_slice := SplitBySpace(string(input_text))
// fmt.Println(text_slice)
text_slice = FindHexBinArticles(text_slice) // convert nr systems text_slice = FindHexBinArticles(text_slice) // convert nr systems
text := RemoveDoubleSpaces(strings.Join(text_slice, " ")) // empty slice units removed text := RemoveDoubleSpaces(strings.Join(text_slice, " ")) // empty slice units removed
@ -79,85 +77,47 @@ func FixPunctuation(text string) string {
func FixApostrophes(text string) string { func FixApostrophes(text string) string {
pair_count := true // after finding first apostrophe will turn false, after second back to true pair_count := true // after finding first apostrophe will turn false, after second back to true
runes := []rune(text) runes := []rune(text)
mark1 := '‘' // rune('\'') mark1 := '‘'
mark2 := '’' // rune('\'') mark2 := '’'
for i, letter := range runes { 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 { 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 continue
} }
}
// runes = append(runes[:i], runes[i+2:]...)
// runes = append(runes[:i-1], runes[i:]...)
if letter == mark1 || letter == mark2 {
if pair_count { if pair_count {
if i < len(runes)-2 && runes[i+1] == rune(32) { 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 pair_count = false
// fmt.Println("first_...")
continue continue
} else { } else {
pair_count = false pair_count = false
// fmt.Println("first...")
continue continue
} }
} }
if !pair_count { if !pair_count {
if i > 1 && runes[i-1] == rune(32) { 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 pair_count = true
// fmt.Println("..._second")
continue continue
} else { } else {
pair_count = true pair_count = true
// fmt.Println("...second")
continue 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 = text[:i+1] + text[i+2:] for _, char := range runes {
pair_count = false text += string(char)
continue }
} return text
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 { func FindHexBinArticles(slice []string) []string {

Loading…
Cancel
Save