This is a creation in Article, where the information may have evolved or changed.
The main purpose is to count the number of words appearing in an article, at present it is only a general framework, the results of statistics only two kinds,
One is two words of one is three words, and the accuracy is not high, need to optimize the place too much,
The first note down, back to idle to continue to optimize, the accuracy and processing speed to bring up.
Rookie writing is not good, look at you a lot of advice.
</pre><pre name= "code" class= "plain" >package mainimport ("FMT" "Io/ioutil" "strings") var Tri map[string] int = make (Map[string]int) var Dou map[string]int = Make (Map[string]int) var Num int = 2var Path string = "Test.txt" func mai N () {Buf, _: = Ioutil. ReadFile (Path) N: = Len (Buf) Str: = String (Buf) Get_slice (n, Buf, &str) List: = Paixu (Dou) List_tri: = Paixu (Tri) Getvalue (Rm_duplicate (&list), Dou) Getvalue (Rm_duplicate (&list_tri), Tri)}func get_slice (n int, Buf []byte, Str *string) {var i, x, y int = 0, 0, 0var Th Ree Stringfor I < n-2 {if buf[i] > x = i + 3for x < n-2 {if BUF[X] > $ {s: = string (buf[i:i+3]) + Strin G (buf[x:x+3]) if I: = strings. Count (*str, s); I > 1 {dou[s] = I}y = x + 3for y < n-2 {if buf[y] > {three = s + string (Buf[y:y+3]) break} else {Y++}}break} E LSE {X++}}IF I: = strings. Count (*str, three); I > 1 {tri[three] = I}i = i + 3} else {I++}}}func Paixu (Map map[string]int) []int {var list []intfor _, K: = Range Map {list = AppenD (list, k)}num: = Len (list) for I: = 0; i < num; i++ {for J: = i + 1, j < Num, J + + {if list[i] < List[j] {List[i], list[j] = list[j], List[i]}}}return list}func Getv Alue (list []int, Map Map[string]int) {For _, I: = Range List[:num] {for k, V: = range Map {if i = = v {fmt. Println (k, "occurrences:", i)}}}}func rm_duplicate (list *[]int) []int {var x []int = []int{}for _, I: = Range *list {if len (x) = = 0 {x = append (x, i)} else {for k, V: = range x {if i = = v {break}if k = = Len (x)-1 {x = append (x, i)}}}}return x}