Created
March 8, 2013 16:23
-
-
Save corecode/5117660 to your computer and use it in GitHub Desktop.
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 domlink-neo4j-import.core | |
(:require [clojure.contrib.duck-streams :as strms] | |
[clojure.string :as s]) | |
(:gen-class)) | |
(defn get-name-id | |
[name {:keys [names next-id] :as r :or {names {} next-id 1}}] | |
(let [id (names name)] | |
(if id | |
[id r] | |
(let [id next-id | |
next-id (inc next-id)] | |
[id {:hosts (assoc names name id) :next-id next-id}])))) | |
(defn -main | |
"Reads an input file with lines containing | |
from-name to-name num-count | |
and replaces names with unique ids. | |
XXX output id->name mapping in the end" | |
[& args] | |
(->> (strms/read-lines *in*) | |
(map #(s/split % #"\s+")) | |
(reduce | |
(fn [names [from to link-count]] | |
(let [[from-id names] (get-name-id from names) | |
[to-id names] (get-name-id to names)] | |
(println from-id to-id link-count) | |
names)) | |
{}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment