Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.56 KB | None | 0 0
  1. case class Continent(override val name: String) extends PlaceNode(name)
  2. val continents: RDD[(VertexId, PlaceNode)] =
  3.   sc.textFile("./EOADATA/continent.csv").
  4.     filter(! _.startsWith("#")).
  5.     map {line =>
  6.       val row = line split ','
  7.       (200L + row(0).toInt, Continent(row(1))) // Add 200 to the VertexId to keep the indexes unique
  8.     }
  9.  
  10. val cclinks: RDD[Edge[Int]] =
  11.   sc.textFile("./EOADATA/country_continent.csv").
  12.     filter(! _.startsWith("#")).
  13.     map {line =>
  14.       val row = line split ','
  15.       Edge(100L + row(0).toInt, 200L + row(1).toInt, 1)
  16.     }
  17. val cnodes = metros ++ countries ++ continents
  18. val countriesGraph = Graph(cnodes, clinks)
  19.  
  20. import org.graphstream.graph.implementations._
  21.  
  22. val graph: SingleGraph = new SingleGraph("countriesGraph")
  23.  
  24. graph.addAttribute("ui.stylesheet","url(file:.//style/stylesheet)")
  25. graph.addAttribute("ui.quality")
  26. graph.addAttribute("ui.antialias")
  27. for ((id:VertexId, place:PlaceNode) <- countriesGraph.vertices.collect())
  28. {
  29.   val node = graph.addNode(id.toString).asInstanceOf[SingleNode]
  30.   node.addAttribute("name", place.name)
  31.   node.addAttribute("ui.label", place.name)
  32.  
  33.   if (place.isInstanceOf[Metro])
  34.     node.addAttribute("ui.class", "metro")
  35.   else if(place.isInstanceOf[Country])
  36.     node.addAttribute("ui.class", "country")
  37.   else if(place.isInstanceOf[Continent])
  38.     node.addAttribute("ui.class", "continent")
  39. }
  40. for (Edge(x,y,_) <- countriesGraph.edges.collect()) {
  41.   graph.addEdge(x.toString ++ y.toString, x.toString, y.toString, true).asInstanceOf[AbstractEdge]
  42. }
  43. graph.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement