Пример #1
0
        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;
                        }
                    }
                }
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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.Position = i;
                    n.longKeyWord(c, (char)0, (char)0);
                    kws.Add(n);

                    char c1 = str [i + 1];
                    if ((c1 != ' ') && (!sUtil.isWord(c1)))
                    {
                        n          = new KeyWordN();
                        n.ID       = id;
                        n.Position = i;
                        n.longKeyWord(c, c1, (char)0);
                        kws.Add(n);
                        if (!includeOF)
                        {
                            kws.RemoveAt(kws.Count - 2);
                            i++;
                        }
                    }
                }
            }
            return(kws);
        }