Created
March 11, 2011 09:49
-
-
Save edwinschaap/865676 to your computer and use it in GitHub Desktop.
twitter skeleton excerise
This file contains 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
declare function fetch-tweets($keyword as xs:string) as node()* { | |
let $uri := "http://search.twitter.com/search.atom?geocode=52.1583,4.49306,200km&rpp=100&q=XXX" | |
return (: TODO replace XXX by keyword, fetch real entrys with doc() from uri :) | |
<entry><title>oops, I did it again</title><uri>http://twitter.com/britneyspears</uri><location>Hollywood</location></entry> | |
}; | |
declare function get-geo($placename as xs:string) as xs:string { | |
let $uri := (:replace XXX by placename :) | |
"http://where.yahooapis.com/v1/places.q("XXX");count=1?format=xml&appid=oWI.U034EMJO6CnsA4vFEvJ5oYEKsoD0qLIRfcoEKOLLTqv9bh6jBHZn9GhdRA--", | |
$centroid := | |
<centroid><latitude>52.33</latitude><longitude>4.86</longitude></centroid> (:TODO get 1st centroid :) | |
return "42,42" (: TODO use $centroid node to create a comma separated string of "latitude,longitude" :) | |
}; | |
declare function safe-geo($placename as xs:string) as xs:string { (: protect Yahoo against strange locations :) | |
let $safename := translate($placename,";:=+&{}[]<>!@#$%^*=+\/|'""," ()()()") | |
return if (contains($placename,":")) then substring-after($placename,":") else get-geo($safename) | |
}; | |
declare function order-tweets($keyword as xs:string) as node()* { | |
let $tweets := fetch-tweets($keyword), | |
$retweets := (), (: TODO select retweets from $tweets :) | |
$newtweets := () (: TODO group unique retweets keeping 1 example for each, ordering those by count descending :) | |
return ($newtweets, $tweets except $retweets) (: note the use of set operator "except" :) | |
}; | |
declare function get-tweets($keyword as xs:string) as node() { | |
<result keyword="{$keyword}">{ | |
let $tweets := order-tweets($keyword) (: TODO: restrict to the first 9 :) | |
for $tweet in $tweets | |
let (: TODO: get info from the $tweet rather than this bogus stuff :) | |
$geo := "52.334782,4.866480", | |
$uri := "http://twitter.com/britneyspears", | |
$txt := "oops, I did it again", | |
$nr := 1 (: TODO determine the tweet-nr where this location occurs first, in the $tweets sequence :) | |
return <tweet nr="{$nr}" geo="{$geo}" user="{$uri}" cnt="">{$txt}</tweet> | |
}</result> | |
}; | |
(: sequence of example queries :) | |
( | |
count(fetch-tweets("Rutte")), | |
count(order-tweets("Rutte")), | |
get-geo("Vrije Universiteit Amsterdam"), | |
get-tweets("Rutte") | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment