Dror's Manual Splice Robot

This notebook contains, "Dror's Robot", described in http://katlas.math.toronto.edu/wiki/How_to_Edit_this_Manual...

After downloading it, KnotTheory` and WikiLink.m, it takes six simple steps to run Dror's Robot:
1. Set the KnotTheory` directory and load KnotTheory`.
2. Set the WikiLink directory and load WikiLink.m.
3. Choose a "scratch work" directory for image generation.
4. Create the WikiLink connection to the Knot Atlas wiki server.
5. Run the "definitions" part of this notebook.
6. Run the robot.

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

Change "KnotAtlasPath" as appropriate for your system (e.g., it should be the directory above "KnotTheory/") and execute the following cell:

Dror's version

KnotAtlasPath  =  "C:/drorbn/KAtlas/";
AppendTo[$Path,  KnotAtlasPath];
<<  KnotTheory`
<<  KnotTheoryExtra`

Scott's version

\(\(KnotAtlasPath\  = \ "c:\scott\math.berkeley.edu\Work\Mathematica\KnotAtlas\";\)\)
AppendTo[$Path,  KnotAtlasPath];
<<  KnotTheory`
<<  KnotTheoryExtra`

2. Set the WikiLink directory and load WikiLink.m.

Change "WikiLinkPath" as appropriate for your system (i.e., it should be the directory where WikiLink.m resides) and execute the following cell:

WikiLinkPath  =  
        KnotAtlasPath <> "WikiLink\\";
Get[WikiLinkPath <> "WikiLink.m"];
SetJarPath[WikiLinkPath];

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

Change the line below as you please and execute it:

ScratchWorkDirectory = KnotAtlasPath <> "Scratch";

4. 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://katlas.math.toronto.edu/w/index.php", 
InputString["Enter Your Username:"], 
InputString["Enter Your Password"]
]\)

WikiUserName[]

5. 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 <> "
"; 
query = 
          query <> \((StringJoin\  @@ \ \((
\(\((StringTake[
                            page, \ {#[\([2]\)] + 1, \ #[\([3]\)] - 
                                1}] <> "
")\) &\)\  /@ \ 
                    marks
)\))\); 
Print[
          query = query <> "Execute these lines? (Yes/No)"]; 
exe\  = \ InputString[query]; 
If[
          exe\  =!= \ "Yes", \ "Not Done", 
replacements\  = \ \({
in\  = \ 
                    StringTake[
                      page, \ {#[\([2]\)] + 1, \ #[\([3]\)] - 
                          1}]; 
Which[
in === "$<< KnotTheory`$", \ \((
StringJoin[
"
" <> 
                          RobotsWarningPhrase[] <> "
", 
"<tt><font color=blue>In[" <> 
                          ToString[\(++n\)] <> "]:=</font></tt><code>  << KnotTheory`</code>
", 
"
", 
"<tt>" <> 
                          KnotTheoryWelcomeMessage[] <> "</tt>
"
]
)\), 
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\ *) 
"
" <> 
                            RobotsWarningPhrase[] <> "
", 
"{{HelpLine|
", 
"n  = " <> 
                            ToString[\(++n\)] <> " |
", 
"in = " <> 
                            ToString[in, \ 
                              WikiForm] <> " |
", 
"out= " <> 
                            ToString[out, \ 
                              WikiForm] <> "}}
"
], 
about = 
                          RemoveWhitespace[
                            about]; 
StringJoin[\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*\ 
                            HelpAndAbout\ *) 
"
" <> 
                            RobotsWarningPhrase[] <> "
", 
"{{HelpAndAbout|
", 
"n  = " <> 
                            
                            ToString[\(++n\)] <> " |
", 
"n1 = " <> 
                            ToString[\(++n\)] <> " |
", 
"in = " <> 
                            ToString[in, \ 
                              WikiForm] <> " |
", 
"out= " <> 
                            ToString[out, \ 
                              WikiForm] <> " |
", 
"about= " <> 
                            ToString[about, \ 
                              WikiForm] <> "}}
"
]
]
)\), 
First[
                          Characters[in]] === "$"\  && \ 
                      Last[Characters[
                            in]] === "$", \ \((
in = 
                        StringTake[
                          in, \ {2, \ \(-2\)}]; 
out = 
                        ToExpression[
                          in]; 
Which[
out === Null, \ \((
StringJoin[
"
" <> 
                              RobotsWarningPhrase[] <> "
", 
"{{In|
", 
"n  = " <> 
                              ToString[\(++n\)] <> " |
", 
"in = " <> 
                              ToString[in, \ 
                                WikiForm] <> "}}
"
]
)\), 
MemberQ[{Graphics, \ 
                            Graphics3D}, \ 
                          Head[out]], \ \((\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*\ Graphics\ *) 
imagename\  = \ 
                            StringReplace[
url <> "_Out_" <> 
                                ToString[\(++n\)] <> ".gif", 
{"("\  -> \ "", \ "%28"\  -> \ "", \ ")"\  -> \ "", \ "%29"\  -> \ ""}
]; 
fullimagename = 
                            ScratchWorkDirectory <> "/" <> 
                              imagename; 
Export[
                            fullimagename, \ 
                            out]; 
WikiUploadFile[
                            fullimagename, \ 
                            in]; 
out = "-" <> 
                              ToString[
                                Head[out]] <> "-"; 
StringJoin[
"
" <> 
                              RobotsWarningPhrase[] <> "
", 
"{{Graphics|
", 
"n  = " <> 
                              ToString[\(++n\)] <> " |
", 
"in = " <> 
                              ToString[in, \ 
                                WikiForm] <> " |
", 
"img= " <> imagename <> " |
", 
"out= " <> 
                              ToString[out, \ 
                                WikiForm] <> "}}
"
]
)\), 
True, \ \((\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*\ InOut\ *) 
out\  = \ 
                            ToString[out, \ FormatType -> OutputForm, 
                              PageWidth -> 
                                72]; 
StringJoin[
"
" <> 
                              RobotsWarningPhrase[] <> "
", 
"{{InOut|
", 
"n  = " <> 
                              ToString[\(++n\)] <> " |
", 
"in = " <> 
                              ToString[in, \ 
                                WikiForm] <> " |
", 
"out= " <> ToString[out, \ 
                                WikiForm] <> "}}
"
]
)\)
]
)\), 
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]
]
]\)

6. Run the robot.

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["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_Determinant_and_the_Signature"]

ManualSpliceRobot["The_Jones_Polynomial"]

ManualSpliceRobot["The_Coloured_Jones_Polynomials"]

ManualSpliceRobot["The_A2_Invariant"]

ManualSpliceRobot["The_HOMFLY-PT_Polynomial"]

ManualSpliceRobot["The_Kauffman_Polynomial"]

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

ManualSpliceRobot["Khovanov_Homology"]

ManualSpliceRobot["Drawing_with_TubePlot"]

ManualSpliceRobot["Lightly_Documented_Features"]

ManualSpliceRobot["How_to_Edit_this_Manual..."]

ManualSpliceRobot["WikiLink_-_The_Mediawiki_Interface"]