Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (35 sloc) 906 Bytes
(ns wonderfulcoyote.gndrprdct
(:require [ultra-csv.core :as ucsv]
[clojure.string :as str])
(def SapWeights
(fn [a b] (assoc a (b :term) (b :weight)))
(ucsv/read-csv "./resources/gender_lex.csv")))
(defn predictgender
"Predict-tweet author gender from text. 0 is male, 1 is female"
(let [g
;; Take the sine
;; Subtract the intercept
(- 0.067242152
;; Sum them
(reduce +
;; Lookup values for each word
(map #(get SapWeights % 0)
;; Tokenization
(str/split (str/lower-case t) #"\s+")))))]
;; Assign appropriate gender
(if (<= g 0) 0 1))
(defn -main
"Tweet text expected as single user per line"
[& args]
(let [fp (first *command-line-args* )]
(with-open [rdr ( fp)]
(doseq [line (line-seq rdr)]
(println (predictgender line))
You can’t perform that action at this time.