Beispiel #1
0
        public void translateTest()
        {
            GoogleTranslator g = new GoogleTranslator();
            string           s = g.Analytical(g.Translate("apple", "auto"));

            Assert.IsTrue(s == "苹果");
        }
        private void FinalData_Load(object sender, EventArgs e)
        {
            //this.textBox1.Text = translate(_title);
            string str = "", str2 = "";

            foreach (string s in MainWindow._tags)
            {
                str += s + ";";
            }
            this.TagsText.Text     = str;
            this.TitleText.Text    = MainWindow._title;
            this.AuthorText.Text   = MainWindow._author;
            this.PostDateText.Text = MainWindow._postdate;
            this.ContentText.Text  = MainWindow._denoisingdata;
            str = "";
            foreach (string s in MainWindow.keywords)
            {
                str += s + ";";
            }
            GoogleTranslator gt = new GoogleTranslator();

            str2 = gt.Analytical(gt.Translate(str, "auto", "auto"));
            if (str != null && str.Length > 0 && GoogleTranslator.isChineseWord(str[0]))
            {
                this.KeywordsText.Text      = str;
                this.KeywordsTransText.Text = str2;
            }
            else
            {
                this.KeywordsText.Text      = str2;
                this.KeywordsTransText.Text = str;
            }
        }
        private static string translate(string str)
        {
            if (str == null || str == "")
            {
                return(str);
            }
            GoogleTranslator googletranslator = new GoogleTranslator();

            str = googletranslator.Analytical(googletranslator.Translate(str, "auto"));
            return(str);
        }
Beispiel #4
0
        private static string translate(string str)
        {
            if (str == null || str == "")
            {
                return(str);
            }

            /*if (!isChineseWord(str[0]))
             * {
             *  GoogleTranslator googletranslator = new GoogleTranslator();
             *  //str = str + "(" + googletranslator.Analytical(googletranslator.Translate(str, "zh")) + ")";
             * }*/
            GoogleTranslator googletranslator = new GoogleTranslator();

            str = googletranslator.Analytical(googletranslator.Translate(str, "auto"));
            return(str);
        }
 /**
  * 一开始本来打算用TF-IDF算法,这样可以明显提高算法的准确度
  * 但是考虑到时间上的原因,我们简单的采用频率计算的方式
  *
  */
 private void getKeyWords()
 {
     /*int N=0,n=0;
      * SqlConnection con = Connection.instance("10.2.26.60", "XueBa", "crawler", "aimashi2015");
      * SqlCommand cmd = con.CreateCommand();
      * string countsql = "select count(distinct wid) from XueBa.dbo.WordInverseTable;";
      * cmd.CommandText = countsql;
      * SqlDataReader reader = cmd.ExecuteReader();
      * if (reader.Read())
      * {
      *  N = reader.GetInt32(0);
      * }
      * con.Close();
      * string[] list = new string[MainWindow.wordFreq.Count];
      * float[] valuelist = new float[MainWindow.wordFreq.Count];
      * MainWindow.wordFreq.Keys.CopyTo(list,0);
      * MainWindow.wordFreq.Values.CopyTo(valuelist, 0);
      *
      * float sum = 0;
      * foreach (float num in valuelist)
      * {
      *  sum += num;
      * }
      * int i = 0;
      * foreach (string word in list)
      * {
      *  int num = (int)MainWindow.wordFreq[word];
      *  float freq = num / sum;
      *  string sqlstr = string.Format("INSERT INTO XueBa.dbo.WordInverseTable(word,wid,freq) values('{0}', '{1}', '{2}')",word,MainWindow.curwid,freq);
      *  con = Connection.instance("10.2.26.60", "XueBa", "crawler", "aimashi2015");
      *  cmd = con.CreateCommand();
      *  cmd.CommandText = sqlstr;
      *  cmd.ExecuteNonQuery();
      *  con.Close();
      *
      *  countsql = string.Format("select count(distinct wid) from XueBa.dbo.WordInverseTable where word = '{0}';",word);
      *  con = Connection.instance("10.2.26.60", "XueBa", "crawler", "aimashi2015");
      *  cmd = con.CreateCommand();
      *  cmd.CommandText = countsql;
      *  reader = cmd.ExecuteReader();
      *  if (reader.Read())
      *  {
      *      n = reader.GetInt32(0);
      *  }
      *  con.Close();
      *  valuelist[i++] = freq*(float)Math.Log(1.0 * (N + 2) / n);
      * }
      * Array.Sort(valuelist,list);*/
     string[] list      = new string[MainWindow.wordFreq.Count];
     int[]    valuelist = new int[MainWindow.wordFreq.Count];
     MainWindow.wordFreq.Keys.CopyTo(list, 0);
     MainWindow.wordFreq.Values.CopyTo(valuelist, 0);
     Array.Sort(valuelist, list);
     if ((list.Length + 9) > MainWindow.maxKeyWordsNo * 10)
     {
         for (int j = 1, k = 1; k <= MainWindow.maxKeyWordsNo && j <= list.Length; j++)
         {
             if (MainWindow._stopWords.Contains(list[list.Length - j]) || Regex.IsMatch(list[list.Length - j], "^[0-9]+(\\.[0-9]+)?$"))
             {
                 continue;
             }
             else
             {
                 MainWindow.keywords.Add(list[list.Length - j]);
                 GoogleTranslator googletranslator = new GoogleTranslator();
                 MainWindow.keywords.Add(googletranslator.Analytical(googletranslator.Translate(list[list.Length - j], "auto")));
                 //MainWindow.keywords.Add(Translator.translate(list[list.Length - j]));
                 k++;
             }
         }
     }
     else
     {
         for (int j = 1, k = 1; k <= (list.Length + 9) / 10 && j <= list.Length; j++)
         {
             if (MainWindow._stopWords.Contains(list[list.Length - j]) || Regex.IsMatch(list[list.Length - j], "^[0-9]+(\\.[0-9]+)?$"))
             {
                 continue;
             }
             else
             {
                 MainWindow.keywords.Add(list[list.Length - j]);
                 GoogleTranslator googletranslator = new GoogleTranslator();
                 MainWindow.keywords.Add(googletranslator.Analytical(googletranslator.Translate(list[list.Length - j], "auto")));
                 k++;
             }
         }
     }
 }
 public FinalData()
 {
     InitializeComponent();
     googletranslator = new GoogleTranslator();
 }