Advertisement
Tooster

gremlin

Apr 18th, 2018
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.88 KB | None | 0 0
  1. > Find all direct connections between any airport in Poland and any airport in Germany. For each connection show the airports and the distance between them.
  2. g.V().has("country", "PL").as("a").bothE().as("edge").otherV().has("country", "DE").as("b").path().by("code").by("dist")
  3.  
  4. > Find all direct connections between any airport in Poland and any airport in Germany such that the distance between the airports is greater that 400 miles. For each connection show the airports and the distance between them.
  5. g.V().has("country", "PL").as("a").bothE().where(values("dist").is(gt(400))).as("edge").otherV().has("country", "DE").as("b").path().by("code").by("dist")
  6.  
  7. Find all direct connections between any airport in Poland that has a connection to Munich and any airport in Germany. For each connection show the airports and the distance between them.
  8. g.V().has("country", "PL").as("a").where(out().id().is(80)).bothE().as("edge").otherV().has("country", "DE").as("b").path().by("code").by("dist")
  9.  
  10. What are the airports in UK (United Kingdom) you can reach from Wrocław  with at most four stops? For each connection show all the airports including the intermediate ones.
  11. g.V().has("city", "Wroclaw").repeat(out()).emit().times(4).has("country", "UK").path().by("code")
  12.  
  13. > What are the airports in UK you can reach from Wrocław  with at most four stops within UK? For each connection show all the airports including the intermediate ones.
  14. g.V().has("city", "Wroclaw").repeat(out().has("country","UK")).emit().times(4).has("country", "UK").path().by("code")
  15.  
  16. > What are the codes of the airports in UK  you cannot reach from Wrocław with at most four stops. Hint:  e.g., you can use  - (minus) operator on lists.
  17. xs = []
  18. g.V().has("city", "Wroclaw").repeat(out()).emit().times(4).has("country", "UK").values("code").dedup().fill(xs)
  19. g.V().and(has("country", "UK"), has("code", without(xs))).values("code")
  20.  
  21. > For each polish airport return the numbers of incoming and outgoing direct connections. Sort the result w.r.t. the first number.
  22. def degree(g,s) {
  23.     v = g.V().has('code',s).next();
  24.     o=g.V(v).out().count().next();
  25.     i=g.V(v).in().count().next();
  26.     println s;
  27.     println "Edges in  : " + i;
  28.     println "Edges out : " + o;
  29.     println "Total     : " +(i+o);
  30. }
  31.  
  32. pl = []
  33. g.V().has("country", "PL").values("code").fill(pl)
  34. for (s in pl){degree(g,s);}
  35. sort...
  36.  
  37. > For each polish airport return the list of directly connected countries.
  38. def cont(g,s){
  39.     println s;
  40.     x = [];
  41.     g.V().has("code",s).out().values("country").dedup().fill(x);
  42.     println x;
  43. }
  44. for (s in pl){
  45.     cont(g,s);
  46. }
  47.  
  48. > Find ten European airports  that have the biggest number of outgoing direct connections. For each of them return the airport  code, city and the number of connections.
  49. g.V().has("code", "EU").out().as("airport").out().select("airport").groupCount().by("code").order(local).by(values, decr).limit(local, 10).select(keys).unfold()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement