public ArrayList <KeyWord> fromString(long id, char[] str, bool forIndex) { ArrayList <KeyWord> kws = new ArrayList <KeyWord>(); KeyWordE k = null; int linkedCount = 0; int lastNPos = -2; for (int i = 0; i < str.Length; i++) { char c = str[i]; if (c == ' ') { if (k != null) { kws.add(k); } k = null; } else if (c == '"') { if (k != null) { kws.add(k); } k = null; if (linkedCount > 0) { linkedCount = 0; setLinkEnd(kws); } else { linkedCount = 1; } } else if (isWord(c)) { if (k == null && c != '-' && c != '#') { k = new KeyWordE(); k.setID(id); k.setKeyWord(""); k.setPosition(i); if (linkedCount > 0) { linkedCount++; } if (linkedCount > 2) { k.isLinked = true; } } if (k != null) { k.setKeyWord(k.getKeyWord() + c.ToString()); } } else { if (k != null) { kws.add(k); } k = null; KeyWordN n = new KeyWordN(); n.setID(id); n.setPosition(i); n.longKeyWord(c, (char)0, (char)0); n.isLinked = i == (lastNPos + 1); kws.add(n); char c1 = str[i + 1]; if ((c1 != ' ' && c1 != '"') && (!isWord(c1))) { n = new KeyWordN(); n.setID(id); n.setPosition(i); n.longKeyWord(c, c1, (char)0); n.isLinked = i == (lastNPos + 1); kws.add(n); if (!forIndex) { kws.remove(kws.size() - 2); i++; } } if (c1 == ' ' || c1 == '"') { setLinkEnd(kws); } lastNPos = i; } } setLinkEnd(kws); return(kws); }
public SortedSet <String> discover(IBox box, char efrom, char eto, int elength, char nfrom, char nto, int nlength) { SortedSet <String> list = new SortedSet <String>(); Random ran = new Random(); if (elength > 0) { int len = ran.Next(KeyWord.MAX_WORD_LENGTH) + 1; char[] cs = new char[len]; for (int i = 0; i < cs.Length; i++) { cs[i] = (char)(ran.Next(eto - efrom) + efrom); } KeyWordE kw = new KeyWordE(); kw.setKeyWord(new String(cs)); foreach (KeyWord tkw in lessMatch(box, kw)) { String str = tkw.getKeyWord().ToString(); if (str.Length < 3) { continue; } int c = list.Count; list.Add(str); if (list.Count > c) { elength--; if (elength <= 0) { break; } } } } if (nlength > 0) { char[] cs = new char[2]; for (int i = 0; i < cs.Length; i++) { cs[i] = (char)(ran.Next(nto - nfrom) + nfrom); } KeyWordN kw = new KeyWordN(); kw.longKeyWord(cs[0], cs[1], (char)0); foreach (KeyWord tkw in lessMatch(box, kw)) { int c = list.Count; list.Add(((KeyWordN)tkw).toKString()); if (list.Count > c) { nlength--; if (nlength <= 0) { break; } } } } return(list); }