入門自然言語処理・演習問題2.8にて

7番の問にて。

「これまで扱ったさまざまなテキストについて〜(中略)〜コンコーダンスツールを使って調査してみよう。」

1章の最初の方でconcordanceやらsimilarやら出てきたな、と薄っすら思い出しつつ、3つ前の問題で使ったstate_unionコーパスでやってみるかと気楽に入力してみる。しかし

>>> state = state_union.words()
>>> state.concordance('however')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'ConcatenatedCorpusView' object has no attribute 'concordance'

エラー。

state_union.words()のクラス'ConcatenatedCorpusView'はconcordanceメソッドを持っていないらしい。

1章で何事もなくconcordance, similarを使えていたtext1~text9はいったい何者だったんだと調べると、

>>> type(text1)

textモジュールのTextクラス、と読んでいいのかな。とりあえずこのクラスに変換すればいいだろうか。ライブラリのtext.pyをざっと見る。どうやら

>>> state = Text(state_union.words()) #Textメソッド
とすれば
 
>>> type(state)

変換できた。(ここで変換という言葉を使うのが適切なのかは自分の現在のレベルからは不明です)
これで目的達成!!

>>> state.concordance('however')
Building index...
Displaying 25 of 92 matches:
impunity at any mountain retreat - however distant . In this shrinking world ,
roblems of staggering proportions . however , with the faith of our fathers in
interests . Neither do we propose , however , to ignore the ideals and vital in
challenging task . In my judgment , however , the Council has made encouraging
standing accomplishment . We know , however , that nothing is as dangerous as o