gpt4 book ai didi

mysql - Wordnet 查询返回例句

转载 作者:行者123 更新时间:2023-11-29 01:53:18 24 4
gpt4 key购买 nike

我有一个用例,我需要知道以下内容:

  1. 单词的同义词(仅同义词就足够了)
  2. 单词的所有含义,其中每个含义包含 - 在该含义上与该单词匹配的同义词、该含义的例句(如果有)、该含义的词性。

示例 - this query link . carry 一词的屏幕截图:

enter image description here

对于每个“意义”,我们都有词性(如 V),与该意义匹配的同义词,(如第一种意义上的 transport pack, take 在第二个意义上,等),在那个意义上包含那个词的例句(This train is carrying nuclear waste, carry the手提箱到汽车等,在第一种意义上,我总是带着钱,在第二种意义上,等等)。

我如何从 Wordnet MySQL database 执行此操作? ?我运行了这个查询,它返回了单词的含义列表:

SELECT a.lemma, c.definition FROM words a INNER JOIN 感觉 b ON a.wordid = b.wordid INNER JOIN synsets c ON b.synsetid = c.synsetid WHERE a.lemma = 'carry';

如何获取每个意义的同义词、例句、词性以及特定于该意义的同义词?我查询了 vframesentencesvframesentencemaps 表,看到了带有 %s 等占位符的例句,并基于 wordid我试图将它们与 words 表匹配,但得到了非常错误的结果。

编辑:

对于单词 carry,如果我运行这些查询,我会得到正确的同义词和意义:

1. select * from words where lemma='carry' //yield wordid as 21354
2. select * from senses where wordid=21354 //yield 41 sysnsetids, like 201062889
3. select * from synsets where synsetid=201062889 //yields the explanation "serve as a means for expressing something"
4. select * from senses where synsetid=20106288` /yields all matching synonyms for that sense as wordids, including "carry" - like 21354, 29630, 45011
5. select * from words where wordid=29630 //yields 'convey'

所以我现在需要的是一种在 41 种感官中的每一种中找到单词 carry 的例句的方法。我该怎么做?

最佳答案

您可以从samples 表中获取句子。例如:

SELECT sample FROM samples WHERE synsetid = 201062889;

产量:

The painting of Mary carries motherly love

His voice carried a lot of anger

因此您可以按如下方式扩展您的查询:

SELECT 
a.lemma AS `word`,
c.definition,
c.pos AS `part of speech`,
d.sample AS `example sentence`,
(SELECT
GROUP_CONCAT(a1.lemma)
FROM
words a1
INNER JOIN
senses b1 ON a1.wordid = b1.wordid
WHERE
b1.synsetid = b.synsetid
AND a1.lemma <> a.lemma
GROUP BY b.synsetid) AS `synonyms`
FROM
words a
INNER JOIN
senses b ON a.wordid = b.wordid
INNER JOIN
synsets c ON b.synsetid = c.synsetid
INNER JOIN
samples d ON b.synsetid = d.synsetid
WHERE
a.lemma = 'carry'
ORDER BY a.lemma , c.definition , d.sample;

注意:带有 GROUP_CONCAT 的子选择将每个含义的同义词作为逗号分隔的列表返回到单行中,以减少行数。如果愿意,您可以考虑在单独的查询中返回这些(或作为此查询的一部分,但其他所有内容都重复)。

更新如果您确实需要同义词作为结果中的行,可以使用以下方法,但我不推荐这样做:同义词和例句都属于特定定义,因此同义词集将为每个例句重复。例如。如果某个特定定义有 4 个例句和 5 个同义词,则仅针对该定义,结果将有 4 x 5 = 20 行。

SELECT 
a.lemma AS `word`,
c.definition,
c.pos AS `part of speech`,
d.sample AS `example sentence`,
subq.lemma AS `synonym`
FROM
words a
INNER JOIN
senses b ON a.wordid = b.wordid
INNER JOIN
synsets c ON b.synsetid = c.synsetid
INNER JOIN
samples d ON b.synsetid = d.synsetid
LEFT JOIN
(SELECT
a1.lemma, b1.synsetid
FROM
senses b1
INNER JOIN words a1 ON a1.wordid = b1.wordid) subq ON subq.synsetid = b.synsetid
AND subq.lemma <> a.lemma
WHERE
a.lemma = 'carry'
ORDER BY a.lemma , c.definition , d.sample;

关于mysql - Wordnet 查询返回例句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35601052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com