使用 WordNet 创建一个简单的字典

发布于 2024-11-16 05:14:55 字数 293 浏览 4 评论 0原文

我正在从 http://www.semantilog.org/wn2sql.html 在 MySQL 中安装 WordNet

我想以与普林斯顿网页相同的方式显示数据:http://wordnetweb.princeton.edu/perl/webwn?s=car

我如何查询数据库这样做吗?我正在使用 PHP。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哽咽笑 2024-11-23 05:14:55

从我从网站上的文档中收集到的信息来看,您似乎需要查询三个表。

首先,您查询 word 表以获得其 wordno,即每个单词具有的唯一编号。它看起来像这样。

//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);

接下来,我们需要查询sense表以获得synsetno,它将输出单词的不同含义。例如:can(名词)和can(动词),每个都有一个唯一的编号,即 synsetno

MySQL 查询将类似于:

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

对于从该查询中获得的每个结果,您'你必须查询synset表来获取每个意义的定义。 Can(名词)和can(动词)有不同的定义。每个 synsetno 的查询。

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

很快!你自己有一本很酷的字典。然而,必须查询三个表,每个表都有大量记录,这对 CPU 来说是一种痛苦。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文