This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my-file-utils | |
(:import java.io.File)) | |
;; Java methods cannot be used as Clojure functions, | |
;; so you have to wrap them in functions. | |
;; anonymous function, map, and filter version | |
(defn list-files [d] | |
(map (fn [f] (.getName f)) | |
(filter (fn [f] (.isDirectory f)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def pattern_graph | |
[[0 1 0 1 1 1 0 1 0] | |
[1 0 1 1 1 1 1 0 1] | |
[0 1 0 1 1 1 0 1 0] | |
[1 1 1 0 1 0 1 1 1] | |
[1 1 1 1 0 1 1 1 1] | |
[1 1 1 0 1 0 1 1 1] | |
[0 1 0 1 1 1 0 1 0] | |
[1 0 1 1 1 1 1 0 1] | |
[0 1 0 1 1 1 0 1 0]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ignacio.tfidf (:require [clojure.contrib.string :as string])) ;; Simple tfidf in clojure, for fun. | |
(def *stopwords* (set (string/split #"\n" (slurp "./stopwords.txt")))) | |
(defn tokenize [raw-text] ;; Lowercases and splits on non-letters, non-numbers. | |
(remove *stopwords* (string/split #"[^a-z0-9äöüáéíóúãâêîôûàèìòùçñ]+" (string/lower-case raw-text)))) | |
(defn idf2 [n-docs match] (Math/pow (Math/log (/ n-docs (count (keys match)))) 2)) | |
(defn index-one [fname] ;; Index for one file. Given an fname, returns a map of token -> map of (fname, count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro create-object [name props funcs] | |
(let [m (reduce #(conj %1 [%2 nil]) {} props) | |
d (symbol (str "dispatcher-" name)) | |
msg-sym (gensym "msg") | |
params-sym (gensym "params")] | |
`(defn ~d [~msg-sym &~params-sym] | |
(cond | |
~@(for [f funcs] | |
[(= ~msg-sym ~(first f)) | |
(apply ~(second f) ~m ~params-sym)]))))) |