Convert graph format for Mathematica graph functions
I am assuming that you can import the data as a string
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
Given that try these steps
Extract the numbers
digits = ToExpression[StringCases[data, DigitCharacter..]]
(* {3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0, 6, 1, 7, 2, 7, 7,
8, 6, 9, 4, 10, 2, 11, 4} *)
Use Partition
to create pairs
pairs = Partition[digits, 2]
(* {{3, 0}, {3, 0}, {3, 2}, {5, 1}, {5, 1}, {5, 4}, {6, 0},
{6, 1}, {7, 2}, {7, 7}, {8, 6}, {9, 4}, {10, 2}, {11, 4}} *)
Use a rule to convert {3,0}
to 3->0
and generate a list
list = pairs /. {x_, y_} -> (x -> y)
(* {3 -> 0, 3 -> 0, 3 -> 2, 5 -> 1, 5 -> 1, 5 -> 4, 6 -> 0,
6 -> 1, 7 -> 2, 7 -> 7, 8 -> 6, 9 -> 4, 10 -> 2, 11 -> 4} *)
Then graph it
Graph[list]
Update
In order to create {{3 -> 0, 1},{3 -> 0, 2},{3-> 2, 3}..} use MapIndexed
with pairs
as the input
MapIndexed[{#1[[1]] -> #1[[2]], #2[[1]]} &, pairs]
(* {{3 -> 0, 1}, {3 -> 0, 2}, {3 -> 2, 3}, {5 -> 1, 4},
{5 -> 1, 5}, {5 -> 4, 6}, {6 -> 0, 7}, {6 -> 1, 8}, {7 -> 2, 9},
{7 -> 7, 10}, {8 -> 6, 11}, {9 -> 4, 12}, {10 -> 2, 13},
{11 -> 4, 14}}
*)
Given data
(as defined by @Jack LaVigne),
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
I might just have written
Graph[ToExpression["{" ~~ StringReplace[data, "[" -> "DirectedEdge["] ~~ "}"]]
to get the graph.
Stitching several functions together to get a function that takes a string containing edges in Maple format and all the options of Graph
:
ClearAll[mapleEdgesToGraph]
mapleEdgesToGraph = Graph[ToExpression @* ToString @* List @*
StringReplace["[" -> "DirectedEdge["] @ #, ##2]&;
Example: Using data
from Jack's answer:
mapleEdgesToGraph[data]
mapleEdgesToGraph[data,
GraphStyle -> "IndexLabeled",
EdgeStyle -> Blue,
GraphLayout -> "CircularEmbedding",
ImageSize -> Large]