1.2 网络和聊天文本

虽然古腾堡项目包含成千上万的书籍,它代表既定的文学。考虑较不正式的语言也是很重要的。NLTK 的网络文本小集合的内容包括 Firefox 交流论坛,在纽约无意听到的对话, 加勒比海盗 的电影剧本,个人广告和葡萄酒的评论:

  1. >>> from nltk.corpus import webtext
  2. >>> for fileid in webtext.fileids():
  3. ... print(fileid, webtext.raw(fileid)[:65], '...')
  4. ...
  5. firefox.txt Cookie Manager: "Don't allow sites that set removed cookies to se...
  6. grail.txt SCENE 1: [wind] [clop clop clop] KING ARTHUR: Whoa there! [clop...
  7. overheard.txt White guy: So, do you have any plans for this evening? Asian girl...
  8. pirates.txt PIRATES OF THE CARRIBEAN: DEAD MAN'S CHEST, by Ted Elliott & Terr...
  9. singles.txt 25 SEXY MALE, seeks attrac older single lady, for discreet encoun...
  10. wine.txt Lovely delicate, fragrant Rhone wine. Polished leather and strawb...

还有一个即时消息聊天会话语料库,最初由美国海军研究生院为研究自动检测互联网幼童虐待癖而收集的。语料库包含超过 10,000 张帖子,以“UserNNN”形式的通用名替换掉用户名,手工编辑消除任何其他身份信息,制作而成。语料库被分成 15 个文件,每个文件包含几百个按特定日期和特定年龄的聊天室(青少年、20 岁、30 岁、40 岁、再加上一个通用的成年人聊天室)收集的帖子。文件名中包含日期、聊天室和帖子数量,例如10-19-20s_706posts.xml包含 2006 年 10 月 19 日从 20 多岁聊天室收集的 706 个帖子。

  1. >>> from nltk.corpus import nps_chat
  2. >>> chatroom = nps_chat.posts('10-19-20s_706posts.xml')
  3. >>> chatroom[123]
  4. ['i', 'do', "n't", 'want', 'hot', 'pics', 'of', 'a', 'female', ',',
  5. 'I', 'can', 'look', 'in', 'a', 'mirror', '.']