Commit 13733249 authored by Jonathan Poalses's avatar Jonathan Poalses

Improved detect-sentence-dialect, so it can take a vector of predicates, and...

Improved detect-sentence-dialect, so it can take a vector of predicates, and test the given sentence against them, returning once any of them give a truthy response
parent a9ba2fdc
......@@ -50,23 +50,27 @@
(def american-words #{"like"})
;; Predicate sets to check a sentence and see if it grammatically matches a dialect
(defn fake-test
[fake]
false)
(def australian-predicates #{})
;; Predicate vectors to check a sentence and see if it grammatically matches a dialect
(def scottish-predicates #{})
(def australian-predicates [fake-test])
(def american-predicates #{})
(def scottish-predicates [fake-test])
(def american-predicates [fake-test])
;; Take a sentence and figure out its dialect
(defn detect-sentence-dialect [sentence]
(let [tokens (dl/tokens sentence)
dialects1 (when (some australian-words (dl/text tokens)) [:australian])
dialects2 (when (some scottish-words (dl/text tokens)) [:scottish])
dialects3 (when (some american-words (dl/text tokens)) [:american])
dialects (remove nil? (flatten (conj dialects1 dialects2 dialects3)))]
dialects1 (if (some australian-words (dl/text tokens)) :australian (when ((apply some-fn australian-predicates) sentence) :australian))
dialects2 (if (some scottish-words (dl/text tokens)) :scottish (when ((apply some-fn scottish-predicates) sentence) :scottish))
dialects3 (if (some american-words (dl/text tokens)) :american (when ((apply some-fn american-predicates) sentence) :american))
dialects (remove nil? [dialects1 dialects2 dialects3])]
(if (empty? dialects) [:standard] dialects)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment