private static IEnumerable <KeyWord> search(IBox box, KeyWord kw, KeyWord con, bool asWord, MaxID maxId) { if (kw is KeyWordE) { asWord = true; return(new Index2KeyWordIterable <KeyWordE> ( box.Select <Object> ("from /E where K==? & I<=?", kw.KWord, maxId.id), box, kw, con, asWord, maxId)); } else { if (con is KeyWordE) { asWord = true; } if (con == null || asWord) { asWord = true; return(new Index2KeyWordIterable <KeyWordN> ( box.Select <Object> ("from /N where K==? & I<=?", kw.KWord, maxId.id), box, kw, con, asWord, maxId)); } else { Object[] os = (Object[])box ["/N", kw.KWord, con.ID, (con.Position + ((KeyWordN)con).size())] .Select <Object> (); if (os != null) { KeyWordN cache = new KeyWordN(); cache.KWord = os [0]; cache.I = (long)os [1]; cache.P = (int)os [2]; List <KeyWord> r = new List <KeyWord> (1); r.Add(cache); return(r); } else { return(emptySearch); } } } }
public void correctInput(List <KeyWord> kws) { for (int i = 0; i < kws.Count; i++) { KeyWord kw = (KeyWord)kws [i]; if (kw is KeyWordE) { String str = kw.KWord.ToString(); if (correctKW.TryGetValue(str, out str)) { if (isWord(str [0])) { kw.KWord = str; } else { KeyWordN kwn = new KeyWordN(); kwn.I = kw.I; kwn.P = kw.P + 1; switch (str.Length) { case 1: kwn.longKeyWord(str [0], (char)0, (char)0); break; case 2: kwn.longKeyWord(str [0], str [1], (char)0); break; default: continue; } kws [i] = kwn; } } } } }
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); }
public List <KeyWord> fromString(long id, char[] str, bool includeOF) { List <KeyWord> kws = new List <KeyWord> (); KeyWordE k = null; for (int i = 0; i < str.Length; i++) { char c = str [i]; if (c == ' ') { if (k != null) { kws.Add(k); if (includeOF) { k = k.getOriginalForm(); if (k != null) { kws.Add(k); } } } k = null; } else if (sUtil.isWord(c)) { if (k == null && c != '-' && c != '#') { k = new KeyWordE(); k.ID = id; k.KWord = ""; k.Position = i; } if (k != null) { k.KWord = k.KWord.ToString() + c; } } else { if (k != null) { kws.Add(k); if (includeOF) { k = k.getOriginalForm(); if (k != null) { kws.Add(k); } } } k = null; KeyWordN n = new KeyWordN(); n.ID = id; n.KWord = c; n.Position = i; kws.Add(n); } } return(kws); }