Re: Clojure example code snippets

2011-05-19 Thread Ken Wesson
On Thu, May 19, 2011 at 5:47 PM, Andreas Kostler wrote: > Hi Armando, > I'm working on a Clojurej library for sentiment analysis which doesn't > contain everything you'd want for nlp but quite a nice subset of input > modules (plain text corpora, rss feeds, html, etc...), > tokenising/normalisin

Re: Clojure example code snippets

2011-05-19 Thread Andreas Kostler
Hi Armando, I'm working on a Clojurej library for sentiment analysis which doesn't contain everything you'd want for nlp but quite a nice subset of input modules (plain text corpora, rss feeds, html, etc...), tokenising/normalising filters (noise removal, porter stemmer, etc), distance/similarit

Re: Clojure example code snippets

2011-05-19 Thread Armando Blancas
Just in case I'll mention that Meikel's use of (with-open) will automatically close the reader. On May 19, 11:40 am, dokondr wrote: > On May 19, 6:52 pm, Meikel Brandmeyer wrote: > > > Hi, > > > something like the following should work. > > > (with-open [rdr (java.io.FileReader. "file.txt")] > >

Re: Clojure example code snippets

2011-05-19 Thread dokondr
On May 19, 6:52 pm, Meikel Brandmeyer wrote: > Hi, > > something like the following should work. > > (with-open [rdr (java.io.FileReader. "file.txt")] >   (doseq [line (line-seq rdr) >           word (.split line "\\s")] >     (when (.endsWith word "ing") >       (println word > > Sincerely >

Re: Aw: Clojure example code snippets

2011-05-19 Thread Benny Tsai
Oops. Just noticed that the original was not quoted in either of my previous emails, which makes things really confusing. My first reply (the one using read-lines) was an extension of odyssomay/Jonathan's code, and the second (with reader) was an extension of Meikel's code. Sorry guys. -- Y

Re: Aw: Clojure example code snippets

2011-05-19 Thread Benny Tsai
I think line-seq needs a java.io.BufferedReader instead of a java.io.FileReader. clojure.java.io has a reader function that constructs a java.io.BufferedReader from a filename, so this worked for me: (ns example (:use [clojure.java.io :only (reader)])) (with-open [rdr (reader "file.txt")]

Re: Clojure example code snippets

2011-05-19 Thread Benny Tsai
I think there can be multiple words on each line, so they have to be split into words first. Maybe something like: (ns example (:use [clojure.contrib.duck-streams :only (read-lines)])) (let [lines (read-lines "file.txt") words (mapcat #(.split % "\\s") lines) ing-words (filter (pa

Re: Clojure example code snippets

2011-05-19 Thread Jonathan Fischer Friberg
There is clojure.contrib.duck-streams/read-lines http://clojuredocs.org/clojure_contrib/clojure.contrib.duck-streams/read-lines Then it's a matter of (filter (partial re-matches #".*ing") (read-lines "/path/to/file")) Jonathan On Thu, May 19, 2011 at 4:52 PM, Meikel Brandmeyer wrote: > Hi, >

Aw: Clojure example code snippets

2011-05-19 Thread Meikel Brandmeyer
Hi, something like the following should work. (with-open [rdr (java.io.FileReader. "file.txt")] (doseq [line (line-seq rdr) word (.split line "\\s")] (when (.endsWith word "ing") (println word Sincerely Meikel -- You received this message because you are subscribed to

Clojure example code snippets

2011-05-19 Thread dokondr
Hi! I am thinking about using Clojure for distributed NLP. Being an absolute newbie in Clojure I look for nice expressive code snippets. For example, I need an easy way to read text files such as in the following Python code: >>> for line in open("file.txt"): ... for word in line.split(): ... if w