基於《美國當代英語語料庫COCA詞頻20000》提取的純單詞文件


最近在背單詞,為了能提高效率,找到一個比較有名的《美國當代英語語料庫COCA詞頻20000 》

來源應該是:http://www.wordfrequency.info/,當然是收費的。

免費的可以在這里下載pdf文件:http://vdisk.weibo.com/s/ctvvyfhPYLfj

由於是pdf文件,且包含大量其他不太有用的信息,就想到提純。

花了半小時寫了個小程序,對pdf文件進行提煉。

這個下載https://sourceforge.net/projects/pdfbox/?source=typ_redirect的相關pdf讀取的dll。

 

 引用上面4個dll,代碼如下

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using org.pdfbox.pdmodel;
 7 using org.pdfbox.util;
 8 using System.IO;
 9 
10 namespace ConsoleApplication6
11 {
12     class Program
13     {
14         public static void pdf2txt(FileInfo pdffile, FileInfo txtfile)
15         {
16 
17             PDDocument doc = PDDocument.load(pdffile.FullName);
18 
19             PDFTextStripper pdfStripper = new PDFTextStripper();
20 
21             string text = pdfStripper.getText(doc);
22 
23             StreamWriter swPdfChange = new StreamWriter(txtfile.FullName, false, Encoding.GetEncoding("gb2312"));
24 
25             swPdfChange.Write(text);
26 
27             swPdfChange.Close();
28 
29         }
30         static void Main(string[] args)
31         {
32             pdf2txt(new FileInfo(@"C:\Users\pchome\Desktop\美國當代英語語料庫COCA詞頻20000.pdf"), new FileInfo(@"C:\Users\pchome\Desktop\output.txt"));
33 
34         }
35      
36     }
37 }

生成output.txt文件,里面包含了pdf文件里的所有內容,不過是排除了格式的。內容大致如下:

然后按照文本文件的排版規律,寫了個提純程序:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using org.pdfbox.pdmodel;
 7 using org.pdfbox.util;
 8 using System.IO;
 9 
10 namespace ConsoleApplication6
11 {
12     class Program
13     {
14         static void Main(string[] args)
15         {
16             FileStream fs = new FileStream(@"C:\Users\pchome\Desktop\ok.txt", FileMode.Create);
17             StreamWriter sw = new StreamWriter(fs);
18 
19             StreamReader sr = File.OpenText(@"C:\Users\pchome\Desktop\output.txt");
20             string str = "";
21             int counter = 0;
22             string word;
23             string chix;
24             
25             while ((str = sr.ReadLine()) != null)
26             {
27                 var lst = str.Split(' ');
28                 try
29                 {
30                     int seq = Convert.ToInt32(lst[0]);
31                     if (counter + 1 == seq)
32                     {
33                         counter += 1;//詞頻
34                         word = Convert.ToString(lst[1]);//單詞
35                         chix = Convert.ToString(lst[2]);//詞性
36                         string content = counter.ToString() + " " + word + "    " + chix;
37                         sw.WriteLine(content);
38                         Console.WriteLine(content);
39                     }
40                 }
41                 catch
42                 {
43                 }
44             }
45 
46             sr.Close();
47             //清空緩沖區
48             sw.Flush();
49             //關閉流
50             sw.Close();
51             fs.Close();
52 
53         }
54     }
55 }

最終得到了一個包含 詞頻 + 單詞 + 詞性 的文本文件。

可以各位同學導入到其他背單詞軟件里,進行學習了

 

 文件下載

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM