Supports importing mama lu
This commit is contained in:
@@ -1,31 +1,16 @@
|
||||
(ns auto-ap.parse
|
||||
(:require [auto-ap.parse.excel :as excel]
|
||||
[auto-ap.parse.templates :as t]
|
||||
[auto-ap.parse.util :as u]
|
||||
[auto-ap.parse.csv :as csv]
|
||||
[clj-fuzzy.metrics :as m]
|
||||
[clojure.java.shell :as sh]
|
||||
[clojure.string :as str]
|
||||
[clj-time.format :as f]
|
||||
[clj-time.core :as time]))
|
||||
[clj-time.core :as time]
|
||||
[clojure.set :as set]))
|
||||
|
||||
|
||||
(defmulti parse-value (fn [method _ _]
|
||||
method))
|
||||
|
||||
|
||||
(defmethod parse-value :trim-commas
|
||||
[_ _ value]
|
||||
(str/replace value #"," "")
|
||||
)
|
||||
|
||||
(defmethod parse-value :clj-time
|
||||
[_ format value]
|
||||
(time/from-time-zone (f/parse (f/formatter format) value)
|
||||
(time/time-zone-for-id "America/Los_Angeles")))
|
||||
|
||||
(defmethod parse-value nil
|
||||
[_ _ value]
|
||||
value)
|
||||
|
||||
(def last-text (atom nil))
|
||||
|
||||
|
||||
@@ -46,7 +31,7 @@
|
||||
(let [value (some-> (first (map second (re-seq v text)))
|
||||
str/trim )
|
||||
[value-parser parser-params] (-> template :parser k)]
|
||||
(assoc result k (parse-value value-parser parser-params value))))
|
||||
(assoc result k (u/parse-value value-parser parser-params value))))
|
||||
{:vendor-code (:vendor template)
|
||||
:text text}))])))
|
||||
|
||||
@@ -67,6 +52,11 @@
|
||||
:out
|
||||
parse))
|
||||
|
||||
(defmethod parse-file
|
||||
"csv"
|
||||
[file filename]
|
||||
(csv/parse-file file filename))
|
||||
|
||||
(defmethod parse-file
|
||||
"xls"
|
||||
[file filename]
|
||||
@@ -79,15 +69,32 @@
|
||||
(excel/parse-file file filename))
|
||||
|
||||
(defn best-match [clients invoice-client-name]
|
||||
(->> clients
|
||||
|
||||
(mapcat (fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}]
|
||||
(map (fn [m]
|
||||
[client (m/jaccard (.toLowerCase invoice-client-name) (.toLowerCase m))])
|
||||
(conj matches name))))
|
||||
(filter #(< (second %) 0.25))
|
||||
(sort-by second)
|
||||
ffirst))
|
||||
(let [fuzzy-match (->> clients
|
||||
(mapcat (fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}]
|
||||
(map (fn [m]
|
||||
[client (m/jaccard (.toLowerCase invoice-client-name) (.toLowerCase m))])
|
||||
(conj matches name))))
|
||||
(filter #(< (second %) 0.25))
|
||||
(sort-by second)
|
||||
ffirst)
|
||||
|
||||
word-set (set (str/split (.toLowerCase invoice-client-name) #"\s" ))
|
||||
client-word-match (->> clients
|
||||
(map
|
||||
(fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}]
|
||||
(let [client-words (-> #{}
|
||||
(into
|
||||
(mapcat
|
||||
(fn [match] (str/split (.toLowerCase match) #"\s" ))
|
||||
matches))
|
||||
(into
|
||||
(str/split (.toLowerCase name) #"\s" )))]
|
||||
[client (count (set/intersection client-words word-set))])))
|
||||
(filter (fn [[_ c]] (> c 0)))
|
||||
(sort-by (fn [[_ c]] c))
|
||||
reverse
|
||||
ffirst)]
|
||||
(or fuzzy-match client-word-match)))
|
||||
|
||||
(defn best-location-match [client text]
|
||||
(or (->> client
|
||||
|
||||
Reference in New Issue
Block a user