如何成功安装ubergraph

时间:2019-04-04 22:27:29

标签: clojure

首先我要说的是,我对Clojure完全陌生,所以如果我缺少明显的东西,请原谅我。 我最近在atom文本编辑器上安装了clojure软件包,以创建一些图形,并尝试添加ubergraph,该扩展使加权图形成为可能,因为标准clojure软件包不支持这些图形。

我遵循了ubergraphs github https://github.com/Engelberg/ubergraph上的快速入门指南,并设法完成了第一步(将ubergraph添加到leiningen依赖项)。我下载了git仓库,不知道如何从这里进行。运行示例代码

(ns example.core
  (:require [ubergraph.core :as uber]))

(def graph1
  (uber/graph [:a :b] [:a :c] [:b :d]))

在github上描述的repl上出现以下错误:

CompilerException java.lang.NullPointerException,编译:(ubergraph / core.clj:11:1)

似乎在core.clj中导致错误的行是:

(import-vars
 [...])

我跳过了变量,因为我不认为它们会导致问题。 Clojure在正确的版本(1.9.0)上运行,并安装了Java 8。感谢您的帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

根据您的评论“还需要将lib放置在特定位置吗?”,这似乎是由于对如何安装库的误解引起的。您不应该手动处理类似的事情; leiningen为您处理库安装。

这里是一个快速指南,假定您尚未创建项目。如果有,请跳至步骤2。

  1. 运行lein new app you-project-name-here。这将创建一个带有project.clj和基本文件结构的准系统项目。如果您使用像IntelliJ + Cursive这样的IDE,则创建新项目将自动执行此步骤。

  2. 进入您的project.clj,并将[ubergraph "0.5.2"]添加到:dependencies条目中。作为最小的简化示例,它应类似于:

    (defproject example "0.1.0-SNAPSHOT"
        :dependencies [[org.clojure/clojure "1.10.0"]
                       [ubergraph "0.5.2"]]
    
        :main example.core) ; The path to your core
    
  3. 将您的core设置为:

    (ns example.core
      (:require [ubergraph.core :as uber])
      (:gen-class))
    
    (def graph1
      (uber/graph [:a :b] [:a :c] [:b :d]))
    
    (defn -main
      "I don't do a whole lot ... yet."
      [& args]
      (println "The graph:" graph1))
    
  4. 现在运行lein run。您应该看到它下载了依赖项,然后打印出类似以下内容:

    The graph: {:node-map {:a #ubergraph.core.NodeInfo{:out-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :a, :dest :b, :mirror? false}}, :c #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :a, :dest :c, :mirror? false}}}, :in-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :b, :dest :a, :mirror? true}}, :c #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :c, :dest :a, :mirror? true}}}, :out-degree 2, :in-degree 2}, :b #ubergraph.core.NodeInfo{:out-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :b, :dest :a, :mirror? true}}, :d #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :b, :dest :d, :mirror? false}}}, :in-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :a, :dest :b, :mirror? false}}, :d #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :d, :dest :b, :mirror? true}}}, :out-degree 2, :in-degree 2}, :c #ubergraph.core.NodeInfo{:out-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :c, :dest :a, :mirror? true}}}, :in-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :a, :dest :c, :mirror? false}}}, :out-degree 1, :in-degree 1}, :d #ubergraph.core.NodeInfo{:out-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :d, :dest :b, :mirror? true}}}, :in-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :b, :dest :d, :mirror? false}}}, :out-degree 1, :in-degree 1}}, :allow-parallel? false, :undirected? true, :attrs {}, :cached-hash #object[clojure.lang.Atom 0x16da1abc {:status :ready, :val -1}]}
    

我怀疑NPE是因为您以某种方式安装了ubergraph,但不允许它自动解决其依赖性。当它尝试运行import-vals时,找不到它所依赖的库之一,因此很合适。