Exemplo n.º 1
0
 public void WriteDictionary()
 {
     using (Stream stream = new FileStream("words.dic", FileMode.OpenOrCreate))
     {
         List <Region>     ls      = GetAreas();
         StringBuilder     builder = new StringBuilder();
         List <FLAG_WORDS> order   = WordsUtility.FlagWords.OrderByDescending(x => x.WORD.Length).ToList();
         foreach (Region region in ls)
         {
             string[] ids = region.TreePath.Split(',');
             int[]    id  = new int[ids.Length];
             for (int i = 0; i < ids.Length; i++)
             {
                 id[i] = int.Parse(ids[i]);
             }
             WORDS w = new WORDS()
             {
                 KEY       = region.Id,
                 WORD      = region.Name,
                 TREE_PATH = id,
             };
             w.RANK = 0.1F;
             FLAG_WORDS fw = order.FirstOrDefault(z => region.Name.EndsWith(z.WORD));
             w.RANK = w.RANK / ls.Sum(x => x.Name.Contains(w.WORD) ? 1 : 0);
             if (fw != null)
             {
                 w.FLAG_KEY = fw.KEY;
                 w.RANK    += w.RANK / ls.Sum(x => x.Name.Contains(w.WORD.TrimEnd(fw.WORD)) ? 1 : 0);
             }
             w.RANK += 1.0F / w.TREE_PATH.Length;
             stream.Write(BitConverter.GetBytes(w.KEY), 0, 4);
             byte[] bw = Encoding.Unicode.GetBytes(w.WORD);
             stream.Write(BitConverter.GetBytes(bw.Length), 0, 4);
             stream.Write(bw, 0, bw.Length);
             stream.Write(BitConverter.GetBytes(w.TREE_PATH.Length), 0, 4);
             foreach (int n in w.TREE_PATH)
             {
                 stream.Write(BitConverter.GetBytes(n), 0, 4);
             }
             stream.Write(BitConverter.GetBytes(w.RANK), 0, 4);
             stream.Write(BitConverter.GetBytes(w.FLAG_KEY), 0, 4);
             string line = string.Format("{0}:【{1}】 ({2}) 【{3}】", w.KEY, w.WORD, w.RANK, region.TreePath);
             builder.AppendLine(line);
             Console.WriteLine(line);
         }
         File.AppendAllText("result.txt", builder.ToString());
     }
 }
Exemplo n.º 2
0
        protected void FixAddressLine(Address address)
        {
            if (address == null)
            {
                return;
            }
            HitWords word = address.Line.LastOrDefault(t => t != null);

            for (int i = 0; i < word.TREE_PATH.Length - 1; i++)
            {
                if (address.Line[i] == null)
                {
                    WORDS w = Utility.Find(word.TREE_PATH[i + 1]);
                    if (w != null)
                    {
                        address.Line[i] = new HitWords(w);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static string GetWord()
 {
     return(WORDS.Rand());
 }
Exemplo n.º 4
0
 public static IEnumerable <string> GetWords(int num = 3)
 {
     return(WORDS.RandPick(num));
 }
Exemplo n.º 5
0
 public string GetWord(WORDS word)
 {
     if ((byte)word >= 0 && (byte)word < NUMBEROFWORDS) //Language is not checked for propper range because its integrity protected by a setter function
     {
         return dictionary[(byte)word,(byte)Language];
     }
     Debug.WriteLine("ERROR: GetWords was passed a value {0} that was out of range(0-{1})",(byte)word,(byte)NUMBEROFWORDS);
     return "";
 }
Exemplo n.º 6
0
 public string GetWord(WORDS word)
 {
     Initialize();
     return(m_words[(int)word].GetWord((LANGUAGES)m_currentLanguage));
 }
Exemplo n.º 7
0
 public static string GetWord()
 {
     return(WORDS.RandomElement());
 }