数据库
首页 > 数据库> > mysql-Wordnet查询以返回例句

mysql-Wordnet查询以返回例句

作者:互联网

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

>单词的同义词(仅同义词就足够了)
>单词的所有含义,每个含义包含-与该单词匹配的同义词,该含义的例句(如果存在),该含义的词性.

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

enter image description here

对于每个“感觉”,我们都有词性(例如V),与该意义相匹配的同义词(例如在第一个意义上的运输,包装,在第二个意义上采用等),包含该意义上的单词的例句(这列火车从第一个意义上讲是运载核废料,将手提箱运至汽车等,从第二个意义上讲,我总是运钱等).

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

从单词中选择a.lemma,c.definition a INNER JOIN感测b ON

如何获得每种感觉的同义词,例句,词性和特定于该感觉的同义词?我查询了vframesentences和vframesentencemaps表,看到了带有%s之类占位符的示例句子,并且基于wordid列,我试图将它们与words表进行匹配,但结果却非常错误.

编辑:

对于进位一词,如果我运行以下查询,则会正确获得同义词和含义:

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”一词的例句的方法.我该怎么做?

解决方法:

您可以从样本表中获取句子.例如:

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的子选择在一行中以逗号分隔的列表形式返回每种意义的同义词,以减少行数.如果愿意,您可以考虑在单独的查询中(或作为该查询的一部分,但重复其他所有内容)返回这些内容.

UPDATE
如果您确实需要同义词作为结果中的行,则可以执行以下操作,但我不建议这样做:同义词和例句都属于特定的定义,因此对于每个例句都将重复使用同义词集.例如.如果特定定义有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;

标签:wordnet,words,sql,mysql,lexicon
来源: https://codeday.me/bug/20191009/1877639.html