mirror of
https://github.com/arnaucube/argos.git
synced 2026-02-08 03:26:39 +01:00
hashtag analysis, and some updates
This commit is contained in:
@@ -2,33 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/dghubble/go-twitter/twitter"
|
||||
)
|
||||
|
||||
func sortMapWords(m map[string]int) map[int][]string {
|
||||
n := map[int][]string{}
|
||||
var a []int
|
||||
for k, v := range m {
|
||||
if v > minNumWords {
|
||||
n[v] = append(n[v], k)
|
||||
}
|
||||
}
|
||||
for k := range n {
|
||||
a = append(a, k)
|
||||
}
|
||||
sort.Sort(sort.Reverse(sort.IntSlice(a)))
|
||||
for _, k := range a {
|
||||
for _, s := range n[k] {
|
||||
fmt.Printf("%d - %s,\n", k, s)
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func mapWords(text string, words map[string]int) {
|
||||
func mapWords(text string, words map[string]int) map[string]int {
|
||||
s := strings.Split(text, " ")
|
||||
|
||||
for _, v := range s {
|
||||
@@ -38,16 +17,18 @@ func mapWords(text string, words map[string]int) {
|
||||
words[v] = 1
|
||||
}
|
||||
}
|
||||
return words
|
||||
}
|
||||
func analyzeWords(tweets []twitter.Tweet) {
|
||||
func analyzeWords(tweets []twitter.Tweet) map[string]int {
|
||||
var words = make(map[string]int)
|
||||
|
||||
for _, v := range tweets {
|
||||
mapWords(v.Text, words)
|
||||
words = mapWords(v.Text, words)
|
||||
}
|
||||
|
||||
fmt.Println(len(words))
|
||||
//get sorted list of frequency words
|
||||
_ = sortMapWords(words)
|
||||
_ = printSortedMapStringInt(words, minNumWords)
|
||||
fmt.Println(" ")
|
||||
return words
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user