I want to keep a list of normalizing functions for a text. How do I store .toLowercase? I was thinking of something like this:
(def normalizing-functions (list remove-punctuations .toLowerCase))
I want to keep a list of normalizing functions for a text. How do I store .toLowercase? I was thinking of something like this:
(def normalizing-functions (list remove-punctuations .toLowerCase))
It looks like your making a list of functions to apply to something on a regular basis. the java method is not quite a clojure function in this sense though its really easy to wrap it up just like you would if you where going to feed it to the map function.
#(. tolowercase %)
Rather than keeping them in a list which you'll have to unpack some way later, it may just be easier to wrap .toLowerCase
in a clojure function (edit: using my or Arthur's syntax) and compose it with the functions you're planning to use to normalize your data using comp
:
user=> (defn remove-punctuation [st] ...removing puncutation mechanics...)
user=> (defn lower-case [st]
(.toLowerCase st))
user=> ((comp remove-punctuation lower-case) "HELLO THERE!")
"hello there"
user=> (defn normalize-data [data]
((comp remove-punctuation lower-case) data))
The memfn
macro will do this in a more readable way.
(def f (memfn toLowerCase))
(f "Hello")
would return "hello". (doc memfn)
has the details.