Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
coursera nlp pa1
;; Starter impl in clojure (use lein to create new project.clj)
(ns pa1.spamlord
:methods [[process [] java.util.List]]))
(defn extract-contacts [line]
(let [matches (re-seq #"(\w+)@(\w+)\.edu" line)
to-contact (fn [[_ name domain]]
{"type" "e"
"value" (str name "@" domain ".edu")})]
(map to-contact matches)))
(defn -process [this input]
(flatten (map extract-contacts (line-seq input)))))
// Modified to call clojure code
public List<Contact> processFile(String fileName, BufferedReader input) {
List<Contact> contacts = new ArrayList<Contact>();
// for each line
Matcher m;
String email;
try {
List results = new spamlord().process(input);
for(Object object : results) {
java.util.Map contact = (java.util.Map)object;
contacts.add(new Contact(fileName,
// for(String line = input.readLine(); line != null; line = input.readLine()) {
// m = myFirstPattern.matcher(line);
// while(m.find()) {
// email = + "@" + + ".edu";
// Contact contact = new Contact(fileName,"e",email);
// contacts.add(contact);
// }
// }
} catch(IOException e) {
return contacts;
//Compile & Run
//cd clj; lein compile; cd ..; javac -cp clj/classes/ -d java/classes/ java/*.java
//java -cp java/classes:clj/classes/:clj/lib/clojure-1.3.0.jar SpamLord data/dev/ data/devGOLD

This comment has been minimized.

Copy link
Owner Author

pedroteixeira commented Mar 11, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.