我在Graphx中有以下图表
graph.vertices.foreach(println)
(6109253945443866644,"Futurama"@en)
(7558506336564503178,"AccessibleComputing"@en)
(0,null)
(-2278222762001827643,"Programming languages"@en)
(-9007336571746445204,http://dbpedia.org/resource/Category:Presocratic_philosophers)
(-3236797006683951166,http://dbpedia.org/resource/Category:Programming_languages)
(-4159090027031366209,http://dbpedia.org/resource/Anaximenes_of_Miletus)
(7722304331424482609,http://dbpedia.org/resource/Category:Futurama)
(-323898215277667127,http://dbpedia.org/resource/AccessibleComputing)
我在此图上应用了连通分量算法,其输出如下: -
ccGraph.vertices.foreach(println)
(6109253945443866644,6109253945443866644)
(7558506336564503178,-323898215277667127)
(0,0)
(-2278222762001827643,-3236797006683951166)
(-9007336571746445204,-9007336571746445204)
(-3236797006683951166,-3236797006683951166)
(-4159090027031366209,-9007336571746445204)
(7722304331424482609,6109253945443866644)
(-323898215277667127,-323898215277667127)
我找不到在ccGraph中找到(vertexID,vertexID)顶点标签/顶点名称的方法,以便输出转换为
(vertexID,vertexID)=> (vertexLabel,vertexLabel)
我尝试了以下方法,但失败了
ccGraph.vertices.map({case arr =>
val k1 = graph.vertices.lookup(arr(0))
val k2 = graph.vertices.lookup(arr(1))
(k1,k2)
})
<console>:51: error: (org.apache.spark.graphx.VertexId, org.apache.spark.graphx.VertexId) does not take parameters
ccGraph.vertices.map({case arr => val k1 = graph1.vertices.lookup(arr(0))
^
<console>:52: error: (org.apache.spark.graphx.VertexId, org.apache.spark.graphx.VertexId) does not take parameters
val k2 = graph1.vertices.lookup(arr(1))
答案 0 :(得分:0)
连通分量算法生成一个新图形,其顶点值设置为组件ID。如果要获得原始值,则必须将它们与原始图形连接。
ccGraph.joinVertices(graph.vertices) { (id, component_id, old_value) =>
...
}