Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I want to write something that takes a sentence and identifies each word it contains and defines what part of speech each word is.

For example

Hello World, I am a sentence

would return this

verb noun, pronoun verb adjective noun

Ideally, I'd like to eventually take it one step further and take a sentence and programmatically have it understand what it is trying to interpret and maybe do something about it.

So my question is, has someone heard of something like this?

share|improve this question

closed as not a real question by gnat, Yusubov, Robert Harvey, MichaelT, Kilian Foth May 29 '13 at 6:26

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
"Hello" is a verb? I mean, I don't know what else it would be, but it doesn't seem like a verb. –  Dan Ray Feb 7 '12 at 18:41
    
@DanRay: Maybe that's a question for english.stackexchange.com? –  StriplingWarrior Feb 7 '12 at 18:58
    
@DanRay haha, you see? That's why I'm trying figure out if something can do this, cause apparently I'm terrible at grammar. –  Vinny Feb 7 '12 at 19:12
    
@Vinny - Of course its possible. The problem is...this is the next trillion dollar idea, and at this time, its still not been made into a product. –  Ramhound Feb 7 '12 at 19:14
1  
@Vinny Yes, someone has heard of something like that. –  user61852 May 28 '13 at 17:47

5 Answers 5

up vote 13 down vote accepted

This is called Natural Language Processing and it's a huge, complex field. Something like you describe is a monumental achievement, and even the best solutions, like Watson, are nowhere near perfect.

Things like this make it challenging: "Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo"

a grammatically correct sentence in American English, used as an example of how homonyms and homophones can be used to create complicated linguistic constructs. It has been discussed in literature since 1972... It was also featured in Steven Pinker's 1994 book The Language Instinct as an example of a sentence that is "seemingly nonsensical" but grammatical...

The sentence's meaning becomes clearer when it's understood that it uses the city of Buffalo, New York and the somewhat-uncommon verb "to buffalo" (meaning "to bully or intimidate"), and when the punctuation and grammar is expanded so that the sentence reads as follows: "Buffalo buffalo that Buffalo buffalo buffalo, buffalo Buffalo buffalo." The meaning becomes even clearer when synonyms are used: "Buffalo bison that other Buffalo bison bully, themselves bully Buffalo bison."

share|improve this answer
    
This is what I'm looking for! Has anyone heard of anyone adapting this on a smaller scale? Open-source? Examples of this being used in smaller scales? –  Vinny Feb 7 '12 at 21:25
    
@Vinny AFAIK nothing much is available in open source as solving these issues is highly profitable to companies, like MS Word grammar detection. There are some chatter-bot programs that are available I believe though. –  Ryathal Feb 7 '12 at 21:31
    
@Vinny It's difficulty has nothing to do with scale. Natural language processing has an inherent complexity that is not reduced when you reduce the "scale". –  user61852 May 28 '13 at 17:44

Though splitting a sentence and determining the grammatical correctness along with solving your first problem is easier than your second problem, many complexities like verb-nouns or gerunds like swimming, programming, etc and other such intricacies, it still is a challenge - See Morons' answer.

But your second problem - people have put in huge efforts to find a perfect solution, but a really perfect "interpretation" algorithm is not realizable practically for any natural language like English - there are variations that will screw up your algorithm. This field - a hybrid between AI, Computer Science and Linguistics is known as NLP. Consider this: Even Google Translate is not perfect when "interpreting" sentences.

But nevertheless, this is a very interesting field to dabble with.

share|improve this answer
    
@StriplingWarrior I just wanted to contrast sufficiently between the two problems posed by the OP. Noted. Edit on its way –  yati sagade Feb 7 '12 at 18:35

I think you should start reading this Wikipedia article:

http://en.wikipedia.org/wiki/Part-of-speech_tagging

(it is a research field, don't expect any easy solution for it.)

share|improve this answer
1  
IT should be added that while NLP is huge, hard and probably intractable on today's computers, POS tagging is the easiest part of it, and with either sufficient corpus size or a lot of dedication and manual rule-writing it can be solved almost perfectly, certainly above 99% correctness. That may well be enough for your needs. –  Kilian Foth Feb 8 '12 at 8:27

Looks like Stanford has some good references:

http://nlp.stanford.edu/software/

With an interesting demo: http://nlp.stanford.edu:8080/parser/

"My dog also likes eating sausage."

"My/PRP$ dog/NN also/RB likes/VBZ eating/VBG sausage/NN"
share|improve this answer

A cheap way of doing this would be to set up a database of the dictionary (I'm almost positive that someone has done this).

Need two fields in the table: word and usage

Turn the phrase into an array of strings, (each word being a string) and independently:

select 'usage' from Dictionary WHERE 'word' = $word; 

It's a heavy solution, but one that I've used in the past.

share|improve this answer
2  
This assumes that each word has only one possible POS, and I assure you that’s not the case at all. –  microtherion May 28 '13 at 17:56
    
Agreed - there is no way this could feasibly work (at least in English) with all the words that can act as nouns, verbs, etc., depending on the context. –  Derek May 28 '13 at 19:45

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