Skip to content

Instantly share code, notes, and snippets.

@corecode
Created March 8, 2013 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corecode/5117660 to your computer and use it in GitHub Desktop.
Save corecode/5117660 to your computer and use it in GitHub Desktop.
(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