|
4 | 4 | [clojure.string :as str]
|
5 | 5 | [clojure.tools.logging :as log]
|
6 | 6 | [jsonista.core :as json]
|
7 |
| - [org.httpkit.client :as http]) |
| 7 | + [org.httpkit.client :as http] |
| 8 | + [utils.config :refer [config]] |
| 9 | + [mount.core :as mount]) |
8 | 10 | (:import (java.io File)
|
9 | 11 | (java.util UUID)))
|
10 | 12 |
|
|
15 | 17 | (doall (csv/read-csv reader))))
|
16 | 18 |
|
17 | 19 | (defn- post-generate [body]
|
18 |
| - @(http/request {:url "http://localhost:3001/nlg/_bulk/" |
| 20 | + @(http/request {:url (format "%s/nlg/_bulk/" (:api-url config)) |
19 | 21 | :method :post
|
20 | 22 | :headers {"Content-Type" "application/json"}
|
21 | 23 | :body (json/write-value-as-string body)}
|
|
25 | 27 | (log/error (.getMessage ^Throwable error))))))
|
26 | 28 |
|
27 | 29 | (defn- fetch-results [id]
|
28 |
| - @(http/request {:url (format "http://localhost:3001/nlg/%s?format=raw" id)} |
| 30 | + @(http/request {:url (format "%s/nlg/%s?format=raw" (:api-url config) id)} |
29 | 31 | (fn [{:keys [status body error]}]
|
30 | 32 | (cond
|
31 | 33 | (not= status 200) (log/errorf "Failed to fetch result `%s` with status %d" id status)
|
|
48 | 50 | [document-plan language data]
|
49 | 51 | (log/infof "Generating text for %s data items" (count data))
|
50 | 52 | (let [ids (take (count data) (repeatedly #(str (UUID/randomUUID))))
|
| 53 | + id->index (zipmap ids (range)) |
51 | 54 | id->data (zipmap ids data)]
|
52 | 55 | (->> {:documentPlanName document-plan
|
53 | 56 | :dataRows id->data
|
54 | 57 | :readerFlagValues {language true}}
|
55 | 58 | (post-generate)
|
56 | 59 | (map get-results)
|
| 60 | + (sort-by (fn [[id _]] (get id->index id))) |
57 | 61 | (map-indexed (fn [i [id variants]]
|
58 | 62 | (log/infof "%.2f%% ready" (float (* 100 (/ (inc i) (count ids)))))
|
59 | 63 | [(get id->data id) variants])))))
|
|
82 | 86 | (save-data-with-variants output-file results header)))
|
83 | 87 |
|
84 | 88 | (defn -main [& [document-plan data-path output-path language]]
|
| 89 | + (mount/start) |
85 | 90 | (if (and document-plan data-path output-path)
|
86 | 91 | (data->text document-plan (io/file data-path) (io/file output-path) (if-not (str/blank? language) language "Eng"))
|
87 | 92 | (println "Usage: pass in four parameters: name of the document plan, path to a data file, path to an output file, and language code")))
|
0 commit comments