4

I've been playing around with Mathematica's visualization and webcrawling capabilities. Building on some demonstration code, I'm able to visualize the a network. Here's an example on a university webpage:

webcrawler[rooturl_, depth_] :=
  Flatten[Rest[NestList[
       Union[Flatten[Thread[# -> Import[#,"Hyperlinks"]] & /@ Last /@ #]] &, 
       {"" -> rooturl}, depth]]];

Graph[webcrawler[
  "http://www.yorku.ca/", 2], {ImageSize -> Full}]

However, I've been trying fruitlessly to figure out a way to apply EdgeLabels[] to this Graph[] command. I would like to have each link written on each line, just to give a sense of what exactly the link clusters represent.

I've tried applying a generated list of the Hyperlink connections to it, which didn't work, and neither did any of the readily obvious commands from documentation/elsewhere on stack/the cookbook.

I envision a very cluttered output.

rcollyer
  • 10,475
  • 4
  • 48
  • 75
canadian_scholar
  • 1,315
  • 12
  • 26
  • Your code was missing a leading `{`, and I'm not sure if I got it right. So, please check it. – rcollyer Oct 12 '11 at 16:11
  • I ran your code (with @rcollyer mods) and your graph is so cluttered that I doubt any labeling will be useful. – Dr. belisarius Oct 12 '11 at 16:52
  • @rcollyer It is working on my system now.. my apologies, I must have messed it up when pasting it into the system. Thank you for catching the error. – canadian_scholar Oct 12 '11 at 18:12
  • @belisarius It is quite cluttered, but helpful for my specific application. But certainly a very important and helpful proviso to raise in case anybody else wants to go down this crazy road... – canadian_scholar Oct 12 '11 at 18:26
  • @ian I guess a meaningful mapping for a web site requires other approaches – Dr. belisarius Oct 12 '11 at 18:32

2 Answers2

6

I don't know in case of a large graph how will the edge label look. But here how it can be done in Mathematica 8.

webcrawler[rooturl_, depth_] := 
Flatten[Rest[
NestList[
 Union[Flatten[
    Thread[# -> Import[#, "Hyperlinks"]] & /@ 
     Last /@ #]] &, {"" -> rooturl}, depth]]];
dats = webcrawler["http://www.uni-kl.de/", 2];
Graph[dats ,EdgeLabels ->Table[dats[[i]] -> dats[[i]][[2]],
{i,Length[dats]}], {ImageSize -> Full}]

enter image description here I hope this helps.

BR

PlatoManiac
  • 1,442
  • 11
  • 31
6

Place EdgeLabels inside Tooltips

The following will display the names of both the edges and the vertices as tooltips. (You can remove the VertexLabels, of course. I included them because the EdgeLabels were often very long.)

data = webcrawler["http://www.yorku.ca/", 2];
Graph[data,
   EdgeLabels -> Placed["Name", Tooltip],
   EdgeShapeFunction -> "Line",
   VertexLabels -> Placed["Name", Tooltip], 
   EdgeStyle -> {Orange},
   VertexSize -> {"Scaled", 0.007},
   ImageSize -> 800]

It should be helpful for browsing the network. But of course, it will not print out the labels.

DavidC
  • 3,056
  • 1
  • 20
  • 30
  • `EdgeLabels -> Placed["Name", Tooltip]` is an alternative to displaying all the edge labels on screen at once. – DavidC Oct 12 '11 at 18:55
  • This is a very helpful alternative - great! – canadian_scholar Oct 12 '11 at 19:11
  • I thought of using Tooltips too. My implementation used Graph[Tooltip[#, #[[2]]] & /@ data]. Didn't know about this `Placed` alternative. – Sjoerd C. de Vries Oct 12 '11 at 19:31
  • @SjoerdC.deVries As of version 8, there are lots of little goodies waiting to be used with Graphs. I wanted to make a window into the network using NeighborhoodGraph, but found that a little too complicated. – DavidC Oct 12 '11 at 20:08
  • @Belisarius Nice. And strikingly familiar. But for some reason the popup window for edges is always empty. (BTW, my problem with NeighborhoodGraph was peculiar to the `webcrawler` data: for some reason mma would not return a graph when I used the data about URL's. Not sure why. – DavidC Oct 13 '11 at 10:59