Commit 99155e50 authored by Jonathan Poalses's avatar Jonathan Poalses

changed the word predicates to be one of the predicates in the vectors rather than a separate check

parent f78d0f9a
...@@ -53,32 +53,29 @@ ...@@ -53,32 +53,29 @@
(def american-words #{"like"}) (def american-words #{"like"})
(def australian-word-predicate #(some australian-words (dl/text (dl/tokens %))))
(def scottish-word-predicate #(some scottish-words (dl/text (dl/tokens %))))
(def american-word-predicate #(some american-words (dl/text (dl/tokens %))))
(defn fake-test (defn fake-test
[fake] [fake]
false) false)
;; Predicate vectors to check a sentence and see if it grammatically matches a dialect ;; Predicate vectors to check a sentence and see if it grammatically matches a dialect
(def australian-predicates [fake-test]) (def australian-predicates [fake-test australian-word-predicate])
(def scottish-predicates [fake-test]) (def scottish-predicates [fake-test scottish-word-predicate])
(def american-predicates [fake-test]) (def american-predicates [fake-test american-word-predicate])
;; Take a sentence and figure out its dialect ;; Take a sentence and figure out its dialect
(defn detect-sentence-dialect [sentence] (defn detect-sentence-dialect [sentence]
(let [token-text (dl/text (dl/tokens sentence)) (let [dialects1 (when ((apply some-fn australian-predicates) sentence) :australian)
dialects1 (if (some australian-words token-text) dialects2 (when ((apply some-fn scottish-predicates) sentence) :scottish)
:australian dialects3 (when ((apply some-fn american-predicates) sentence) :american)
(when ((apply some-fn australian-predicates) sentence) :australian))
dialects2 (if (some scottish-words token-text)
:scottish
(when ((apply some-fn scottish-predicates) sentence) :scottish))
dialects3 (if (some american-words token-text)
:american
(when ((apply some-fn american-predicates) sentence) :american))
dialects (remove nil? [dialects1 dialects2 dialects3])] dialects (remove nil? [dialects1 dialects2 dialects3])]
(if (empty? dialects) (if (empty? dialects)
[:standard] [:standard]
......
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