(ns Trial
(:use queries)
(:import (java.io BufferedReader IOException InputStreamReader)
java.net.URL
javafiles.Porter))
;;
----------------------------------------------------------------------------
(def *server* "fiji4.ccs.neu.edu")
(def *lemur* (str "http://" *server* "/~zerg/lemurcgi/lemur.cgi?g=p"))
(def *query* "type of weather event")
;;
----------------------------------------------------------------------------
;; add v= in word
(defn addv= [a-word]
(str "&v=" a-word))
;; make a query
(defn make-query [address line]
(str address (apply str (map addv= (.split line " " )))))
;;
----------------------------------------------------------------------------
;; is there another way to do this?
;; buffer->string: StringBuffer -> String
(defn buffer->string [buffer]
(loop [line (.readLine buffer) sb (StringBuilder.)]
(if(nil? line)
(.toString sb)
(recur (.readLine buffer) (.append sb line)))))
;; fetch: URL-string -> String
;; fetch returns the string of the HTML url
;; the url is given as a string.
(defn fetch [url]
(let[stream (. (URL. url) openStream)]
(let [buffer (BufferedReader. (InputStreamReader. stream))]
buffer)))
;;
----------------------------------------------------------------------------
;; Strip removes all the html crap and puts the number in a String
Array
(defn strip [string]
(.split (first (.split (second (.split string "<BODY>")) "<HR>")) "
+"))
;;
----------------------------------------------------------------------------
;; Global References and Constants
;;
----------------------------------------------------------------------------
;; Database number 3 information
(def *db-total-documents* 84678)
(def *db-total-terms* 24401877)
(def *db-unique-terms* 166054)
(def *db-avg-doc-len* 288)
;;
----------------------------------------------------------------------------
;; I had to do this because the code kept crashing
(def *xxx* (fetch (make-query *lemur* *query*)))
(def *xxx* (buffer->string *xxx*))
(def *xxx* (rest (strip *xxx*)))
;;
---------------------------------------------------------------------------
Please help me retrieve this web page.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---