私はかなりの量の SO に潜んでいて、かなりの量の検索と読み取りを行ってきましたが、プログラミング全般の初心者であることも告白しなければなりません。私は学びながら学ぼうとしているので、Python の NLTK で遊んでいます。以下のスクリプトでは、マルチスクリーン出力の最初の画面となるものだけを記述することを除いて、すべてを機能させることができます。少なくとも、それが私が考えている方法です。
スクリプトは次のとおりです。
#! /usr/bin/env python
import nltk
# First we have to open and read the file:
thefile = open('all_no_id.txt')
raw = thefile.read()
# Second we have to process it with nltk functions to do what we want
tokens = nltk.wordpunct_tokenize(raw)
text = nltk.Text(tokens)
# Now we can actually do stuff with it:
concord = text.concordance("cultural")
# Now to save this to a file
fileconcord = open('ccord-cultural.txt', 'w')
fileconcord.writelines(concord)
fileconcord.close()
出力ファイルの先頭は次のとおりです。
Building index...
Displaying 25 of 530 matches:
y . The Baobab Tree : Stories of Cultural Continuity The continuity evident
regardless of ethnicity , and the cultural legacy of Africa as well . This Af
530 件の一致全体をファイルに書き込むために、ここで何が欠けていますか?