FusionAtlas's Manual Splice Robot

This notebook contains a modification of "Dror's Robot", described in http://katlas.org/wiki/How_to_Edit_this_Manual...

After downloading this notebook, FusionAtlas, and KnotTheory` it takes six simple steps to run Dror's Robot:
1. Set the KnotTheory` and FusionAtlas` directories and load KnotTheory` and FusionAtlas`.
2. Choose a "scratch work" directory for image generation.
3. Create the WikiLink connection to the Knot Atlas wiki server.
4. Run the "definitions" part of this notebook.
5. Run the robot. (Run the commands in either section 5a (for the KnotAtlas) or section 5b (for the FusionAtlas).)

1. Set the KnotTheory` directory and load KnotTheory`.

Create a  " "MyKnotTheoryPath" as appropriate for your system (e.g., it should be the directory above "KnotTheory/"), add a line appending it to the $Path, then execute the following cell:

We need the KnotTheory package in order to use WikiLink later in the game.

ScottKnotTheoryPath ="C:\\scott\\projects\\KnotTheory\\trunk\\";
AppendTo[$Path, ScottKnotTheoryPath];
EmilyKnotTheoryPath="~/Documents/Math/KnotAtlas/KnotTheory/trunk/"
AppendTo[$Path, EmilyKnotTheoryPath];
<< KnotTheory`

ScottFusionAtlasPath="c:\\scott\\projects\\fusionatlas\\code\\package\\";
AppendTo[$Path, ScottFusionAtlasPath];
NoahFusionAtlasPath="~/Documents/math papers/fusionatlas/code/package/";
AppendTo[$Path, NoahFusionAtlasPath];
EmilyFusionAtlasPath="~/Documents/Math/fusionatlas/code/package/";
AppendTo[$Path, EmilyFusionAtlasPath];

<<FusionAtlas`

2. Choose a "scratch work" directory for image generation.

Change the line below as you please and execute it:

ScratchWorkDirectory=FusionAtlasDirectory[]<>"Scratch";

3. Create the WikiLink connection to the Knot Atlas wiki server.

Execute the cell below. You will be prompted for your username and password on the Knot Atlas wiki.

CreateWikiConnection[
"http://tqft.net/w/index.php",
InputString["Enter Your Username:"],
InputString["Enter Your Password"]
];
WikiUserName[]

4. Run the "definitions" part of this notebook.

Simply execute the (longish) cell below.

WhitespaceQ[" "] =True;
WhitespaceQ["\n"] =True;
WhitespaceQ[_] = False;
RobotsWarningPhrase[]="<!--Robot Land, no human edits to \"END\"-->";
RemoveWhitespace[s_String] := Module[
{chars, k, out=""},
chars = Characters[" "<>s<>" "];
Do[
If[
!(WhitespaceQ[chars[[k-1]]] && WhitespaceQ[chars[[k]]]),
out=out<>chars[[k]]
],
{k, 2, Length[chars]}
];
StringDrop[out, -1]
];
ManualSpliceRobot[url_String] := Module[
{page, marks, query, exe, replacements, in, out, about,  n=0},
page = WikiGetPageText[url];
marks = Partition[Flatten[Transpose[{
StringPosition[page, "<!--$"],
StringPosition[page, "$-->"],
StringPosition[page, "<!--END-->"]
}]], 6];
query="The following Mathematica lines were found in "<>url<>"\n";
query=query<>(StringJoin @@ (
(StringTake[page, {#[[2]]+1, #[[3]]-1}]<>"\n")& /@ marks
));
Print[query=query<>"Execute these lines? (Yes/No)"];
exe = InputString[query];
If[!MatchQ[exe, "Yes"|"yes"|"Y"|"y"], "Not Done",
replacements = {
in = StringTake[page, {#[[2]]+1, #[[3]]-1}];
Which[
in==="$<<FusionAtlas`$", (
StringJoin[
"\n"<>RobotsWarningPhrase[]<>"\n",
"<tt><font color=blue>In["<>ToString[++n]<>"]:=</font></tt><code>  <<FusionAtlas`</code>\n",
"\n",
"<tt>"<>FusionAtlasWelcomeMessage[]<>"</tt>\n"
]
),
StringTake[in, 2]==="$?" && Last[Characters[in]]==="$", (
in=StringTake[in, {3, -2}];
out= RemoveWhitespace[ToExpression[in<>"::usage"]];
If[Head[about=ToExpression[in<>"::about"]]=!= String,
StringJoin[                                                                                                       (* HelpLine *)
"\n"<>RobotsWarningPhrase[]<>"\n",
"{{HelpLine|\n",
"n  = "<>ToString[++n]<>" |\n",
"in = "<>ToString[in, WikiForm]<>" |\n",
"out= "<>ToString[out, WikiForm]<>"}}\n"
],
about=RemoveWhitespace[about];
StringJoin[                                                                                                       (* HelpAndAbout *)
"\n"<>RobotsWarningPhrase[]<>"\n",
"{{HelpAndAbout|\n",
"n  = "<>ToString[++n]<>" |\n",
"n1 = "<>ToString[++n]<>" |\n",
"in = "<>ToString[in, WikiForm]<>" |\n",
"out= "<>ToString[out, WikiForm]<>" |\n",
"about= "<>ToString[about, WikiForm]<>"}}\n"
]
]
),
First[Characters[in]]==="$" && Last[Characters[in]]==="$", (
in=StringTake[in, {2, -2}];
out=ToExpression[in];
Which[
out===Null, (
StringJoin[
"\n"<>RobotsWarningPhrase[]<>"\n",
"{{In|\n",
"n  = "<>ToString[++n]<>" |\n",
"in = <nowiki>"<>in<>"</nowiki>}}\n"
]
),
MemberQ[{Graphics, Graphics3D}, Head[out]], (                     (* Graphics *)
imagename = StringReplace[
url<>"_Out_"<>ToString[++n]<>".gif",
{"(" -> "", "%28" -> "", ")" -> "", "%29" -> "", "\"" -> ""}
];
fullimagename=ScratchWorkDirectory<>"/"<>imagename;
If[Length[FileNames[ScratchWorkDirectory]]==0,CreateDirectory[ScratchWorkDirectory]];
Export[fullimagename, out];
Print["attempting to upload file: fullimagename==",fullimagename, " in==",in];
WikiUploadFile[fullimagename, in];
out="-"<>ToString[Head[out]]<>"-";
StringJoin[
"\n"<>RobotsWarningPhrase[]<>"\n",
"{{Graphics|\n",
"n  = "<>ToString[++n]<>" |\n",
"in = <nowiki>"<>in<>"</nowiki> |\n",
"img= "<>imagename<>" |\n",
"out= <nowiki>"<>out<>"</nowiki>}}\n"
]
),
True, (                                                                                                                                 (* InOut *)
out = ToString[out, FormatType->OutputForm,PageWidth->72];
StringJoin[
"\n"<>RobotsWarningPhrase[]<>"\n",
"{{InOut|\n",
"n  = "<>ToString[++n]<>" |\n",
"in = <nowiki>"<>in<>"</nowiki> |\n",
"out= <nowiki>"<>out<>"</nowiki>}}\n"
]
)
]
),
True, (
out=ToExpression[in];
If[out===Null, "",
StringJoin[
RobotsWarningPhrase[],
ToString[out]
]
]
)
],
{#[[4]]+1, #[[5]]-1}
}& /@ marks;
page = StringReplacePart[page, First /@ replacements, Last /@ replacements];
WikiSetPageText[url, page]
]
]

