Exemplo n.º 1
0
        private KanjiListRow AddToListRow(ScrapedKanji kanji, KanjiListRow currentRow, KanjiSortedList kanjiEndList)
        {
            KanjiListRow currCopy = currentRow;

            if (!currCopy.AddKanjiToRow(kanji))
            {
                kanjiEndList.MyContent.Add(currCopy);
                currCopy = new KanjiListRow();
                currCopy.MaxColumnCount = 6;
                currCopy.AddKanjiToRow(kanji);
            }

            return(currCopy);
        }
Exemplo n.º 2
0
        private void btnTrySort_Click(object sender, EventArgs e)
        {
            folderKanjiDialog.ShowNewFolderButton = true;
            DialogResult dr = folderKanjiDialog.ShowDialog();

            if (dr == DialogResult.Abort || dr == DialogResult.Cancel)
            {
                return;
            }

            string path;

            if ((path = folderKanjiDialog.SelectedPath) == "")
            {
                return;
            }

            List <ScrapedKanji> availableKanjiList = new List <ScrapedKanji>();
            KanjiSortedList     kanjiEndList       = new KanjiSortedList();



            foreach (ListViewItem itm in lvwData.Items)
            {
                if (itm.Tag != null)
                {
                    ScrapedKanji kanji = (ScrapedKanji)itm.Tag;
                    if (kanji.Selected)
                    {
                        availableKanjiList.Add(kanji);
                    }
                }
            }

            int count = 0;

            KanjiListRow kanjiRow = new KanjiListRow();

            kanjiRow.MaxColumnCount = 6;
            string validateHiragana = "あいうえおかきくけこさしすせそはひふへほたちつてとらりるれろやゆまみむめもなにぬねのじがぎぐげごばびぶべぼだぢづでど";

            do
            {
                ScrapedKanji firstSibling = availableKanjiList[0];
                bool         firstIsKanji = true;

                if (validateHiragana.Contains(firstSibling.Word[0]))
                {
                    firstIsKanji = false;
                }

                //availableKanjiList.Remove(firstSibling);
                availableKanjiList.RemoveAll(removeKanji => removeKanji.Word.Equals(firstSibling.Word, StringComparison.InvariantCultureIgnoreCase));
                List <KanjiCompatibilityRating> ratedKanji = new List <KanjiCompatibilityRating>();

                foreach (ScrapedKanji kanjiCandidate in availableKanjiList)
                {
                    int candidateScore = 0;

                    if (kanjiCandidate.Word.Contains(firstSibling.Word))
                    {
                        candidateScore += 10;
                    }

                    if (kanjiCandidate.Word.Contains(firstSibling.Word[0]))
                    {
                        if (firstIsKanji)
                        {
                            candidateScore += 10;
                        }

                        if (kanjiCandidate.Word[0] == firstSibling.Word[0])
                        {
                            candidateScore += 10;
                        }

                        if (!firstIsKanji)
                        {
                            if (kanjiCandidate.Word[0] != firstSibling.Word[0])
                            {
                                candidateScore = 0;
                            }
                        }

                        if (candidateScore != 0)
                        {
                            foreach (char moji in firstSibling.Word)
                            {
                                if (kanjiCandidate.Word.Contains(moji))
                                {
                                    candidateScore++;
                                }
                            }
                        }
                    }

                    ratedKanji.Add(new KanjiCompatibilityRating {
                        Score = candidateScore, MyKanji = kanjiCandidate
                    });
                }


                ratedKanji = ratedKanji.OrderByDescending(mykanji => mykanji.Score).ToList <KanjiCompatibilityRating>();


                kanjiRow = AddToListRow(firstSibling, kanjiRow, kanjiEndList);

                //foreach (KanjiCompatibilityRating rk in ratedKanji)

                while (ratedKanji.Count > 0)
                {
                    KanjiCompatibilityRating rk = ratedKanji[0];

                    if (rk.MyKanji.Word.Equals("素早い", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Console.WriteLine("Found!");
                    }

                    if (rk.Score == 0)
                    {
                        break;
                    }

                    kanjiRow = AddToListRow(rk.MyKanji, kanjiRow, kanjiEndList);
                    //availableKanjiList.Remo availableKanjiList.Where(rvk => rvk.Word.Equals(rk.MyKanji.Word)).ToList();
                    //availableKanjiList.Remove(rk.MyKanji);
                    ratedKanji.RemoveAll(removeKanji => removeKanji.MyKanji.Word.Equals(rk.MyKanji.Word, StringComparison.InvariantCultureIgnoreCase));
                    availableKanjiList.RemoveAll(removeKanji => removeKanji.Word.Equals(rk.MyKanji.Word, StringComparison.InvariantCultureIgnoreCase));
                }

                //if(kanjiEndList.MyContent.Count > 30)
                //{
                //    WriteSortedListToCSV(kanjiEndList, path);
                //    break;
                //}
            }while (availableKanjiList.Count > 0);

            WriteSortedListToCSV(kanjiEndList, path);
        }