Last active
July 30, 2018 19:25
-
-
Save msszczep/9ad519c9a3000eff58c8c533f80c85f2 to your computer and use it in GitHub Desktop.
Are You Polish? (in Clojure)
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
; 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