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
(ns poalses.jonathan.dialect.dialect-nlp (ns poalses.jonathan.dialect.dialect-nlp
(:require [clojure.datafy :refer [datafy]] (:require [clojure.datafy :refer [datafy]]
[dk.simongray.datalinguist :as dl] [dk.simongray.datalinguist :as dl]
[dk.simongray.datalinguist.triple :refer [triple->datalog]]) [dk.simongray.datalinguist.triple :refer [triple->datalog]])
(:import [edu.stanford.nlp.coref CorefCoreAnnotations$CorefChainAnnotation])) (:import [edu.stanford.nlp.coref CorefCoreAnnotations$CorefChainAnnotation]))
...@@ -50,23 +50,27 @@ ...@@ -50,23 +50,27 @@
(def american-words #{"like"}) (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 ;; Take a sentence and figure out its dialect
(defn detect-sentence-dialect [sentence] (defn detect-sentence-dialect [sentence]
(let [tokens (dl/tokens sentence) (let [tokens (dl/tokens sentence)
dialects1 (when (some australian-words (dl/text tokens)) [:australian]) dialects1 (if (some australian-words (dl/text tokens)) :australian (when ((apply some-fn australian-predicates) sentence) :australian))
dialects2 (when (some scottish-words (dl/text tokens)) [:scottish]) dialects2 (if (some scottish-words (dl/text tokens)) :scottish (when ((apply some-fn scottish-predicates) sentence) :scottish))
dialects3 (when (some american-words (dl/text tokens)) [:american]) dialects3 (if (some american-words (dl/text tokens)) :american (when ((apply some-fn american-predicates) sentence) :american))
dialects (remove nil? (flatten (conj dialects1 dialects2 dialects3)))] dialects (remove nil? [dialects1 dialects2 dialects3])]
(if (empty? dialects) [:standard] dialects))) (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