Improve line endings
This commit is contained in:
parent
c3966a1098
commit
f243aea8c4
2 changed files with 13 additions and 4 deletions
|
|
@ -28,7 +28,7 @@
|
||||||
(loop [phrase (vec start)]
|
(loop [phrase (vec start)]
|
||||||
(let [next-word (rand-nth (get markov-chain (take-last (count start) phrase)))
|
(let [next-word (rand-nth (get markov-chain (take-last (count start) phrase)))
|
||||||
next-phrase (conj phrase next-word)]
|
next-phrase (conj phrase next-word)]
|
||||||
(if (should-end? next-word)
|
(if (should-end? next-phrase)
|
||||||
next-phrase
|
next-phrase
|
||||||
(recur next-phrase)))))
|
(recur next-phrase)))))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,19 @@
|
||||||
(defn read-corpus [files]
|
(defn read-corpus [files]
|
||||||
(flatten (for [file files]
|
(flatten (for [file files]
|
||||||
(-> (slurp file)
|
(-> (slurp file)
|
||||||
(str/replace #"\"" "")
|
(str/replace #"[^\sa-zA-ZäöüÄÖÜß',.:!?]" "")
|
||||||
(str/split #"\s+")))))
|
(str/split #"\s+")))))
|
||||||
|
|
||||||
(def sentence-ending? #(some? (re-find #"[.?!]$" %)))
|
(defn sentence-ending? [words]
|
||||||
|
(let [last-word (last words)
|
||||||
|
second-to-last (last (butlast words))]
|
||||||
|
(and
|
||||||
|
(re-find #"[.?!]$" last-word)
|
||||||
|
(or
|
||||||
|
(not (#{"Mr." "Mrs."} last-word))
|
||||||
|
;; if it ends with a title, the title needs an article before that
|
||||||
|
(and (#{"Mr." "Mrs."} last-word)
|
||||||
|
(not (#{"the" "a"} second-to-last)))))))
|
||||||
|
|
||||||
(defn sentence-start? [state]
|
(defn sentence-start? [state]
|
||||||
(some? (re-find #"^[A-Z]" (first state))))
|
(some? (re-find #"^[A-Z]" (first state))))
|
||||||
|
|
@ -78,7 +87,7 @@
|
||||||
{:exit-message (error-message errors)}
|
{:exit-message (error-message errors)}
|
||||||
|
|
||||||
(> (count arguments) 0)
|
(> (count arguments) 0)
|
||||||
{:corpus arguments :order (:order options) :interval (:interval options)}
|
(merge options {:corpus arguments})
|
||||||
|
|
||||||
:else
|
:else
|
||||||
{:exit-message (usage summary)})))
|
{:exit-message (usage summary)})))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue