最近在背单词,为了能提高效率,找到一个比较有名的《美国当代英语语料库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 }
最终得到了一个包含 词频 + 单词 + 词性 的文本文件。
可以各位同学导入到其他背单词软件里,进行学习了