Created
March 8, 2013 16:48
-
-
Save corecode/5117884 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.string :as s]) | |
(:gen-class)) | |
(defn get-name-id | |
[name-str {:keys [names next-id] :as r :or {names {} next-id 1}}] | |
(let [id (names name-str)] | |
(if id | |
[id r] | |
(let [id next-id | |
next-id (inc next-id)] | |
[id {:names (assoc names name-str 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" | |
[inname] | |
(with-open [inf (clojure.java.io/reader inname)] | |
(->> (line-seq inf) | |
(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