Created
August 11, 2018 18:49
-
-
Save lkrych/2058a73fdbaa76662e8cdccd2aee5af1 to your computer and use it in GitHub Desktop.
Main function of frequency table construction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"regexp" | |
"strings" | |
flags "github.com/jessevdk/go-flags" | |
) | |
var opts struct { | |
File string `short:"f" long:"file" description:"a file to read strings from."` | |
} | |
func main() { | |
//interpret the CL stdin | |
flags.Parse(&opts) | |
file, err := ioutil.ReadFile(opts.File) | |
checkErr(err) | |
//create an array of strings that is split by the newline character | |
splitByWord := strings.Split(string(file), " ") | |
table := createFreqTable(splitByWord) | |
fmt.Println("The frequency table is") | |
wordCount := 0 | |
for _, node := range table.keys() { | |
wordCount++ | |
fmt.Printf("%v -> %v \n", node.key, node.val) | |
} | |
fmt.Println("The number of unique words is", wordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment