Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Are You Polish? (in Clojure)
; https://gist.github.com/Youenn-Bouglouan/02cd3ac6fd0130cc48b207eec6049af6
;
; http://www.ybouglouan.pl/2017/03/are-you-polish-fharp-will-tell-us-probably/
(defn are-you-polish? [surname]
(letfn [(score-polish-characters
[surname]
(->> (re-seq #"[ąćęłńóśżź]" surname)
count))
(score-polish-digraphs
[surname]
(->> (partition 2 1 surname)
(map (partial apply str))
(filter #{"ch" "cz" "dz" "dż" "dź" "rz" "sz"})
count
(* 3)))
(score-polish-ending
[surname]
(if (nil?
(re-find
#"wicz|czyk|wski|wska|ński|ńska|ski|ska|cki|cka|ło|ła|ak|rz$"
surname))
0 6))]
(let [final-score
(->> surname
clojure.string/lower-case
((juxt
score-polish-characters
score-polish-digraphs
score-polish-ending
count))
((juxt (comp (partial apply +) (partial take 3))
(comp float last)))
(apply /))
final-assessment
(cond (<= final-score 0.2) "Not Polish"
(>= final-score 0.8) "Definitely Polish"
:else "Probably Polish")]
(str final-score ", " final-assessment))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment