This commit is contained in:
Bryce Covert
2020-04-18 07:19:28 -07:00

View File

@@ -4,7 +4,7 @@
[auto-ap.views.components.modal :refer [action-modal]]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.components.typeahead :refer [typeahead]]
[clj-fuzzy.metrics :refer [jaccard]]
[clj-fuzzy.metrics :refer [jaccard jaro-winkler]]
[clojure.spec.alpha :as s]
[clojure.string :as str]
[auto-ap.entities.vendors :as entity]
@@ -14,17 +14,19 @@
(mapv #(.toLowerCase (str/join "" %))
(partition len 1 text)))
(defn partial-matches-vendor? [text vendors]
(when (> (count text) 4)
(let [text (.toLowerCase text)]
(defn partial-matches-vendor? [vendor vendors]
(when (> (count (:name vendor)) 5)
(let [text (.toLowerCase (:name vendor))]
(->> vendors
(filter #(not= (:id %) (:id vendor)))
(map :name)
(mapcat
(fn [v] (mapv
(fn [n] [v (jaccard text n )])
(fn [n] [v (jaro-winkler text n ) n text])
(ngrams v (count text)))))
#_(sort-by second)
(filter #(< (second %) 0.3))
(filter #(> (second %) 0.9))
#_(map (fn [x] (doto x println)))
(map first)
first))))
@@ -40,7 +42,7 @@
(when (:error vendor)
[:span.icon.has-text-danger
[:i.fa.fa-exclamation-triangle]])]
:warning (when-let [vendor (partial-matches-vendor? (:name vendor) all-vendors)]
:warning (when-let [vendor (partial-matches-vendor? vendor all-vendors)]
(str "Are you sure you don't mean " vendor "?"))
:action-text "Save"
:save-event save-event
@@ -127,7 +129,6 @@
:subscription vendor}]]
[:span.icon.is-small.is-left
[:i.fa.fa-phone]]]]
[horizontal-field
[:label.label "Secondary"]
[:div.control.has-icons-left
@@ -157,7 +158,6 @@
:subscription vendor}]]
[:span.icon.is-small.is-left
[:i.fa.fa-phone]]]]
[horizontal-field
[:label.label "Invoice Reminders"]
[:div.control