Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ネットワークグラフを作成する

kunou
July 06, 2018

 ネットワークグラフを作成する

kunou

July 06, 2018
Tweet

More Decks by kunou

Other Decks in Technology

Transcript

  1. ίʔυશମ (ns gen-network.core) (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as

    str]) (require '[loom.graph :as lg]) (require '[loom.io :as lio]) (def data-text “data.txt") (def keywords ["a" "b" "c" "d"]) (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", ")))) (defn word-relation [key list] (->> list (filter (fn [words] (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) (defn main [] (->> keywords (reduce (fn [accum keyword] (concat accum (word-relation keyword data-list))) []) )) ; (remove (fn [x] (<= (nth x 2) 4))) (apply lg/weighted-graph) ((fn [graph] (lio/view graph :alg :fdp))))) (main) ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  2. ϑΝΠϧΛಡΈࠐΉ $ cat data.txt a, b c, d a, b

    a, b a, b a, e c, d a, e a, d c, b e, d ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  3. ϑΝΠϧΛಡΈࠐΉ (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as str]) (def

    data-text "data.txt") (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", "))))
 
 ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  4. ϑΝΠϧΛಡΈࠐΉ (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as str]) (def

    data-text "data.txt") (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", "))))
 => ([“a” “b”] [“c” “d”] [“a” “b”] [“a” “b”] [“a” “b”] [“a” “e”] [“c” “d”] [“a” “e”] [“a” “d”] [“c” “b”] [“e" “d"]) ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  5. ϑΝΠϧΛಡΈࠐΉ (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as str]) (def

    data-text "data.txt") (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", "))))
 => ([“a” “b”] [“c” “d”] [“a” “b”] [“a” “b”] [“a” “b”] [“a” “e”] [“c” “d”] [“a” “e”] [“a” “d”] [“c” “b”] [“e" “d"]) ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ) JavaͷΫϥεΛΠϯϙʔτ
  6. ϑΝΠϧΛಡΈࠐΉ (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as str]) (def

    data-text "data.txt") (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", "))))
 => ([“a” “b”] [“c” “d”] [“a” “b”] [“a” “b”] [“a” “b”] [“a” “e”] [“c” “d”] [“a” “e”] [“a” “d”] [“c” “b”] [“e" “d"]) clojure.stringΛ࢖͑ΔΑ͏ʹ͢Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  7. ϑΝΠϧΛಡΈࠐΉ (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as str]) (def

    data-text "data.txt") (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", "))))
 => ([“a” “b”] [“c” “d”] [“a” “b”] [“a” “b”] [“a” “b”] [“a” “e”] [“c” “d”] [“a” “e”] [“a” “d”] [“c” “b”] [“e" “d"]) FileReaderΛॳظԽ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  8. ϑΝΠϧΛಡΈࠐΉ (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as str]) (def

    data-text "data.txt") (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", "))))
 => ([“a” “b”] [“c” “d”] [“a” “b”] [“a” “b”] [“a” “b”] [“a” “e”] [“c” “d”] [“a” “e”] [“a” “d”] [“c” “b”] [“e" “d"]) BuffReaderΛॳظԽ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  9. ϑΝΠϧΛಡΈࠐΉ (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as str]) (def

    data-text "data.txt") (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", "))))
 => ([“a” “b”] [“c” “d”] [“a” “b”] [“a” “b”] [“a” “b”] [“a” “e”] [“c” “d”] [“a” “e”] [“a” “d”] [“c” “b”] [“e" “d"]) ߦ͝ͱʹ෼͚Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  10. ϑΝΠϧΛಡΈࠐΉ (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as str]) (def

    data-text "data.txt") (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", "))))
 => ([“a” “b”] [“c” “d”] [“a” “b”] [“a” “b”] [“a” “b”] [“a” “e”] [“c” “d”] [“a” “e”] [“a” “d”] [“c” “b”] [“e" “d"]) ߦΛ``,``Ͱ෼͚ͯVectorʹ͢Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  11. ಡΈࠐΜͩ݁Ռ͔Β૊Έ߹Θͤճ਺Λ਺͑Δ (defn word-relation [key list] (->> list (filter (fn [words]

    (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  12. ಡΈࠐΜͩ݁Ռ͔Β૊Έ߹Θͤճ਺Λ਺͑Δ (defn word-relation [key list] (->> list (filter (fn [words]

    (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) (word-relation "a" data-list) => (["a" "b" 4] ["a" "e" 2] ["a" "d" 1]) ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  13. ಡΈࠐΜͩ݁Ռ͔Β૊Έ߹Θͤճ਺Λ਺͑Δ (defn word-relation [key list] (->> list (filter (fn [words]

    (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) => ([“a” “b”] [“c” “d”] [“a” “b”] [“a” “b”] [“a” “b”] [“a” “e”] [“c” “d”] [“a” “e”] [“a” “d”] [“c” “b”] [“e" “d"]) ͜͜·Ͱ࣮ߦ͢Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  14. ಡΈࠐΜͩ݁Ռ͔Β૊Έ߹Θͤճ਺Λ਺͑Δ (defn word-relation [key list] (->> list (filter (fn [words]

    (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) => (["a" "b"] ["a" "b"] ["a" "b"] ["a" "b"] ["a" "e"] ["a" "e"] ["a" "d"]) ͜͜·Ͱ࣮ߦ͢Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  15. ಡΈࠐΜͩ݁Ռ͔Β૊Έ߹Θͤճ਺Λ਺͑Δ (defn word-relation [key list] (->> list (filter (fn [words]

    (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) => (("b") ("b") ("b") ("b") ("e") ("e") ("d")) ͜͜·Ͱ࣮ߦ͢Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  16. ಡΈࠐΜͩ݁Ռ͔Β૊Έ߹Θͤճ਺Λ਺͑Δ (defn word-relation [key list] (->> list (filter (fn [words]

    (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) => ("b" "b" "b" "b" "e" "e" "d") ͜͜·Ͱ࣮ߦ͢Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  17. ಡΈࠐΜͩ݁Ռ͔Β૊Έ߹Θͤճ਺Λ਺͑Δ (defn word-relation [key list] (->> list (filter (fn [words]

    (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) => {"b" ["b" "b" "b" "b"], "e" ["e" "e"], "d" ["d"]} ͜͜·Ͱ࣮ߦ͢Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  18. ಡΈࠐΜͩ݁Ռ͔Β૊Έ߹Θͤճ਺Λ਺͑Δ (defn word-relation [key list] (->> list (filter (fn [words]

    (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) => (["a" "b" 4] ["a" "e" 2] ["a" "d" 1]) ͜͜·Ͱ࣮ߦ͢Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  19. ޙ͸ϥΠϒϥϦͷྗͰ (defn main [] (->> keywords (reduce (fn [accum keyword]

    (concat accum (word-relation keyword data-list))) []) ; (remove (fn [x] (<= (nth x 2) 4))) (apply lg/weighted-graph) ((fn [graph] (lio/view graph :alg :fdp))))) ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  20. ޙ͸ϥΠϒϥϦͷྗͰ (defn main [] (->> keywords (reduce (fn [accum keyword]

    (concat accum (word-relation keyword data-list))) []) ; (remove (fn [x] (<= (nth x 2) 4))) (apply lg/weighted-graph) ((fn [graph] (lio/view graph :alg :fdp))))) => (["a" "b" 4] ["a" "e" 2] ["a" "d" 1] [“b" "a" 4] ["b" "c" 1] ["c" "d" 2] ["c" "b" 1] [“d" "c" 2] ["d" "a" 1] ["d" "e" 1]) ͜͜·Ͱ࣮ߦ͢Δ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  21. ޙ͸ϥΠϒϥϦͷྗͰ (defn main [] (->> keywords (reduce (fn [accum keyword]

    (concat accum (word-relation keyword data-list))) []) ; (remove (fn [x] (<= (nth x 2) 4))) (apply lg/weighted-graph) ((fn [graph] (lio/view graph :alg :fdp))))) άϥϑσʔλΛ࡞੒ ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  22. ޙ͸ϥΠϒϥϦͷྗͰ (defn main [] (->> keywords (reduce (fn [accum keyword]

    (concat accum (word-relation keyword data-list))) []) ; (remove (fn [x] (<= (nth x 2) 4))) (apply lg/weighted-graph) ((fn [graph] (lio/view graph :alg :fdp))))) ഑ஔΛࢦఆͯ͠ඳը ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)
  23. ίʔυશମ (ns gen-network.core) (import '(java.io BufferedReader FileReader)) (require '[clojure.string :as

    str]) (require '[loom.graph :as lg]) (require '[loom.io :as lio]) (def data-text “data.txt") (def keywords ["a" "b" "c" "d"]) (def data-list (->> (FileReader. data-text) (BufferedReader.) (line-seq) (map #(str/split % #", ")))) (defn word-relation [key list] (->> list (filter (fn [words] (some #(= % key) words))) (map (fn [words] (remove #(= key %) words))) (flatten) (group-by #(identity %)) ((fn [group] (map #(vector key (first %) (count (second %))) group))))) (defn main [] (->> keywords (reduce (fn [accum keyword] (concat accum (word-relation keyword data-list))) []) )) ; (remove (fn [x] (<= (nth x 2) 4))) (apply lg/weighted-graph) ((fn [graph] (lio/view graph :alg :fdp))))) (main) ωοτϫʔΫάϥϑΛੜ੒͢Δ(ClojureͰ)