group 791 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Collapse all nodes with group = X into a single node */
  2. BEG_G {
  3. node_t metaN;
  4. graph_t g = graph ("metagraph", "S");
  5. $tvtype = TV_ne;
  6. $O = g;
  7. }
  8. /* create only one node with given name/value */
  9. N[group == "X"] {
  10. if (!metaN) {
  11. metaN = node (g, $.name);
  12. }
  13. }
  14. /* duplicate all others */
  15. N[group != "X"] { node (g, $.name); }
  16. /* Create an edge only if at least one of the nodes
  17. * is not a collapsed node */
  18. E {
  19. node_t t;
  20. node_t h;
  21. if ($.tail.group == "X") {
  22. if ($.head.group == "X") return;
  23. t = metaN;
  24. h = node (g, $.head.name);
  25. }
  26. else if ($.head.group == "X") {
  27. t = node (g, $.tail.name);
  28. h = metaN;
  29. }
  30. else {
  31. t = node (g, $.tail.name);
  32. h = node (g, $.head.name);
  33. }
  34. edge (t, h, "");
  35. }
  36. /* set g to be output graph */