5a. Run the robot. (katlas)

Execute any one or any many of the cells below; you may execute them in any order and/or repeat any given execution many times as you make progress editing pages. It should be obvious how to run the robot on new pages as well...
Notice that each time you run the robot it prints all the lines it will splice BEFORE executing them and asks for confirmation. You should review each such printout before confirming; this is a wiki and malicious code could have been planted.

Warning: This robot is grumpy and unforgiving. If things are formatted not quite the way it likes them, it goes crazy with beeps and red error messages.

ManualSpliceRobot["Setup"]

ManualSpliceRobot["Naming_and_Enumeration"]

ManualSpliceRobot["Planar_Diagrams"]

ManualSpliceRobot["Gauss_Codes"]

ManualSpliceRobot["DT_%28Dowker-Thistlethwaite%29_Codes"]

ManualSpliceRobot["Braid_Representatives"]

ManualSpliceRobot["Arc_Presentations"]

ManualSpliceRobot["Drawing_Planar_Diagrams"]

ManualSpliceRobot["Drawing_Braids"]

ManualSpliceRobot["Structure_and_Operations"]

ManualSpliceRobot["Invariants_from_Braid_Theory"]

ManualSpliceRobot["Three_Dimensional_Invariants"]

ManualSpliceRobot["The_Alexander-Conway_Polynomial"]

ManualSpliceRobot["The_Multivariable_Alexander_Polynomial"]

ManualSpliceRobot["The_Determinant_and_the_Signature"]

ManualSpliceRobot["The_Jones_Polynomial"]

ManualSpliceRobot["The_Coloured_Jones_Polynomials"]

ManualSpliceRobot["The_A2_Invariant"]

ManualSpliceRobot["Quantum_knot_invariants"]

ManualSpliceRobot["The_HOMFLY-PT_Polynomial"]

ManualSpliceRobot["The_Kauffman_Polynomial"]

ManualSpliceRobot["Finite_Type_%28Vassiliev%29_Invariants"]

ManualSpliceRobot["Khovanov_Homology"]

ManualSpliceRobot["Heegaard_Floer_Knot_Homology"]

ManualSpliceRobot["Drawing_with_TubePlot"]

ManualSpliceRobot["Lightly_Documented_Features"]

ManualSpliceRobot["\"Rubberband\" Brunnian Links"]

ManualSpliceRobot["How_to_Edit_this_Manual..."]

To splice the WikiLink manual page, WikiLink has to be on the path. If you've got this far it already is!

ManualSpliceRobot["WikiLink_-_The_Mediawiki_Interface"]

5b. Run the robot. (fusionatlas)

Execute any one or any many of the cells below; you may execute them in any order and/or repeat any given execution many times as you make progress editing pages. It should be obvious how to run the robot on new pages as well...
Notice that each time you run the robot it prints all the lines it will splice BEFORE executing them and asks for confirmation. You should review each such printout before confirming; this is a wiki and malicious code could have been planted.

Warning: This robot is grumpy and unforgiving. If things are formatted not quite the way it likes them, it goes crazy with beeps and red error messages.

ManualSpliceRobot["Entering_a_(graded_bipartite)_graph"]

ManualSpliceRobot["Computing_properties_of_graphs"]

ManualSpliceRobot["Atlas_of_subfactors"]

?WikiSetPageText