I'm writing a program that attempts to derive meaning from natural language. The program will accept a String, and see if it contains certain combinations of words. See the following code snippet for an example:
if (phrase.contains("turn")) { // turn something on/off
if (phrase.contains("on") && !phrase.contains("off")) { // turn something ON
if (phrase.contains("pc") || phrase.contains("computer")) // turn on computer
turnOnComputer();
else if (phrase.contains("light") || phrase.contains("lamp")) // turn on lights
turnOnLights();
else
badPhrase();
}
else if (phrase.contains("off") && !phrase.contains("on")) { // turn something OFF
if (phrase.contains("pc") || phrase.contains("computer")) // turn off computer
turnOffComputer();
else if (phrase.contains("light") || phrase.contains("lamp")) // turn off lights
turnOffLights();
else
badPhrase();
}
else {
badPhrase();
}
}
else {
badPhrase();
}
As you can see, this can quickly become an unmanageable mess of code if I want to interpret more than a few meanings. How can I manage this better?
Apache OpenNLP is a machine learning based toolkit for the processing of natural language text.
It includes a sentence detector, a tokenizer, a parts-of-speech (POS) tagger, and a treebank parser.
Manual for NLP
Download
Hope it helps ; )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With