Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case class Continent(override val name: String) extends PlaceNode(name)
- val continents: RDD[(VertexId, PlaceNode)] =
- sc.textFile("./EOADATA/continent.csv").
- filter(! _.startsWith("#")).
- map {line =>
- val row = line split ','
- (200L + row(0).toInt, Continent(row(1))) // Add 200 to the VertexId to keep the indexes unique
- }
- val cclinks: RDD[Edge[Int]] =
- sc.textFile("./EOADATA/country_continent.csv").
- filter(! _.startsWith("#")).
- map {line =>
- val row = line split ','
- Edge(100L + row(0).toInt, 200L + row(1).toInt, 1)
- }
- val cnodes = metros ++ countries ++ continents
- val countriesGraph = Graph(cnodes, clinks)
- import org.graphstream.graph.implementations._
- val graph: SingleGraph = new SingleGraph("countriesGraph")
- graph.addAttribute("ui.stylesheet","url(file:.//style/stylesheet)")
- graph.addAttribute("ui.quality")
- graph.addAttribute("ui.antialias")
- for ((id:VertexId, place:PlaceNode) <- countriesGraph.vertices.collect())
- {
- val node = graph.addNode(id.toString).asInstanceOf[SingleNode]
- node.addAttribute("name", place.name)
- node.addAttribute("ui.label", place.name)
- if (place.isInstanceOf[Metro])
- node.addAttribute("ui.class", "metro")
- else if(place.isInstanceOf[Country])
- node.addAttribute("ui.class", "country")
- else if(place.isInstanceOf[Continent])
- node.addAttribute("ui.class", "continent")
- }
- for (Edge(x,y,_) <- countriesGraph.edges.collect()) {
- graph.addEdge(x.toString ++ y.toString, x.toString, y.toString, true).asInstanceOf[AbstractEdge]
- }
- graph.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement