Sam Stone Sam Stone -4 years ago 61
Python Question

How would I make Python recognize categories of strings (i.e. different grammatical types of words)

I'm working on creating a program which holds a basic conversation with the user, but while thinking about how I could make this program process the user's inputs, I ran into a slight problem:

print "(Computer:)then what would you like to talk about?"
ci= raw_input("")
print "(Computer:)why do you want to talk about",ci,"?"

Most of the people I had respond to the program's question contained possessive or personal pronouns within their response, but, because the meaning of a pronoun depends upon which person is saying it, the program's response is rendered nonsensical. I have come up with two ways that I personally could correct this:

  1. I could have the program respond with a demonstrative pronoun (this, these, that, those). Though this would eliminate the issue, it makes the exchange between user and program much duller.

  2. I could manually have the program check the response for every word or contraction in the English language which contains 'I' or 'you' (or some from thereof)

However, because there just has to be a better solution to this than making the program boring or spending the rest of my days entering 'if' statements into a script; I would like to ask for help. (I apologize if there's an obvious solution to this problem, I'm still fairly new to coding).

Answer Source

Can you please ask exactly what you're looking for? answering as per my understanding. maybe you have to take a look at NLTK and similar NLP libraries, this application requires natural processing, it won't be possible to get sense out of user's input. please read about chatbots and NLP. Thanks

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download