-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalisisTweets.hs
140 lines (114 loc) · 3.71 KB
/
AnalisisTweets.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module AnalisisTweets
(
Tweets,
verTweets,
verRetweets,
tweetMasRT,
tweetMasMG,
idiomas
) where
import System.Exit
import System.Process
import ParsersArchivos
import TiposDatos
import System.Console.ANSI
import GHC.Generics
import Data.Aeson
import Data.Aeson.Types
import Data.List
import qualified Data.ByteString.Lazy as B
import Data.List (sortBy)
import Data.Function (on)
import Data.Maybe
test = verTweets "/home/andalu30/twitter-data/tweet.js"
test2 = verRetweets "/home/andalu30/twitter-data/tweet.js"
test3 = tweetMasRT "/home/andalu30/twitter-data/tweet.js"
test4 = tweetMasMG "/home/andalu30/twitter-data/tweet.js"
test5 = idiomas "/home/andalu30/twitter-data/tweet.js"
verTweets :: String -> IO()
verTweets path = do
clearScreen
let tweets = ParsersArchivos.parseTweets path
tweets <- tweets
let textos = map full_text tweets
let soloTweets = filter (\x -> not $ Data.List.isPrefixOf "RT" x) textos
let cantidad = length soloTweets
-- imprimeTextosTweets $ take 10 soloTweets
imprimeTextosTweets soloTweets
putStr "Se han publicado "
print cantidad
putStrLn" tweets, sin contar retweets"
imprimeTextosTweets :: [String] -> IO()
imprimeTextosTweets [] = putStrLn "" --Base
imprimeTextosTweets (x:ls) = do --Recursiva
putStr "\n->"
print x
imprimeTextosTweets ls
verRetweets :: String -> IO()
verRetweets path = do
clearScreen
let tweets = ParsersArchivos.parseTweets path
tweets <- tweets
let textos = map full_text tweets
let soloRetweets = filter (\x -> Data.List.isPrefixOf "RT" x) textos
let cantidad = length soloRetweets
-- imprimeTextosTweets $ take 10 soloRetweets
imprimeTextosTweets soloRetweets
putStr "Se han publicado "
print cantidad
putStrLn" retweets"
ordenaTuplasSND :: [(a, String)] -> [(a, String)]
ordenaTuplasSND = sortBy (flip compare `on` snd)
tweetMasRT :: String -> IO ()
tweetMasRT path = do
clearScreen
let tweets = ParsersArchivos.parseTweets path
tweets <- tweets
let textoyRts = map (\x -> (full_text x, retweet_count x)) tweets
let soloMios = filter (\x -> not $ Data.List.isPrefixOf "RT" (fst x)) textoyRts --Aunque no hace falta
let ordered = ordenaTuplasSND soloMios
let tweetMasRT = ordered !! 0
putStr "El tweet con mas retweets es: \n->"
print $ fst tweetMasRT
putStr" con "
print $ snd tweetMasRT
putStrLn" RTs"
tweetMasMG :: String -> IO ()
tweetMasMG path = do
clearScreen
let tweets = ParsersArchivos.parseTweets path
tweets <- tweets
let textoyMGS = map (\x -> (full_text x, favorite_count x)) tweets
let soloMios = filter (\x -> not $ Data.List.isPrefixOf "RT" (fst x)) textoyMGS
let ordered = ordenaTuplasSND soloMios
let tweetMasRT = ordered !! 0
putStr "El tweet con mas 'me gusta' es: \n->"
print $ fst tweetMasRT
putStr" con "
print $ snd tweetMasRT
putStrLn" 'me gusta'"
idiomas :: String -> IO ()
idiomas path = do
clearScreen
let tweets = ParsersArchivos.parseTweets path
tweets <- tweets
let textsAndLangs = map (\x -> (full_text x, lang x)) tweets
let soloMios = filter (\x -> not $ Data.List.isPrefixOf "RT" (fst x)) textsAndLangs
let ordered = ordenaTuplasSND soloMios
let langs = map (\x -> snd x) ordered
let groups = group langs
let ids = nub langs
let recuento = cuentaIdiomas groups []
let index = fromMaybe 0 (elemIndex (maximum recuento) recuento)
let maxLang = ids !! index
putStr "Se han utilizado todos idiomas que aparecen a continución.\n\t"
print ids
putStr "El idioma más utilizado en los tweets es:\n\t"
print maxLang
cuentaIdiomas :: Foldable t => [t a] -> [Int] -> [Int]
cuentaIdiomas [] ac = ac
cuentaIdiomas (x:xs) ac = do
let newac = ac ++ [(length x)]
cuentaIdiomas xs newac