south bay produce.

This commit is contained in:
Bryce Covert
2019-10-24 20:16:28 -07:00
parent 84e202bab9
commit aa90c1b4c1
4 changed files with 44 additions and 21 deletions

View File

@@ -17,23 +17,30 @@
(defn template-applies? [text {:keys [keywords]}]
(every? #(re-find % text) keywords))
(defn extract-template [text template]
(if (:multi template)
(mapcat
#(extract-template % (dissoc template :multi))
(str/split text (:multi template)))
(defn extract-template
([text template]
(if (:multi template)
(mapcat
#(extract-template % text (dissoc template :multi))
(str/split text (:multi template)))
(when template
[(->> template
:extract
(reduce-kv
(fn [result k v]
(let [value (some-> (first (map second (re-seq v text)))
str/trim )
[value-parser parser-params] (-> template :parser k)]
(assoc result k (u/parse-value value-parser parser-params value))))
{:vendor-code (:vendor template)
:text text}))])))
(extract-template text text template)))
([text full-text template]
(when (and template
(or (not (:multi-match? template))
(re-find (:multi-match? template) text )))
[(->> template
:extract
(reduce-kv
(fn [result k v]
(let [value (some-> (or (first (map second (re-seq v text)))
(first (map second (re-seq v full-text))))
str/trim )
[value-parser parser-params] (-> template :parser k)]
(assoc result k (u/parse-value value-parser parser-params value))))
{:vendor-code (:vendor template)
:text text
:full-text full-text}))])))
(defn parse [text]
(reset! last-text text)
@@ -96,7 +103,7 @@
ffirst)]
(or fuzzy-match client-word-match)))
(defn best-location-match [client text]
(defn best-location-match [client text full-text]
(or (->> client
:client/location-matches
(mapcat (fn [{:keys [:location-match/location :location-match/matches]}]
@@ -104,5 +111,12 @@
(filter (fn [[location match]] (re-find (re-pattern (str "(?i)" match)) text)) )
first
first)
(->> client
:client/location-matches
(mapcat (fn [{:keys [:location-match/location :location-match/matches]}]
(map (fn [match] [location match]) matches)))
(filter (fn [[location match]] (re-find (re-pattern (str "(?i)" match)) full-text)) )
first
first)
(:client/default-location client)
(first (:client/locations client))))