I try to use nps_chat corpora provided by nltk library. I follow the example given here. In particular, I can reproduce this results:

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

However, I cannot figure out who says what. I mean, I do see posts (messages) but I do not know who is the author. Is it possible to determine the author? Of course I do understand that the real author cannot be given but is there anonymized authorship? If it is the case, can I find somewhere dialog corpora with authorship?


As stated here, the corpus is a bunch of XML files in which the authors are encoded as an attribute value to a post element:
enter image description here

To view the individual XML files in an editor (because this will help you understanding their strcture), just go to the directory where it is stored (default directories are given here).

If you want to use it in Python:

nps_chat.posts('10-19-20s_706posts.xml') seems to be a function provided by the corpus reader that returns a list of posts (which are again lists of words) and extracts only the inner elements, ignoring attributes in the XML elements.
The documentation together with the source code for the reader can be found here.
I'm too lazy now to go through it in all deatil, but it should be easy to find out whether there is an already implemented function that enables you to return the author of a post.

If you need to process the author within your code (because you could otherwise just look at the raw XML) and the reader doesn't provide such a function already, you probably need to write one on your own.
It shouldn't be too hard actually, there are good libraries to process some XML files - more precisely, the reader makes use of a special XML Corpus Reader - and while writing, you can cheat by looking at the already provided fuctions. Actually you'd just need to check what the posts function exactly does and modify it so as to return not just the inner elements of a post but also the value that is stored in the user attribute (you'd need to consider then how to bring the return type together with the word list, because you can not return both the word list and the user name in one element, so you'd need e.g. an additional function returning only the user, or one combining both somehow), but that should be doable, as soon as you have managed to access an individual post with an XML parser.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.