我很驚喜地發現使用iTextSharp從pdf文件中提取文本是多麼容易。通過以下this article,我能得到一個PDF文件轉換用這個簡單的代碼到文本:什麼算法可以將文本分解爲其組成單詞?
string pdfFilename = dlg.FileName;
// Show just the file name, without the path
string pdfFileNameOnly = System.IO.Path.GetFileName(pdfFilename);
lblFunnyMammalsFile.Content = pdfFileNameOnly;
string textFilename = String.Format(@"C:\Scrooge\McDuckbilledPlatypus\{0}.txt", pdfFileNameOnly);
PDFParser pdfParser = new PDFParser();
if (!pdfParser.ExtractText(pdfFilename, textFilename))
{
MessageBox.Show("there was a boo-boo");
}
的問題是,在文本文件中生成包含這樣的文本(也就是沒有空格):
IwaspleasantlysurprisedtofindhoweasyitistouseiTextSharptoextractthetextfromatextfile.
是否有一個算法「在那裏」,將採取這樣的文本,並作出一個最好的猜測,這個詞斷裂(AKA「空間」)應該去哪裏?
我會說最好解決爲什麼你的文本提取不包含空格,然後試圖破解你爲自己創建的新問題的解決方案。 – 2012-07-08 05:04:57
[Watch Peter Norvig在數據的不合理有效性中使用詞分詞](http://youtu.be/yvDCzhbjYWs?t=18m10s),知道你的答案 – Alexander 2012-07-08 09:06:44
@Gavin:因爲我使用這個第三方代碼來做到最難的部分,我對這種事情發生的原因沒有太多的控制,也不會把它稱爲我爲自己創造的問題。 – 2012-07-08 18:29:42