Exemplo n.º 1
0
        public static DistinctString Convert(DistinctString tweet)
        {
            //------形態素解析を使わない処理

            {
                //----------区切る前の処理
                //文字列の追加 -> rebuilder.ReserveAddition()
                //文字列の削除 -> rebuilder.ReserveDeletion()
                StringRebuilder rebuilder = new StringRebuilder(tweet);

                //TODO: >>>>>>>>>>>>>>>お願いまるた<<<<<<<<<<<<<<<<<<<

                tweet = rebuilder.Rebuild();
            }

            //----------区切る処理
            DistinctString[] sentences = tweet.Split(new Char[] {
                '、',    //、
                '。',    //。
                '\n',   //改行
                ',',    //,
                '.',    //.
                ' ',    //全角空白
                ' ',    //半角空白
                '?',
                '?',
                '!',
                '!',
                '「',
                '」'
            });
            //----------

            {
                //----------区切った後の処理
                for (int i = 0; i < sentences.Length; i++)
                {
                    StringRebuilder rebuilder = new StringRebuilder(sentences[i]);

                    //TODO: >>>>>>>>>>>>>>>お願いまるた<<<<<<<<<<<<<<<<<<<

                    for (int j = 0; j < sentences[i].Str.Length; j++)
                    {
                        for (int b = 0; b < source.Length; b++)
                        {
                            if (source[b].Length + j <= sentences[i].Str.Length && sentences[i].Str.Substring(j, source[b].Length) == source[b])
                            {
                                rebuilder.ReserveDeletion(j, source[b].Length);
                                rebuilder.ReserveAddition(j, target[b]);
                            }
                        }
                    }

                    for (int j = 1; j < sentences[i].Str.Length; j++)
                    {
                        //5000兆円欲しい
                        if (sentences[i].Str[j] == '円')
                        {
                            int index = j - 1;
                            for (int k = j - 1; k >= 0; k--)
                            {
                                if (!Util.IsHalfByRegex(sentences[i].Str[k]))
                                {
                                    break;
                                }
                                index = k;
                            }
                            rebuilder.ReserveDeletion(index, j - index);
                            rebuilder.ReserveAddition(index, "5000兆");
                        }
                    }

                    sentences[i] = rebuilder.Rebuild();
                }
            }

            //------

            DistinctString res = new DistinctString("");

            foreach (DistinctString sentence in sentences)
            {
                List <int>           parentIndeces;
                List <List <IWord> > parsedSentence = ParseSentence(sentence, out parentIndeces);
                //------形態素解析を使う処理(処理済み文字列はresに順次追加)
                //Wordの削除 -> 普通に parsedSentence:List から削除していい
                //Wordの追加 -> new Word(string)を parsedSentence 任意の場所に追加

                //TODO: >>>>>>>>>>>>>>>お願いまるた<<<<<<<<<<<<<<<<<<<
                parsedSentence = WeakClauseDeleter.Delete(parsedSentence, parentIndeces);

                //------
                foreach (List <IWord> list in parsedSentence)
                {
                    foreach (IWord s in list)
                    {
                        res.Connect(s.ToKanji());
                    }
                }
            }
            return(res);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DistinctString  pastStr   = new DistinctString(textBox.Text);
            StringRebuilder rebuilder = new StringRebuilder(pastStr);

            /*Random rand = new Random();
             * int p = rand.Next(Math.Max(1, pastStr.Str.Length/2)), cnt = rand.Next(pastStr.Str.Length - p) + 1;
             * rebuilder.ReserveDeletion(p, cnt);
             * rebuilder.ReserveAddition(p, "lattemaltamalta");
             * DistinctString newStr = rebuilder.Rebuild();*/
            DistinctString newStr = TweetConverter.Convert(pastStr);

            try
            {
                tokens.Statuses.Update(newStr.Str);
            }
            catch (Exception ex)
            {
                MessageBox.Show("ツイート出来ませんでした。");
            }

            List <Point> pastPos = getPos(pastStr.Str);
            List <Point> newPos  = getPos(newStr.Str);

            textBox.Text       = "";
            textBox.Visibility = Visibility.Hidden;
            chars = new List <TextBox>();
            for (int i = 0; i < newStr.Str.Length; i++)
            {
                TextBox charBox = new TextBox();
                charBox.FontFamily      = textBox.FontFamily;
                charBox.FontSize        = textBox.FontSize;
                charBox.Text            = newStr.Str[i].ToString();
                charBox.BorderThickness = new Thickness(0);
                charBox.Background      = Brushes.Transparent;
                charBox.IsReadOnly      = true;
                chars.Add(charBox);
                canvas.Children.Add(charBox);

                int id = newStr.Ids[i];
                if (id == -1)
                {
                    Canvas.SetLeft(charBox, newPos[i].X);
                    Canvas.SetTop(charBox, newPos[i].Y);
                    getAppearanceAnimation(charBox).Begin();
                }
                else
                {
                    Canvas.SetLeft(charBox, pastPos[id].X);
                    Canvas.SetTop(charBox, pastPos[id].Y);

                    //TODO: Beginしっぱなしでいいのか?
                    getTranslationalAnimation(charBox, new PropertyPath("(Canvas.Left)"), newPos[i].X).Begin();
                    getTranslationalAnimation(charBox, new PropertyPath("(Canvas.Top)"), newPos[i].Y).Begin();
                }
            }
            timer          = new DispatcherTimer();
            timer.Interval = animationTime.TimeSpan + TimeSpan.FromMilliseconds(1000);
            timer.Tick    += (s, e_) =>
            {
                timer.Stop();
                foreach (TextBox charBox in chars)
                {
                    canvas.Children.Remove(charBox);
                }
                textBox.Visibility = Visibility.Visible;
            };
            timer.Start();
        }