Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
              \\Mathematica\\8.0\\Documentation\\English\\System\\Guides"]

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: 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
1  
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 –  rm -rf Aug 1 '12 at 7:42
    
@R.M You are right! +1 Update the post, thanks. –  Vitaliy Kaurov Aug 1 '12 at 7:56
add comment

3 Answers 3

up vote 15 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:

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

This will filter out links to guides only:

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

This extracts a name from the link:

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

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

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

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

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

Here is a list of guides:

guides = 
  FileNames["*", 
   "C:\\Program Files\\Wolfram Research\\Mathematica\\
       8.0\\Documentation\\English\\System\\Guides"];

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
add comment

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
add comment

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["http://reference.wolfram.com/mathematica/guide/HowToTopics.html",  2], style];
Graph[VertexList[g], Tooltip /@ EdgeList[g], style]

enter image description here

share|improve this answer
1  
+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
add comment

Your Answer

 
discard

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.