【发布时间】:2017-10-30 21:00:25
【问题描述】:
我的代码应该读取 4 列,将它们拆分为前 2 列的顶点和最后两列的边缘属性。CSV 文件在 37 行数据中具有 33 个唯一顶点。我不明白为什么我得到 74 个顶点和 37 个边。有趣的是,如果我省略 addE 语句,我只会得到 37 个顶点。
显然,由于我一直在尝试解决当前的问题,因此未包括属性部分。
1\t2\tstep\tcmp
2\t3\tconductor\tna
3\t4\tswitch\tZ300
\t 用于制表符 等等
我的代码是:
graph = TinkerGraph.open()
graph.createIndex('myId', Vertex.class)
g = graph.traversal()
getOrCreate = { myid ->
p = g.V('myId', myid)
if (!p.hasNext())
{g.addV('connector').property('myId',myid) }
else
{p.next()}
}
new File('Continuity.txt').eachLine {
if (!it.startsWith("#")){
def row = it .split('\t')
def fromVertex = getOrCreate(row[0])
def toVertex = getOrCreate(row[1])
g.addE("connection").from(fromVertex).to(toVertex).iterate()
}
}
【问题讨论】:
标签: gremlin