Home>

I was able to create a program that requires a short TF in the GO language, but I cannot create a program that requires a long TF in English.
The long sentences in English are summarized in .txt, but I don't know how to find the long TF written in the text file. Thanks for your help.

go
  • Answer # 1

    The frequency of occurrence can be counted as follows.
    The rest is sort, but after the postscript I tried to think about by myself.

    https://play.golang.org/p/sjDV88hRXPr

    package main
    import (
        "bufio"
        "bytes"
        "fmt"
        "strings"
    )
    var source = `
    I have a pen.
    I have an apple.
    Apple pen!
    I have a pen.
    I have a pineapple.
    Pineapple pen!
    `
    func main () {
        count: = map [string] int {}
        scanner: = bufio.NewScanner (bytes.NewBuffer ([] byte (source)))
        scanner.Split (bufio.ScanWords)
        for scanner.Scan () {
            word: = strings.TrimRight (scanner.Text (), ".!")
            count [word] + = 1
        }
        fmt.Println (count)
    }

    Output

    map [Apple: 1 I: 4 Pineapple: 1 a: 3 an: 1 apple: 1 have: 4 pen: 4 pineapple: 1]