Created
September 26, 2013 07:31
-
-
Save timothyandrew/6710926 to your computer and use it in GitHub Desktop.
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
(ns antonyms.core | |
(:gen-class) | |
(:require [clj-http.client :as client])) | |
(use 'clojure.java.io) | |
(defn antonym-for | |
[word] | |
(let [api-key "8c1e369f560ac4b0acfff71c674b37d6" | |
server-url (str "http://words.bighugelabs.com/api/2/" api-key "/" word "/json") | |
response (client/get server-url {:as :json :throw-exceptions false})] | |
(get-in response [:body :noun :ant]))) | |
(defn process-file | |
"Call func once for with each line in filename" | |
[filename func] | |
(with-open [rdr (reader filename)] | |
(doseq [line (line-seq rdr)] | |
(func line)))) | |
(defn print-with-antonym | |
[word] | |
(let [antonym (antonym-for word)] | |
(if-not (nil? antonym) | |
(println (str word " " antonym))))) | |
(defn -main | |
[filename] | |
(process-file filename print-with-antonym)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment