cvsnt-2008-02-process.js

Go to the documentation of this file.
00001 /***
00002 Process the cvsnt-2008-02.html data.
00003 ***/
00004 
00005 /* Add logging to TextMill */
00006 var outputArea = null,     /* will be set after body has loaded */
00007     textmillArea = null;
00008 
00009 TextMill.TMLogger = function(msg)
00010 {
00011    if (outputArea && msg && msg.length)
00012    {
00013       var newPara = document.createElement("p");
00014       if (newPara)
00015       {
00016          /* Hanging indent, no blank space between paragraphs */
00017          newPara.style.marginLeft = "3em";
00018          newPara.style.textIndent = "-3em";
00019          newPara.style.marginTop = newPara.style.marginBottom = "0";
00020          newPara.style.paddingTop = newPara.style.paddingBottom = "0";
00021 
00022          /* Insert the message */
00023          newPara.innerHTML = msg;
00024          outputArea.appendChild(newPara);
00025       }
00026    }
00027 };
00028 
00029 function logElement(elem, contents)
00030 {
00031    var newElem;
00032    if (! elem || ! contents) return;
00033    if (outputArea && (newElem = document.createElement(elem)))
00034    {
00035       newElem.innerHTML = contents;
00036       outputArea.appendChild(newElem);
00037 
00038       /* scroll to the bottom */
00039       outputArea.scrollTop = outputArea.scrollHeight;
00040    }
00041 }
00042 
00043 /* Start things going */
00044 function startup()            /* run after body is loaded */
00045 {
00046    /* Set up logging */
00047    outputArea = document.getElementById("output");
00048    textmillArea = document.getElementById("textmill");
00049    resultsArea = document.getElementById("results");
00050 }
00051 
00052 
00053 /* Load modules */
00054 function loadModules()
00055 {
00056    var useRsp = document.forms["controls"].useResponder.checked;
00057 
00058    /* Add the modules we've loaded to the system */
00059    TextMill.addModule(archiveToEmail);
00060    if (useRsp) TextMill.addModule(emailResponder);
00061 
00062    /* See what we have */
00063    logElement("h2", "TextMill status after loading");
00064    logElement("pre", TextMill);
00065    return false;
00066 }
00067 
00068 /* Run */
00069 function runTM()
00070 {
00071    var start = new Date(), stop;
00072 
00073    /* Try running something */
00074    logElement("h2", "Try running something");
00075    TextMill.run();
00076 
00077    /* Log elapsed time */
00078    stop = new Date();
00079    logElement
00080    (
00081       "p"
00082     , "--- Run finished in "
00083       + (stop - start)
00084       + " milliseconds"
00085    );
00086    return false;
00087 }
00088 
00089 /* Show the current state of TextMill */
00090 function showTM()
00091 {
00092    logElement("pre", TextMill);
00093    return false;
00094 }
00095 
00096 /* Change the input div to show the TextMill multitexts */
00097 function showProgress()
00098 {
00099    var workDiv = document.getElementById("archive");
00100    var archiveData = document.getElementById("data");
00101    if (archiveData) workDiv.removeChild(archiveData);
00102 
00103    /* Show the sources */
00104    var sources = TextMill.sources;
00105    if (sources)
00106    {
00107       var showSources = new Array();
00108       for (var sourceName in sources)
00109       {
00110          var source = sources[sourceName];
00111          var showSource =
00112          {
00113             name: sourceName,
00114             standing:
00115                source.standing.confidence * source.standing.strength
00116          };
00117          showSources.push(showSource);
00118       }
00119       showSources.sort
00120       (
00121          function(s1,s2)
00122          {
00123             if (s1.standing>s2.standing) return -1;
00124             if (s1.standing<s2.standing) return  1;
00125             return 0;
00126          }
00127       );
00128 
00129       var newDiv = document.createElement("div");
00130       var innerHTML = "<ol>\n";
00131       for (var sidx = 0; sidx < showSources.length; sidx++)
00132       {
00133          innerHTML +=
00134             "<li>"
00135           + showSources[sidx].name
00136           + ": "
00137           + showSources[sidx].standing
00138           + "</li>\n";
00139       }
00140       innerHTML += "</ol><hr>";
00141       newDiv.innerHTML = innerHTML;
00142       workDiv.appendChild(newDiv);
00143    }
00144 
00145    /* Show the non-Archive MultiText forms */
00146    var mTexts = TextMill.multiTexts;
00147 
00148    for (var mtidx = 0; mtidx < mTexts.length; mtidx++)
00149    {
00150       var newDiv = document.createElement("div");
00151       newDiv.innerHTML = "";
00152       for (var type in mTexts[mtidx].forms)
00153       {
00154          if (type == "Archive") continue;
00155          for (var tidx = 0; tidx < mTexts[mtidx].forms[type].length;
00156               tidx++)
00157          {
00158             var text = mTexts[mtidx].forms[type][tidx].data;
00159             text = text.replace(/&/g, "&amp;");
00160             text = text.replace(/</g, "&lt;");
00161             text = text.replace(/>/g, "&gt;");
00162             newDiv.innerHTML += "<pre>" + text + "</pre>\n<hr>";
00163          }
00164       }
00165       workDiv.appendChild(newDiv);
00166    }
00167 }
00168 
00169 /* Show final results */
00170 function showResults()
00171 {
00172    var area = document.getElementById("results");
00173    var innerHTML = "<h1>Results</h1>\n";
00174    var sources = TextMill.sources;
00175 
00176    if (sources)
00177    {
00178       var showSources = new Array();
00179       for (var sourceName in sources)
00180       {
00181          var source = sources[sourceName];
00182          var showSource =
00183          {
00184             name: sourceName,
00185             standing:
00186                source.standing.confidence * source.standing.strength
00187          };
00188          showSources.push(showSource);
00189       }
00190       showSources.sort
00191       (
00192          function(s1,s2)
00193          {
00194             if (s1.standing>s2.standing) return -1;
00195             if (s1.standing<s2.standing) return  1;
00196             return 0;
00197          }
00198       );
00199 
00200       for (var sidx = 0; sidx < showSources.length; sidx++)
00201       {
00202          innerHTML +=
00203             "<div style=\"font-size: "
00204           + (showSources[sidx].standing * 3.0)
00205           + "em;\">"
00206           + showSources[sidx].name
00207           + "</div>\n";
00208       }
00209       
00210       area.innerHTML = innerHTML;
00211       area.style.display = "block";
00212    }
00213 }
00214 
00215 /* Show the TM divs */
00216 function showTMPanel()
00217 {
00218    if (textmillArea) textmillArea.style.display = "block";
00219    if (outputArea)   outputArea.style.display = "block";
00220 
00221    var tmdArea = document.getElementById("TMdisplay");
00222    if (tmdArea)      tmdArea.style.display = "none";
00223 
00224    window.scrollTo(0,0);
00225    return false;
00226 }

Based on content generated using Doxygen