Revision: 25318
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 26, 2010 12:05 by PesPes
Initial Code
(ns parsing2 (:use clojure.contrib.str-utils) ;(:use com.ashafa.clutch) (:import java.io.File java.util.Date java.text.DateFormat jxl.Workbook jxl.Sheet jxl.Range jxl.Cell org.geonames.ToponymSearchCriteria org.geonames.ToponymSearchResult org.geonames.WebService org.jdom.input.SAXBuilder)) (defstruct flight :day :rf :aircraft :from :etd :to :eta) (defstruct map-point :name :country :latitude :longitude) (def *days* ["SUNDAY" "MONDAY" "TUESDAY" "WEDNESDAY" "THURSDAY" "FRIDAY" "SATURDAY"]) (def *curr-day* (atom "None")) (def *curr-rf* (atom "None")) (def *curr-aircraft* (atom "None")) (def *countries-ck* ["Sudan" "Uganda"]) (defn in-list? ) ;(geo-code "Khartoum" "AFRICA") (defn geo-code [loc area] (let [tsc (doto (ToponymSearchCriteria. ) (.setQ (str loc "," area)) (.setMaxRows 5)) result (WebService/search tsc)] (doseq [r (.getToponyms result)] (let [n (.getName r) c (.getCountryName r) lat (.getLatitude r) lon (.getLongitude r) m (some #{c} *countries-ck*)] (when m (let [s (struct map-point n m lat lon )] (prn s))))))) (defn get-rf-ac [flight] (let [rf (get flight :rf) ac (get flight :aircraft)] (when (> (.length rf) 0) (do (reset! *curr-rf* rf) (reset! *curr-aircraft* (.trim ac)) (prn *curr-rf* *curr-aircraft*))) (let [flt (assoc flight :rf (deref *curr-rf*) :aircraft (deref *curr-aircraft*))] (prn flt)))) (defn get-day [{from :from to :to :as flight}] (let [match (some (set *days*) (vals flight)) from-s (geo-code from "AFRICA") to-s (geo-code to "AFRICA")] (when (and from (> (.length from) 0)) (when match (reset! *curr-day* (.toUpperCase match))) (prn from-s) (get-rf-ac (assoc flight :day (deref *curr-day*) :to to-s :from from-s))))) (defn format-it [r] (let [[day rf aircraft from etd to eta] (map #(.getContents %) r)] (let [f (struct flight day rf aircraft from etd to eta)] (get-day f)))) ;;(parse-it "src/data/01_04_2009_UNMIS_1.xls") (defn parse-it [file] (let [wb (Workbook/getWorkbook (File. file))] (doseq [sheet (.getSheets wb)] (let [num-rows (range 0 (.getRows sheet))] (doseq [r num-rows] (let [row (.getRow sheet r)] (prn (format-it row))))))))
Initial URL
Initial Description
Initial Title
Parsing / Geocoding in Clojure
Initial Tags
Initial Language
Clojure