/
TwiSKO.rsc
50 lines (44 loc) · 1.58 KB
/
TwiSKO.rsc
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
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module TwiSKO
// TWItter to subatomic Scientific Knowledge Objects
import io::json::Parser;
import io::json::Access;
import io::json::ADT;
import io::date::AccessTwitterDate;
import IO; // println
import String; //startsWith, endsWith
import List; //size, reverse
public void main(list[str] as)
{
go();
}
public void go()
{
loc w = |home:///workspace/open/data/last1000.json|;
loc r = |home:///workspace/open/data/last1000.xml|;
w = |cwd:///grammarware.json|;
r = |cwd:///grammarware.xml|;
//loc w = |home:///workspace/open/data/one.json|;
list[JSO] tweets = gimmeArray(loc2jso(w));
list[str] res = reverse([s | str s <- [processTweet(gimmeMap(tweet)) | JSO tweet <- tweets], s!=""]);
//str res = ("" | it + processTweet(gimmeMap(tweet)) | JSO tweet <- gimmeArray(loc2jso(w)));
writeFile(r,(""|it+s|str s <- res));
println("<size(res)> entries created from <size(tweets)> tweets.");
}
str processTweet(map[str,JSO] t)
{
str txt = gimmeString(t["text"]);
if (startsWith(txt,"@") || startsWith(txt,"RT @"))
return "";
return "
'\<entry\>
' \<ts d=\"<t2day(t)>\" m=\"<t2month(t)>\" y=\"<t2year(t)>\" time=\"<t2time(t)>\"/\>
' \<text\><txt>\</text\>
' \<twi\><t2id(t)>\</twi\>
'\</entry\>";
}
str t2day(map[str,JSO] t) = gimmeDay(gimmeString(t["created_at"]));
str t2month(map[str,JSO] t) = gimmeMonth(gimmeString(t["created_at"]));
str t2year(map[str,JSO] t) = gimmeYear(gimmeString(t["created_at"]));
str t2time(map[str,JSO] t) = gimmeTime(gimmeString(t["created_at"]));
str t2id(map[str,JSO] t) = gimmeString(t["id_str"]);