<commit_before>(ns ziad-example.core
  (:require [reagent.core :as r]
            [ziad.pos :as pos]
            [ziad.common :as common]))

(def init-sent "<NAME> went to there house.  She wanted to go to you're house.")

(defn by-id [id] (js/document.getElementById id))

(defn convert-sent [sent]
  (let [start-time (js/Date.now)
        tokens (pos/pos-tagger sent)
        total-time (- (js/Date.now) start-time)
        html-text (common/tokens->html tokens)]
    (js/console.log html-text)
    {:sentence sent
     :tokens tokens
     :html html-text
     :analysis-time total-time}))

(defonce state (r/atom (convert-sent init-sent)))

(defn analyze [event]
  (.preventDefault event)
  (let [input (.-value (by-id "input-text"))
        new-state (convert-sent input)]
    (reset! state new-state)))

(defn page []
  [:div
   [:div {:class "page-header"}
    [:h1 "Ziad " [:small "Grammar Checker and Part of Speech Tagger"]]
    [:div {:style {:position "absolute" :top "10px" :right "20px"}}
     [:a {:href "https://github.com/ckirkendall/ziad"} "GitHub Source"]]]
   [:form
    [:div [:textarea {:id "input-text" :class "form-control"
                      :rows 3 :defaultValue (:sentence @state)}]]
    [:div [:button {:class "btn btn-primary" :on-click analyze} "Analyze"]]]
   [:div {:class "results"}
    [:div {:class "panel panel-default"}
     [:div {:class "panel-heading"}
      [:strong "Analysis"]
      " - "
      (:analysis-time @state)
      " millseconds"]
     [:div {:class "panel-body" :dangerouslySetInnerHTML {:__html (:html @state)}}]]
    [:div {:class "panel panel-default"}
     [:div {:class "panel-heading"} [:strong "Tokens"]]
     [:div {:class "panel-body"}
      (let [tokens (:tokens @state)]
        (map (fn [cnt tok]
               ^{:key (str tok cnt)}
               [:span
                [:span {:class (common/token->class tok)}
                 (:tok tok)]
                "/" (:word tok) " "])
          (range (count tokens))
          tokens))]]]])


(r/render-component [page] (by-id "content"))
<commit_msg>added grammar threshold adjuster<commit_after>(ns ziad-example.core
  (:require [reagent.core :as r]
            [ziad.pos :as pos]
            [ziad.common :as common]))

(def init-sent "<NAME> went to there house.  She wanted to go to you're house.")

(defn by-id [id] (js/document.getElementById id))

(defn convert-sent [sent]
  (let [start-time (js/Date.now)
        tokens (pos/pos-tagger sent)
        total-time (- (js/Date.now) start-time)
        html-text (common/tokens->html tokens)]
    {:sentence sent
     :tokens tokens
     :html html-text
     :analysis-time total-time}))

(defonce state (r/atom (convert-sent init-sent)))

(defn analyze []
  (let [input (.-value (by-id "input-text"))
        new-state (convert-sent input)]
    (reset! state new-state)))

(defn update-sent [event]
  (.preventDefault event)
  (analyze))

(defn update-grammar-threshold [e]
  (js/console.log (.-target e))
  (let [value (.. e -currentTarget -value)]
    (reset! pos/grammar-threshold value)
    (analyze)))

(defn page []
  [:div
   [:div {:class "page-header"}
    [:h1 "Ziad " [:small "Grammar Checker and Part of Speech Tagger"]]
    [:div {:style {:position "absolute" :top "10px" :right "20px"}}
     [:a {:href "https://github.com/ckirkendall/ziad"} "GitHub Source"]]]
   [:form
    [:div [:textarea {:id "input-text" :class "form-control"
                      :rows 3 :defaultValue (:sentence @state)}]]
    [:div [:button {:class "btn btn-primary" :on-click update-sent} "Analyze"]]
    [:br]
    [:div {:class "form-group"}
     [:label "Grammar Threshold - " @pos/grammar-threshold ]
     [:input {:type "range"
              :style {:width 200}
              :defaultValue @pos/grammar-threshold
              :min (/ 1 1000000)
              :max (/ 1 25000)
              :step (/ 1 1000000)
              :on-change update-grammar-threshold}]]]
   [:div {:class "results"}
    [:div {:class "panel panel-default"}
     [:div {:class "panel-heading"}
      [:strong "Analysis"]
      " - "
      (:analysis-time @state)
      " millseconds"]
     [:div {:class "panel-body" :dangerouslySetInnerHTML {:__html (:html @state)}}]]
    [:div {:class "panel panel-default"}
     [:div {:class "panel-heading"} [:strong "Tokens"]]
     [:div {:class "panel-body"}
      (let [tokens (:tokens @state)]
        (map (fn [cnt tok]
               ^{:key (str tok cnt)}
               [:span
                [:span {:class (common/token->class tok)}
                 (:tok tok)]
                "/" (:word tok) " "])
          (range (count tokens))
          tokens))]]]])


(r/render-component [page] (by-id "content"))

{'fraction_non_alphanumeric': 0.1787007454739084, 'fraction_numerical': 0.007880724174653887, 'mean_word_length': 2.4529411764705884, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7467217', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1516, 'n_words': 424}