Concordance function in NLTK book will not work on my corpus

947 views
Skip to first unread message

pglufkin

unread,
Nov 16, 2011, 3:25:16 PM11/16/11
to nltk-...@googlegroups.com
in the first chapter of the nltk book they have the operation

>>>text1.concordance("monstrous") and it builds and displays 11 matches in how the word 'monstrous' is used in 11 sentences.

When I add my corpus and try thescroll.concordance("God") i get this error:

Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    thescroll.concordance("God")
AttributeError: 'StreamBackedCorpusView' object has no attribute 'concordance'

My corpus works with other nltk built in functions once it is loaded, like fdist1=FreqDist(thescroll)

Please help . . . thank you.

Alexis Dimitriadis

unread,
Nov 17, 2011, 5:39:45 AM11/17/11
to nltk-...@googlegroups.com
> AttributeError: 'StreamBackedCorpusView' object has no attribute 'concordance'


PG,

The type behind PlainTextCorpusView has no method concordance(). text1-9 are objects of type Text--  you can see this by typing "type(text1)". The crucial difference is between methods, e.g., object.call(args), and plain functions like call(object).

Type Text is designed for interactive/demo use... to be honest I never quite understood why it's there, or why the NLTK book spends so much time on it. My advice would be to ignore it and base your own scripts on the rest. If you really need concordances: they're somewhere in the nltk hierarchy, you'll have to google for it. There was also some discussion on this list recently about capturing the output of concordance (instead of just printing it on the screen), so check the list archives.

Here are some python commands that will help you examine what you've got in your hands:

help(text1), type(text1), dir(text1), dir(). Also help(dir).

I'd also recommend learning about python directly (even before you're done with chapter 4 of the NLTK book). You'll find several tutorials on the python website. And of course, google is always your friend. We're always here to help if you can't find the answer yourself.

Have fun with it,

Alexis
--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nltk-users/-/eWrrO3E8AHgJ.
To post to this group, send email to nltk-...@googlegroups.com.
To unsubscribe from this group, send email to nltk-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nltk-users?hl=en.

pglufkin

unread,
Nov 17, 2011, 8:40:50 PM11/17/11
to nltk-...@googlegroups.com, alexis.di...@gmail.com
 ok, thx Alex, i will learn Python - good excuse!
Reply all
Reply to author
Forward
0 new messages