42. UQ
The University of
Queensland
label
ANU
Australian National
University
label
Monash
affiliation
UMelbourne
affiliation
UNSW
affiliation
USydney
affiliation
UAdelaide
affiliation
Go8
memberOf
memberOf
memberOf
memberOf
memberOf
memberOf
memberOf
University of
Melbourne
label
Monash
University
label
University of
Adelaide
label
Group of 8
label
University of
Sydney
label
University
of NSW
label
45. Graphs in Scala
val graph: Graph[String, String] =
Graph(vertexRDD, edgeRDD)
// Create a subgraph based on the vertices connected
// by an "affiliation" property.
val affiliationRelatedSubgraph =
graph.subgraph(t => t.attr ==
"http://dbpedia.org/ontology/affiliation")
// Find connected components of affiliationRelatedSubgraph.
val ccGraph =
affiliationRelatedSubgraph.connectedComponents()
46. Graphs in Scala
// Create a hashmap of componentLists.
affiliationRelatedSubgraph.vertices.leftJoin
(ccGraph.vertices) {
case (id, u, comp) => comp.get
}.foreach { case (id, startingNode) =>
{
if (!(componentLists.contains(startingNode))) {
componentLists(startingNode) = new
ListBuffer[VertexId]
}
componentLists(startingNode) += id
}
}
47. Graphs in Scala
// Output a report on the connected components.
println("------ connected components in related triples ------
n")
for ((component, componentList) <- componentLists){
if (componentList.size > 1) {
for(c <- componentList) {
println(labelMap(c));
}
println("--------------------------")
}
}
48. ------ connected components in related triples ------
Australian National University
University of Sydney
University of Adelaide
University of New South Wales
--------------------------
The University of Queensland
University of Melbourne
Monash University
--------------------------