<commit_before>(ns vip.data-processor.output.xml-helpers
  (:require [clojure.string :as str]
            [korma.core :as korma])
  (:import [java.nio.file Files]
           [java.nio.file.attribute FileAttribute]))

(defn create-xml-file
  [{:keys [filename] :as ctx}]
  (let [base-filename (-> filename (str/split #" ") last)
        xml-file (Files/createTempFile
                  base-filename ".xml" (into-array FileAttribute []))]
    (-> ctx
        (assoc :xml-output-file xml-file)
        (update :to-be-cleaned conj xml-file))))

(defmacro xml-node [name]
  (let [tag (keyword name)]
    `{:tag ~tag :content [(str ~name)]}))

(defmacro boolean-xml-node [name]
  (let [tag (keyword name)]
    `{:tag ~tag :content [(condp = ~name
                            1 "yes"
                            0 "no"
                            nil)]}))

(defn empty-content? [c]
  (or (nil? c)
      (empty? (first (:content c)))))

(defn remove-empties [content]
  (remove empty-content? content))
<commit_msg>fix xml file output this time?<commit_after>(ns vip.data-processor.output.xml-helpers
  (:require [korma.core :as korma])
  (:import [java.nio.file Files]
           [java.nio.file.attribute FileAttribute]))

(defn create-xml-file
  [{:keys [import-id] :as ctx}]
  (let [xml-file (Files/createTempFile
                  import-id ".xml" (into-array FileAttribute []))]
    (-> ctx
        (assoc :xml-output-file xml-file)
        (update :to-be-cleaned conj xml-file))))

(defmacro xml-node [name]
  (let [tag (keyword name)]
    `{:tag ~tag :content [(str ~name)]}))

(defmacro boolean-xml-node [name]
  (let [tag (keyword name)]
    `{:tag ~tag :content [(condp = ~name
                            1 "yes"
                            0 "no"
                            nil)]}))

(defn empty-content? [c]
  (or (nil? c)
      (empty? (first (:content c)))))

(defn remove-empties [content]
  (remove empty-content? content))

{'fraction_non_alphanumeric': 0.16589147286821707, 'fraction_numerical': 0.0020671834625322996, 'mean_word_length': 2.2320534223706177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 19}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7650853', 'n_tokens_mistral': 660, 'n_tokens_neox': 644, 'n_words': 166}