You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
595 B

7 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/dghubble/go-twitter/twitter"
  6. )
  7. func mapWords(text string, words map[string]int) map[string]int {
  8. s := strings.Split(text, " ")
  9. for _, v := range s {
  10. if _, ok := words[v]; ok {
  11. words[v] = words[v] + 1
  12. } else {
  13. words[v] = 1
  14. }
  15. }
  16. return words
  17. }
  18. func analyzeWords(tweets []twitter.Tweet) map[string]int {
  19. var words = make(map[string]int)
  20. for _, v := range tweets {
  21. words = mapWords(v.Text, words)
  22. }
  23. //get sorted list of frequency words
  24. _ = printSortedMapStringInt(words, minNumWords)
  25. fmt.Println(" ")
  26. return words
  27. }