2
$\begingroup$

In this answer, @Vitaliy Kaurov explores and utilizes new Mathematica's functionality WolframLanguageData:

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

As you can see, there two types of nodes: "green" for guides, and "red" for reference pages. This covers of course only a small subset of Mathematica documentation, since "FunctionalityArea" is limited to "GraphicsFunctions". But this is convenient for visual exploration, certainly much better than a graph with hundreds of thousands nodes, so I like this as a test example.


I would like to do some visualization of Mathematica's documentation structure with external tools. In order to do this, I want to obtain information presented in the graph above inside a JSON file with the following format:

{
  "groups":[
    {"name":"guide"},
    {"name":"ref"}
  ],
  "nodes":[
    {"name":"Finance","group":0},
    {"name":"StringManipulation","group":0},
    {"name":"Raster","group":1},
    {"name":"CapForm","group":1},
    ...
  ],
  "links":[
    {"source":1,"target":0},
    {"source":2,"target":0},
    {"source":3,"target":0},
    {"source":3,"target":2},
    ...
  ]
}
  • "groups" are simply two types of pages of Mathematica documentation, "guide", and "ref";
  • "nodes" is a list of nodes that contain the node name and index of the node's group;
  • "links" is a list of links between nodes, and nodes are determined by their indexes in their list.

I tried to incorporate @Szabolcs 's code from another answer into my solution:

g = RandomGraph[BarabasiAlbertGraphDistribution[100, 1]]

names = VertexList[g];
groups = VertexDegree[g]; (* let's try degree-based colouring *)

Export[
  "graph.json",
  {
    "nodes" -> MapThread[{"name" -> #1, "group" -> #2} &, {names, groups}],
    "links" -> 
       ({"source" -> #1 - 1, "target" -> #2 - 1, "value" -> 1} &) @@@ EdgeList[g]
  },
  "JSON"]

However, I couldn't get all bits and pieces working. Hope some of you could help.

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.