Ejemplo n.º 1
0
        public void OverviewFor(string t, string p, ref bool b, ref SearchSet obj, List <Search> list)
        {
            SearchSet ss = null;

            if (string.IsNullOrWhiteSpace(p))
            {
                OverviewFor(t, PartsOfSpeech.Adjective.ToString(), ref b, ref obj, list);
                OverviewFor(t, PartsOfSpeech.Adverb.ToString(), ref b, ref obj, list);
                OverviewFor(t, PartsOfSpeech.Noun.ToString(), ref b, ref obj, list);
                OverviewFor(t, PartsOfSpeech.Verb.ToString(), ref b, ref obj, list);

                ss = obj;
            }
            else
            {
                PartOfSpeech pos = PartOfSpeech.Of(p);

                if (!string.IsNullOrWhiteSpace(pos?.Key))
                {
                    ss = netData.Is_defined(t, pos);
                    Morph ms = new Morph(t, pos, netData);
                    hasmatch = AddSearchFor(t, pos, list);

                    //TODO: if this isn't reset then morphs aren't checked on subsequent searches - check for side effects of resetting this manually
                    if (!hasmatch)
                    {
                        string m;
                        // loop through morphs (if there are any)
                        while ((m = ms.Next()) != null)
                        {
                            if (m != t)
                            {
                                ss += netData.Is_defined(m, pos);
                                AddSearchFor(m, pos, list);
                            }
                        }
                    }
                }
            }

            b   = ss?.NonEmpty ?? false;
            obj = ss;
        }
Ejemplo n.º 2
0
        public string Next()
        {
            string word, tmp;
            int    cnt, st_idx = 0, end_idx1, end_idx2;

            /* first time through for this string */
            if (firsttime)
            {
                firsttime = false;
                cnt       = str.Split('_').Length;
                svprep    = 0;

                /* first try exception list */
                e = new Exceptions(str, pos, netData);
                if ((tmp = e.Next()) != null && tmp != str)
                {
                    svcnt = 1; /* force next time to pass NULL */
                    return(tmp);
                }
                /* then try simply morph on original string */
                if (pos.Key != "verb" && ((tmp = Morphword(str)) != null) && str != tmp)
                {
                    return(tmp);
                }

                int prep;
                if (pos.Key == "verb" && cnt > 1 && (prep = Hasprep(str, cnt)) != 0)
                {
                    svprep = prep;
                    return(Morphprep(str));
                }
                else
                {
                    svcnt = cnt = str.Split('_').Length;
                    while (--cnt > 0)
                    {
                        end_idx1 = str.Substring(st_idx).IndexOf('_') + st_idx;
                        end_idx2 = str.Substring(st_idx).IndexOf('-') + st_idx;
                        int    end_idx;
                        string append;
                        if (end_idx1 >= st_idx && end_idx2 >= st_idx)
                        {
                            if (end_idx1 < end_idx2)
                            {
                                end_idx = end_idx1;
                                append  = "_";
                            }
                            else
                            {
                                end_idx = end_idx2;
                                append  = "-";
                            }
                        }
                        else if (end_idx1 >= st_idx)
                        {
                            end_idx = end_idx1;
                            append  = "_";
                        }
                        else
                        {
                            end_idx = end_idx2;
                            append  = "-";
                        }
                        if (end_idx < 0)
                        {
                            return(null);
                        }

                        word = str.Substring(st_idx, end_idx - st_idx);
                        if ((tmp = Morphword(word)) != null)
                        {
                            searchstr += tmp;
                        }
                        else
                        {
                            searchstr += word;
                        }

                        searchstr += append;
                        st_idx     = end_idx + 1;
                    }
                    word = str.Substring(st_idx);
                    if ((tmp = Morphword(word)) != null)
                    {
                        searchstr += tmp;
                    }
                    else
                    {
                        searchstr += word;
                    }

                    if (searchstr != str && netData.Is_defined(searchstr, pos).NonEmpty)
                    {
                        return(searchstr);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else  // not firsttime
            {
                if (svprep > 0)
                {
                    svprep = 0;
                    return(null);
                }
                else if (svcnt == 1)
                {
                    return(e.Next());
                }
                else
                {
                    svcnt = 1;
                    e     = new Exceptions(str, pos, netData);
                    if ((tmp = e.Next()) != null && tmp != str)
                    {
                        return(tmp);
                    }

                    return(null);
                }
            }
        }