Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a simple dictionary using WordNet

Tags:

php

mysql

wordnet

I'm installing WordNet in MySQL from http://www.semantilog.org/wn2sql.html

I'd like to display the data in the same way as Princeton's webpage: http://wordnetweb.princeton.edu/perl/webwn?s=car

How would I query the database to do that? I'm using PHP.

like image 929
Chad Avatar asked Jun 19 '11 21:06

Chad


1 Answers

From what I gather from the documentation on the website, it seems you need to query three tables.

First you query the word table in order to get it's wordno, a unique number each word has. It would look something like this.

//assuming you've connected to your MySQL db
$word=$_GET['s']; //This variable stores the value given through url
if (ctype_alpha($word)){ // If it's alphabetical
  $word_clean=mysql_real_escape_string($word); //Sanitize it for MySQL
}else{
  //Not a valid word, error handle
  exit();
}
$query='SELECT wordno FROM word WHERE lemma=`$word_clean` LIMIT 1';
$result=mysql_query($query);

Next, we need to query the sense table in order to get the synsetno, which'll output the different senses of the word. Ex: can (noun) and can (verb), each have a unique number which is the synsetno

The MySQL query will be something along the lines of:

$query='SELECT synsetno FROM sense WHERE wordno=`$wordno`';

For each result you get from that query, you'll have to query the synset table to get the definition of each sense. Can (noun) and can (verb) have different definitions. The query for each synsetno.

$query='SELECT definition FROM synset WHERE synsetno=`$synset`';

And presto! You have yourself a pretty cool dictionary. It is a pain on the CPU, however, to have to query three tables, each with a ton of records.

like image 200
Joseph Szymborski Avatar answered Sep 30 '22 13:09

Joseph Szymborski