string Chain(string word)
        {
            var buf = new StringBuilder();

            buf.Append(word);
            Word w = wordBrain[word];
            Word center;

            while (!Null(word) && w != null)
            {
                WordCandidate mychild = w.Candidates.Random();
                if (Null(mychild?.MyText))
                {
                    break;
                }
                buf.Append(mychild.MyText);
                WordCandidateChild childschild = mychild.Candidates.Random();
                if (Null(childschild?.MyText))
                {
                    break;
                }
                //buf.Append(childschild.MyText);
                center = wordBrain[mychild.MyText];
                word   = center.Candidates.Find(wc => wc.MyText == childschild.MyText)?.MyText ?? center.Candidates.Random()?.MyText;
                buf.Append(word);
                w = wordBrain[word];
            }
            return(buf.ToString());
        }
Beispiel #2
0
    public void input(string[] textVal)
    {
        this.charCount++;
        List <WordCandidate> tempList = new List <WordCandidate>();

        foreach (string text in textVal)
        {
            foreach (WordCandidate candidate in this.candidates.ToArray())
            {
                if (candidate.word.Length < this.charCount - 2)
                {
                    this.candidates.Remove(candidate);
                }

                WordCandidate temp = new WordCandidate(candidate.word, candidate.deviation);
                temp.word += text;
                tempList.Add(temp);
            }
            if (this.candidates.Count == 0 && this.charCount < 2)
            {
                tempList.Add(new WordCandidate(text, 0));
            }
            if (text != textVal[0])
            {
                tempList[tempList.Count - 1].deviation++;
            }
        }
        this.candidates.AddRange(tempList);
    }
Beispiel #3
0
 public void backspace()
 {
     if (this.charCount > 1)
     {
         this.charCount--;
     }
     foreach (WordCandidate candidate in this.candidates.ToArray())
     {
         WordCandidate temp = new WordCandidate(candidate.word, candidate.deviation);
         temp.word.Remove(temp.word.Length - 1);
         this.candidates.Add(temp);
         candidate.deviation++;
     }
 }
Beispiel #4
0
        public async Task <List <WordCandidate> > GetWordList(string term, string q_chapter)
        {
            var client = new RestClient("https://icd.who.int/ct11_2018-2/api/searchservice?theIndex=icd11_mms_en_2018-06-05&q=" + System.Web.HttpUtility.UrlDecode(term + "%") + "&chapterFilter=" + q_chapter + "useBroaderSynonyms=false&useFlexiSearch=false");
            // client.Authenticator = new HttpBasicAuthenticator(username, password);

            var request = new RestRequest(Method.GET);

            Task <IRestResponse> t = client.ExecuteTaskAsync(request);

            t.Wait();
            var restResponse = await t;
            //  Console.WriteLine(restResponse.Content);


            //    dynamic  prettyJson = JValue.Parse(restResponse.Content).ToString(Formatting.Indented); //convert json to a more human readable fashion
            dynamic searchResult       = JsonConvert.DeserializeObject(restResponse.Content);
            List <WordCandidate> wlist = new List <WordCandidate>();

            var           wordlist = searchResult.words;
            var           chapters = searchResult.searchQuery.chapterFilters;
            List <string> clist    = new List <string>();

            foreach (var chap in chapters)
            {
                clist.Add(Convert.ToString(chap));
            }

            chapterList = clist;

            foreach (var word in wordlist)
            {
                WordCandidate wc = new WordCandidate();
                wc.Label = word.label;
                wlist.Add(wc);
            }

            return(wlist);
        }
        /// <summary>
        /// 文を学習します。
        /// </summary>
        /// <param name="texts"></param>
        /// <param name="timeStamp"></param>
        public void Learn(string texts, DateTime timeStamp)
        {
            if (texts.Length == 0)
            {
                return;
            }
            texts = Regex.Replace(texts, "<[@#].+?>", "");
            // 改行を統一
            texts = texts.Replace("\r\n", "\n").Replace('\r', '\n');
            // 改行で区切って繰り返し学習
            foreach (var text in texts.Split('\n'))
            {
                string[] list = Split(text);
                if (list.Length == 0)
                {
                    continue;
                }
                string now = "", next, nenext;

                if (prevList != null && prevList.Length > 0)
                {
                    // 前の発言の最後の単語を取り出す
                    var prevWord = prevList.LastOrDefault();
                    // その単語が記憶されてなかったら追加しておく

                    if (!wordBrain.ContainsKey(prevWord))
                    {
                        wordBrain.Add(prevWord, new Word(prevWord));
                    }
                    // その単語の\0候補の子候補リストに、今の発言の最初の単語を加える
                    wordBrain[prevWord].Add("\0", timeStamp).Add(list[0], timeStamp);

                    if (!wordBrain.ContainsKey("\0"))
                    {
                        wordBrain.Add("\0", new Word("\0"));
                    }
                    WordCandidate wc = wordBrain["\0"].Add(list[0], timeStamp);
                    if (list.Length > 1)
                    {
                        wc.Add(list[1], timeStamp);
                    }
                }

                for (var i = 0; i < list.Length; i++)
                {
                    now    = list[i];
                    next   = i < list.Length - 1 ? list[i + 1] : "\0";
                    nenext = i < list.Length - 2 ? list[i + 2] : "\0";
                    if (!wordBrain.ContainsKey(now))
                    {
                        wordBrain[now] = new Word(now);
                    }
                    WordCandidate wc = wordBrain[now].Add(next, timeStamp);
                    if (!Null(nenext))
                    {
                        wc.Add(nenext, timeStamp);
                    }
                }
                lengthBrain.Add(text.Length);
                prevList = list;
            }
        }