diff --git a/src/clj/auto_ap/jobs/ntg.clj b/src/clj/auto_ap/jobs/ntg.clj index 789fc447..ef4613a0 100644 --- a/src/clj/auto_ap/jobs/ntg.clj +++ b/src/clj/auto_ap/jobs/ntg.clj @@ -68,8 +68,8 @@ (filter (fn [[_ _ _ _ _ _ _ _ _ _ _ break-flag]] (= "Y" break-flag))) (map (fn [[vendor location-hint invoice-number ship-date invoice-total ]] - (let [[matching-client similarity] (and location-hint - (parse/best-match clients location-hint 0.0))] + (let [matching-client (and location-hint + (parse/exact-match clients location-hint))] {:invoice/vendor vendor :invoice/location (parse/best-location-match matching-client location-hint location-hint ) :invoice/date (coerce/to-date (atime/parse ship-date atime/normal-date)) @@ -115,7 +115,7 @@ first :content first) - [matching-client similarity] (and location-hint (parse/best-match clients location-hint 0.0)) + matching-client (and location-hint (parse/exact-match clients location-hint)) ] (if matching-client diff --git a/src/clj/auto_ap/parse.clj b/src/clj/auto_ap/parse.clj index 1a5fe6f3..124d4752 100644 --- a/src/clj/auto_ap/parse.clj +++ b/src/clj/auto_ap/parse.clj @@ -121,6 +121,16 @@ first)] (or fuzzy-match client-word-match)))) +(defn exact-match + ([clients invoice-client-name] + (->> clients + (filter (fn [{:keys [:client/matches :client/name] :as client :or {matches []}}] + (seq + (filter (fn [m] + (= (.toLowerCase invoice-client-name) (.toLowerCase m))) + (conj matches name))))) + first))) + (defn best-location-match [client text full-text] (or (->> client :client/location-matches