Ejemplo n.º 1
0
        public KeyWordE getOriginalForm()
        {
            String of;

            if (antetypes.TryGetValue(K, out of))
            {
                KeyWordE e = new KeyWordE();
                e.I = this.I;
                e.P = this.P;
                e.K = of;
                return(e);
            }
            return(null);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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.KWord    = c;
                    n.Position = i;
                    kws.Add(n);
                }
            }

            return(kws);
        }