开发者

Creating a simple dictionary using WordNet

开发者 https://www.devze.com 2023-03-14 11:38 出处:网络
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: h开发者_如何学JAVAttp://wordnetweb.princeton.edu/per

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: h开发者_如何学JAVAttp://wordnetweb.princeton.edu/perl/webwn?s=car

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消