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
But I am not sure what is the next most efficient way to analyze the connections.
A walk through guide pages
------------ 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]
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]
Answer
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.
Comments
Post a Comment