
144
7 章 GraphX を使った共起ネットワークの分析
VertexRDD
にある頂点だけを返すことを思い出してください。そのため、共起している概念がない
概念は、取り除かれることになります。高い次数を持つトピック名を調べる関数を書いて、後から
再利用できるようにしておきましょう。
def topNamesAndDegrees(degrees: VertexRDD[Int],
topicGraph: Graph[String, Int]): Array[(String, Int)] = {
val namesAndDegrees = degrees.innerJoin(topicGraph.vertices) {
(topicId, degree, name) => (name, degree)
}
val ord = Ordering.by[(String, Int), Int](_._2)
namesAndDegrees.map(_._2).top(10)(ord)
}
namesAndDegrees VertexRDD
の上位
10
個の成分を次数の順に出力してみると、以下のようにな
りました。
topNamesAndDegrees(degrees, topicGraph).foreach(println)
...
(Research,3753)
(Child,2364)
(Toxicology,2019)
(Pharmacology,1891)
(Adolescent,1884)
(Pathology,1781) ...