【发布时间】:2016-06-16 21:35:15
【问题描述】:
我正在尝试转换以下格式的边缘列表
data = [('a', 'developer'),
('b', 'tester'),
('b', 'developer'),
('c','developer'),
('c', 'architect')]
邻接矩阵的形式为
developer tester architect
a 1 0 0
b 1 1 0
c 1 0 1
我想将矩阵存储为以下格式
1 0 0
1 1 0
1 0 1
我已经用 GraphX 试过了
def pageHash(title:String ) = title.toLowerCase.replace(" ","").hashCode.toLong
val edges: RDD[Edge[String]] = sc.textFile("/user/query.csv").map { line =>
val row = line.split(",")
Edge(pageHash(row(0)), pageHash(row(1)), "1")
}
val graph: Graph[Int, String] = Graph.fromEdges(edges, defaultValue = 1)
我能够创建图形,但无法转换为相邻矩阵表示。
【问题讨论】:
标签: scala apache-spark