Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On the very last image below you can see a typical path of walking through Documentation Center guide pages. What is the best way to get the graph data and visualize the whole structure of these connections starting from the main table of contents page? An obvious thing to do is to look for example into directory:

SetDirectory["C:\\Program Files\\Wolfram\\Research

FileNames[] // Column

enter image description here

But I am not sure what is the next most efficient way to analyze the connections.

A walk through guide pages

enter image description here

------------ UPDATE: new built-in WolframLanguageData ------------

I posted an answer in connection with newly released functionality - WL now contains data about itself.

------------ UPDATE: image from @Leoind data ------------

style = {VertexStyle -> White, VertexShapeFunction -> "Point", 
  EdgeStyle -> Directive[Opacity[.3], Hue[.15, .5, .8]], 
  Background -> Black, EdgeShapeFunction -> (Line[#1] &), 
  ImageSize -> 500};

gr = Graph[Union[Sort /@ data], style]

enter image description here

The origin of self-loops was explained by @R.M in his comment. Almost all guide pages have their own URL at the top navigation bar. Here is the final graph with removed self-loops:

am = AdjacencyMatrix[gr];(am[[#, #]] = 0) & /@ Range[Length[am]];
AdjacencyGraph[am, style]

enter image description here

share|improve this question
Looks like pretty much every guidebook is a self loop to itself. It must be from the navigator link at the very top (just below the search bar), showing the current tree. You can find these with s1 = DeleteDuplicates@Cases[data, HoldPattern[x_ -> x_] :> x]. There are a few without any self-loops and these are ones without a top navigation link. These can be found with s2 = DeleteDuplicates@ Flatten@Cases[data, HoldPattern[x_ -> _] | HoldPattern[_ -> x_] :> x]; Complement[s2, Intersection[s1, s2]]. Looking at a sample guide from each of these lists should make it clear – R. M. Aug 1 '12 at 7:42
@R.M You are right! +1 Update the post, thanks. – Vitaliy Kaurov Aug 1 '12 at 7:56
up vote 16 down vote accepted

I will answer the technical part of the question - namely, how to get the entire graph. How one would go about analyzing and visualizing it, is another story.

This will open and parse a given guide notebook, and get the links to other notebooks:

getLinks[file_] :=
  With[{nb = NotebookOpen[file]},
    With[{result = 
        Cases[NotebookGet[nb], (ButtonData -> ref_) :> ref, Infinity]},

This will filter out links to guides only:

getGuideLinks[links_List] :=
   Cases[links, l_String /; StringMatchQ[l, "paclet:guide" ~~ __]];

This extracts a name from the link:

nameFromLink[link_String] :=
   If[# === {}, Sequence @@ {}, First@#] &@
      StringCases[link, "paclet:guide/" ~~ x__ :> x];

This gets the names of all guides linked from a given one:

getLinkedGuideNames[guidefile_String] :=
    Map[nameFromLink, getGuideLinks@getLinks@guidefile];

This constructs a list of graph rules from a list of files with guides:

getGraphRules[guideFiles : {__String}] :=
     Thread[FileBaseName[#] -> getLinkedGuideNames[#]] & /@ 

Here is a list of guides:

guides = 
   "C:\\Program Files\\Wolfram Research\\Mathematica\\

You can now, if you wish, construct a graph as follows:

Graph[Union[getGraphRules[guides]] /. Rule -> DirectedEdge]

but it is a huge graph which visually is not easy to analyze. One obviously needs to analyze it more locally by inducing subgraphs etc.

For convenience of anyone who would like to play with this, I placed the rules obtained with the above code into this gist.

share|improve this answer
+1 Thank you, very consistent. I built an image on this and added to my question. I wonder where the self loops are coming from. – Vitaliy Kaurov Aug 1 '12 at 6:58
Thanks, @Vitaliy, glad I could help. – Leonid Shifrin Aug 1 '12 at 8:32

Using this webcrawler code from Wolfram site, and Guides page in online docs as the starting url:

webcrawler[rooturl_, depth_] := Flatten[Rest[NestList[Union[Flatten[Thread[# -> Import[#, "Hyperlinks"]] & /@ Last /@ #]] &, {"" -> rooturl}, depth]]];
style = {VertexStyle -> White, VertexShapeFunction -> "Point", 
 EdgeStyle -> Directive[Opacity[.5], Hue[.15, .5, .8]], 
 Background -> Black, EdgeShapeFunction -> (Line[#1] &), ImageSize -> 500};
g=Graph[webcrawler["",  2], style];
Graph[VertexList[g], Tooltip /@ EdgeList[g], style]

enter image description here

share|improve this answer
+1 for the purty image. – CHM Jul 20 '12 at 0:53
+1 Neat outside the box idea ;-) – Vitaliy Kaurov Aug 1 '12 at 6:56

The notebook DocumentationNavigator.nb has all the inter-dependencies built-in (they're arguments supplied to TreeBrowse`LoadVirtualCells and other undocumented functions that build up the documentation center. We can then parse the raw text contents of this notebook to pull out this list. I do that in the following, but I haven't restricted it solely to paclet:guide, which is what you're after. You'll also find links to paclet:tutorial, paclet:ref, etc. Weeding these out should be simple.

doc = Import[FileNameJoin[{$InstallationDirectory, 
    "/Documentation/English/System/DocumentationNavigator.nb"}], "Text"];

tree = (StringCases[doc, "RowBox[{\" \", \"\\<\\" ~~ Shortest[l__] ~~ "\\\"\\>" ~~ 
    Shortest[__] ~~ "TreeBrowse`LoadVirtualCells[" ~~ Shortest[t__] ~~ " 1]," :> 
    {l ~~ "\"", StringDrop[StringTrim@t, -1]}] // ToExpression) /. 
    Delimiter | None -> Sequence[] //. 
    {x_String, y_String?(StringMatchQ[#, "paclet:" ~~ __] &), z___} :> {x, z} /. 
    {x_String} :> x //. {x_String, y_List} :> x -> y;

In the {x_String, y_String?(StringMatchQ[#, "paclet:" ~~ __] &), z___} :> {x, z} rule, I discard all the links to paclet:foo. However, these might be useful in creating a Hyperlink by changing the RHS of the rule to {Hyperlink[x, y], z}, which can then be used in visualizations.

The tree structure obtained from the following will mimic the structure in the documentation center (almost, since this is not exactly the documentation center, but is the function navigator).

enter image description here

share|improve this answer
+1 for the impressive knowledge of hidden internals... – sebhofer Jul 20 '12 at 7:29
+1 This is indeed quite deep ;-) – Vitaliy Kaurov Aug 1 '12 at 6:57
Could you tell me how to make the picture has the Jagged edges effect THX! – Shutao TANG Aug 17 '15 at 13:16

Due to release of new functionality WolframLanguageData there is another way of doing it. Let's take a look at only Graphics functions (one can generalize). Draw a directed network illustrating connectivity of Wolfram Language documentation reference (leaf nodes) and guide (internal nodes) pages:

graphicssym = EntityList[EntityClass["WolframLanguageSymbol", {"FunctionalityArea", "GraphicsFunctions"}]];

linktrails = EntityValue[graphicssym, 
   EntityProperty["WolframLanguageSymbol", "LinkTrails"]];

edges = Flatten[(DirectedEdge @@@ Partition[#, 2, 1]) & /@ 
    Select[Flatten[linktrails, 1], Length[#] > 1 &]];

verts = Flatten[List @@@ edges] // Union;

Graph[edges, VertexLabels -> Placed["Name", Tooltip], 
 VertexStyle -> ((# -> If[StringMatchQ[#, "*ref/*"], Red, Green]) & /@verts)]

enter image description here

Also fun related things:

WolframLanguageData["Cos", "RelationshipCommunityGraph"]

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.