CodeIgniter Forums
Processing natural language - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Processing natural language (/showthread.php?tid=9209)



Processing natural language - El Forum - 06-17-2008

[eluser]bapobap[/eluser]
Does anyone know of any good resources, books, tips, ideas even code on how to handle natural language?

I was hoping to make my search code a lot better by making it more human friendly and able to recognise (as best as a computer can) certain key words.

A 10-minute google hasn't come up with much other than research papers which are way too complicated.

Any ideas?

Thanks!


Processing natural language - El Forum - 06-17-2008

[eluser]xwero[/eluser]
The simplest code to identify some keywords is
Code:
$keywords = array('who', 'what', 'where', 'how much', 'how to', 'contains');
$found_keywords = array();
$search_words = str_word_count($_POST['search'], 2); // the 2 is to get the keyword position as key in the array

foreach($keywords as $keyword)
{
   if(($position = array_search($keyword,$search_words)) !== FALSE)
   {
        $found_keywords[] = array($keyword,$position);
   }
}
Then you can build on the $found_keywords to get the values you need to build the search query.


Processing natural language - El Forum - 06-17-2008

[eluser]bapobap[/eluser]
Is it best to address it in a procedural way like that? That's what I've been doing and the results haven't been as good as I would have liked, though I can't think of any other way to do it!

Thanks!


Processing natural language - El Forum - 06-17-2008

[eluser]nmweb[/eluser]
There's are reason the research papers are complicated, this subject-matter is incredibly complicated. Rather than looking at natural language handling rather look at command-line handling. Indicate a number of keywords that trigger certain searches. E.g. search query starts with 'who' then search for persons.


Processing natural language - El Forum - 06-17-2008

[eluser]xwero[/eluser]
As nmweb said if you want to identify all keywords in the search input you are going to do a lot of checks. For instance the search 'users who's name contains me'. The str_word_count will get the who with the added 's string. And the who here is only valid with the user and name parts of the search string.

There is no easy solution for this otherwise it would be floating around already Wink