;; Function to read a file and return its contents as a string
(defn read-file [filename]
  (slurp filename))

;; Function to split a string into a sequence of words
(defn split-words [text]
  (-> text
      (clojure.string/lower-case)   ; Convert to lowercase
      (re-seq #"\w+")               ; Split by non-word characters
      (filter #(> (.length %) 2)))) ; Filter out short words

;; Function to count the number of words in a sequence
(defn word-count [seq]
  (count seq))

;; Function to count the frequency of each word in a sequence
(defn get-word-frequency-map [seq]
  (reduce #(assoc %1 %2 (inc (%1 %2 0))) {} seq))

;; Function to perform sentiment analysis on a sequence of words
(defn sentiment-analysis [seq]
  (let [positive-words #{"good" "great" "awesome" "excellent" "fantastic"}
        negative-words #{"bad" "terrible" "awful" "horrible" "pathetic"}
        positive-count (count (filter #(positive-words %) seq))
        negative-count (count (filter #(negative-words %) seq))
        score (- positive-count negative-count)]
    (cond
      (> positive-count negative-count) "Positive"
      (< positive-count negative-count) "Negative"
      :else "Neutral")))

;; Function to display the results of text processing tasks
(defn display-results [text]
  (let [words (split-words text)
        word-count (word-count words)
        frequency-map (get-word-frequency-map words)
        sentiment (sentiment-analysis words)]
    (println "Total word count:" word-count)
    (println "Word frequency map:" frequency-map)
    (println "Sentiment analysis:" sentiment)))

;; Main function to read a file name and process the text
(defn -main []
  (let [filename (read-line "Enter filename: ")]
    (display-results (read-file filename))))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: