// breaks the word list down and placed it into hyperlinks, and appends the definition private string formatWrdDefn(string wrdlst, SynSet defn) { string retstr = null; retstr = formatWordList(wrdlst); string tmpstr = linkDefinition(defn.defn); // turn definition words into hyperlinks if (!string.IsNullOrEmpty(tmpstr)) { //if (WNOpt.opt("-o").flag && defn.hereiam != -1) //{ // tmpstr = "<font color='green'>Synset offset:" + defn.hereiam.ToString() + "<font> " + tmpstr; //} retstr += ":"; } retstr += " <span class='Defn'>" + tmpstr + "</span><br />" + Constants.vbCrLf; return(retstr); }
// format lists private string decodeOther(SynSet ss) { string buf = ss.defn; string tmpstr = null; string[] tmparr = null; string retstr = null; string wrdlst = null; string defn = null; string fullAppName = Assembly.GetExecutingAssembly().GetName().CodeBase; //This strips off the exe name string FullAppPath = Path.GetDirectoryName(fullAppName); FullAppPath = Strings.Mid(FullAppPath, Strings.Len("file:\\\\")); buf = Strings.Replace(buf, "_", " "); // split the summary buffer into lines tmparr = Strings.Split(buf, Constants.vbLf); int i = 0; int x = 0; bool senseflag = false; // determine if a sense has been located int prevLevel = 0; // previous indent level, so the system knows how many ul's to close and how to handle new indents ArrayList levelArray = new ArrayList(); for (i = 2; i <= tmparr.GetUpperBound(0); i++) { tmpstr = tmparr[i]; // get a line for processing // this is a section separator if (Strings.InStr(tmpstr, "----") > 0) { continue; } // Sense, followed by a number (eg. Sense 1) denotes a definition line if (Strings.Left(tmpstr, 5) == "Sense" & !(Strings.InStr(tmpstr, "--") > 0)) { if (Strings.Asc(Strings.Mid(tmpstr, 7, 1)) >= 49 & Strings.Asc(Strings.Mid(tmpstr, 7, 1)) <= 57) { senseflag = true; // collapse all open levels if (prevLevel > 0) { int inc = 0; for (inc = levelArray.Count; inc >= 0; inc += -1) { try { levelArray.RemoveAt(levelArray.Count - 1); retstr += "</ul>"; } catch { } } prevLevel = 0; } continue; } } // this is a 'pertains to' line // If Left(LTrim(tmpstr), 11) = "Pertains to" And InStr(tmpstr, "Sense") Then // this is 'pertains to' or antonym if (Strings.InStr(tmpstr, "(Sense") > 0) { retstr += "<br />" + Constants.vbCrLf + Strings.Left(tmpstr, Strings.InStr(tmpstr, ")")); tmparr[i] = Strings.Mid(tmpstr, Strings.Len(Strings.Left(tmpstr, Strings.InStr(tmpstr, ")"))) + 1); i -= 1; continue; } // this is a definition line if (senseflag) { retstr += "<font color='red'><b>" + x + 1 + ") </b></font> "; tmpstr = Strings.RTrim(tmpstr); wrdlst = Strings.Left(tmpstr, Strings.InStr(tmpstr, "--") - 2); defn = Strings.Mid(tmpstr, Strings.Len(wrdlst) + 6); wrdlst = Strings.Replace(wrdlst, ", ", ","); Wnlib.SynSet tmpss = new Wnlib.SynSet(); tmpss.defn = defn; tmpss.hereiam = -1; retstr += formatWrdDefn(wrdlst, tmpss); x += 1; senseflag = false; // this is an indented definition } else if (!senseflag & !string.IsNullOrEmpty(Strings.LTrim(Strings.RTrim(tmpstr)))) { if (Strings.InStr(tmpstr, "CATEGORY TERM") > 0) { // collapse higher levels if (prevLevel > 0) { int inc = 0; for (inc = 1; inc <= prevLevel; inc++) { try { levelArray.RemoveAt(levelArray.Count - 1); retstr += "</ul>"; } catch { } } prevLevel = 0; } wrdlst = Strings.Mid(tmpstr, Strings.InStr(tmpstr, ")") + 2); wrdlst = formatWordList(wrdlst); defn = Strings.Left(tmpstr, Strings.InStr(tmpstr, ")")); retstr += "<li>" + Constants.vbTab + defn + " " + wrdlst + "</li>"; continue; } else if (Strings.InStr(tmpstr, "(noun)") > 0 || Strings.InStr(tmpstr, "(verb)") > 0 || Strings.InStr(tmpstr, "(adj)") > 0 || Strings.InStr(tmpstr, ("adverb")) > 0) { // this check must be made first, otherwise confusion can occur from colons in the sentence (for the next check) int lvl = 0; lvl = indentLevel(tmpstr); if (lvl < prevLevel) { int levdif = 0; int inc = 0; levdif = prevLevel - lvl; // get the number of levels we've jumped back for (inc = 1; inc <= levdif; inc++) { // remove the defined level from the tracking array try { levelArray.RemoveAt(levelArray.Count - 1); retstr += "</ul>"; } catch { } } } else if (lvl > prevLevel) { levelArray.Add(lvl); retstr += "<ul>"; } else { if (levelArray.IndexOf(lvl) == -1) { // starting level was level 2, so this confuses the system retstr += "<ul>"; levelArray.Add(lvl); } } prevLevel = lvl; wrdlst = Strings.Mid(tmpstr, Strings.InStr(tmpstr, ")") + 2); defn = ""; //defn = Mid(wrdlst, InStr(wrdlst, "--") + 3) //wrdlst = Left(wrdlst, InStr(wrdlst, "--") - 1) Wnlib.SynSet tmpss = new Wnlib.SynSet(); tmpss.defn = ""; tmpss.hereiam = -1; wrdlst = formatWrdDefn(wrdlst, tmpss); retstr += "<li>" + Constants.vbTab + Strings.Left(tmpstr, Strings.InStr(tmpstr, ")")) + " " + wrdlst + "</li>"; continue; } else if (Strings.InStr(tmpstr, ">") > 0) { // this check must be made first, otherwise confusion can occur from colons in the sentence (for the next check) int lvl = 0; lvl = indentLevel(tmpstr); if (lvl < prevLevel) { int levdif = 0; int inc = 0; levdif = prevLevel - lvl; // get the number of levels we've jumped back for (inc = 1; inc <= levdif; inc++) { // remove the defined level from the tracking array try { levelArray.RemoveAt(levelArray.Count - 1); retstr += "</ul>"; } catch { } } } else if (lvl > prevLevel) { levelArray.Add(lvl); retstr += "<ul>"; } else { if (levelArray.IndexOf(lvl) == -1) { // starting level was level 2, so this confuses the system retstr += "<ul>"; levelArray.Add(lvl); } } prevLevel = lvl; wrdlst = Strings.Mid(tmpstr, Strings.InStr(tmpstr, ">") + 2); if (wrdlst.IndexOf("--") > -1) { defn = Strings.Mid(wrdlst, Strings.InStr(wrdlst, "--") + 3); wrdlst = Strings.Left(wrdlst, Strings.InStr(wrdlst, "--") - 1); } else { int z = 1; // this line exists purely as a breakpoint placeholder } Wnlib.SynSet tmpss = new Wnlib.SynSet(); tmpss.defn = defn; tmpss.hereiam = -1; wrdlst = formatWrdDefn(wrdlst, tmpss); retstr += "<li>" + Constants.vbTab + Strings.Left(tmpstr, Strings.InStr(tmpstr, ">")) + " " + wrdlst + "</li>"; continue; } else if (Strings.InStr(tmpstr, ":") > 0) { int lvl = 0; lvl = indentLevel(tmpstr); if (lvl < prevLevel) { int levdif = 0; int inc = 0; levdif = prevLevel - lvl; // get the number of levels we've jumped back for (inc = 1; inc <= levdif; inc++) { // remove the defined level from the tracking array try { levelArray.RemoveAt(levelArray.Count - 1); retstr += "</ul>"; } catch { } } } else if (lvl > prevLevel) { levelArray.Add(lvl); retstr += "<ul>"; } else { if (levelArray.IndexOf(lvl) == -1) { // starting level was level 2, so this confuses the system retstr += "<ul>"; levelArray.Add(lvl); } } prevLevel = lvl; wrdlst = Strings.Mid(tmpstr, Strings.InStr(tmpstr, ":") + 2); defn = Strings.Mid(wrdlst, Strings.InStr(wrdlst, "--") + 3); if (Strings.InStr(wrdlst, "--") == 0) { continue; } wrdlst = Strings.Left(wrdlst, Strings.InStr(wrdlst, "--") - 1); Wnlib.SynSet tmpss = new Wnlib.SynSet(); tmpss.defn = defn; tmpss.hereiam = -1; wrdlst = formatWrdDefn(wrdlst, tmpss); retstr += "<li>" + Constants.vbTab + Strings.Left(tmpstr, Strings.InStr(tmpstr, ":") + 1) + " " + wrdlst + "</li>"; continue; } } } //If thirdindentflag Then // retstr += "</ul>" ' close the third indent // thirdindentflag = False //End If //If secondindentflag Then // retstr += "</ul>" ' close the second indent // secondindentflag = False //End If //If firstindentflag Then // retstr += "</ul>" ' close the first indent // firstindentflag = False //End If // collapse all open levels if (prevLevel > 0) { int inc = 0; for (inc = levelArray.Count; inc >= 0; inc += -1) { //levelArray.RemoveAt(levelArray.IndexOf(inc)) try { levelArray.RemoveAt(levelArray.Count - 1); retstr += "</ul>"; } catch { } } prevLevel = 0; } return(retstr); }