Exemplo n.º 1
0
        public Reader_Dictionary()
        {
            Assembly currentAssembly = Assembly.GetExecutingAssembly();

            // Get all embedded resources
            string[] arrResources = currentAssembly.GetManifestResourceNames();

            Lines = ReadLines(() => Assembly.GetExecutingAssembly()
                              .GetManifestResourceStream("Domain.DataFiles.Phrases.cedict_ts.u8"),
                              Encoding.UTF8)
                    .ToList();


            foreach (string line in Lines)
            {
                if (line[0] != '#')
                {
                    Word_Dictionary w = new Word_Dictionary(line);
                    w.Level = 7;
                    Words.Add(w);
                }
            }
        }
Exemplo n.º 2
0
        private ArrayList ReverseDecompose(string input, bool checkTraditional, int FastCompute)
        {
            ArrayList result = new ArrayList();

            int textCursor = input.Length;

            while (textCursor > 0)
            {
                ArrayList Matches   = new ArrayList();
                Word      BestMatch = new Word();

                Int32 MaxLongMatch = 0;

                for (Int32 x = 1; x < textCursor + 1; x++)
                {
                    if (x > FastCompute)
                    {
                        break;                  //Fast Compute
                    }
                    //if ((textCursor + x < input.Length) || (textCursor + x == input.Length))
                    //{
                    foreach (Word w in includedWords)
                    {
                        if (w.Character == input.Substring(textCursor - x, x))
                        {
                            MaxLongMatch = x;
                            Matches.Add(w);
                            BestMatch = w;
                        }

                        //Si coincide con alguna definicion de caracteres tradicionales
                        if ((w.GetType() == typeof(Word_Dictionary)) && (checkTraditional))
                        {
                            Word_Dictionary dicw = (Word_Dictionary)w;

                            if (dicw.TraditionalCharacter == input.Substring(textCursor - x, x))
                            {
                                MaxLongMatch = x;
                                Matches.Add(w);
                                BestMatch       = w; //Se mostrara el caracter simplificado
                                BestMatch.Level = 20;
                            }
                        }

                        //Cortar ejecucion en algun numero determinado de Matches
                    }
                    //}
                } //End for Single Match

                int CountMatches = Matches.Count;

                if (CountMatches != 0)
                {
                    result.Add(BestMatch);

                    if (BestMatch.Level > level.MaxLevel)
                    {
                        level.MaxLevel = BestMatch.Level;
                    }

                    textCursor = textCursor - MaxLongMatch;
                }

                else
                {
                    result.Add(new Word {
                        Character = "X", Description = "Match not found"
                    });

                    textCursor = textCursor - 1;
                }
            }

            return(result);
        }