如何成功安装ubergraph

问题描述 投票:0回答:1

首先我要说的是,我对clojure完全不熟悉,所以请原谅我,如果我错过了一些明显的东西。我最近在原子文本编辑器上安装了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
 [...])

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

clojure
1个回答
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时,找不到它所依赖的其中一个库,并且它投入了一个合适的版本。

© www.soinside.com 2019 - 2024. All rights reserved.