小编wat*_*sit的帖子

如何在python nltk和wordnet中获得单词/ synset的所有下位词?

我有一个wordnet中所有名词的列表,现在我想只留下车辆中的单词并删除其余的单词.我该怎么做?下面是我想要的伪代码,但我不知道如何使其工作

for word in wordlist:
  if not "vehicle" in wn.synsets(word):
    wordlist.remove(word)
Run Code Online (Sandbox Code Playgroud)

python nltk wordnet

8
推荐指数
2
解决办法
9544
查看次数

确保用户不要垃圾邮件"喜欢"按钮

我的朋友和我正在创建一个请愿板,我正在添加一个喜欢/不喜欢的功能.我打算这样做,只有用户可以喜欢/不喜欢它.问题是,我不知道如何确保用户不多次垃圾邮件按钮以及如何注册哪个用户喜欢/不喜欢哪个主题.以下是我的代码.

编辑:谢谢我现在正在创建喜欢/不喜欢的表.但现在我必须将用户与数据库进行比较,看看他们之前是否喜欢评论.我知道我必须使用WHERE(检查喜欢和不喜欢的表),但我不知道如何将它与IF结合起来.

<?php
include connect.php

if (isset($_POST['like']) || isset($_POST['dislike'])) 
{
    if($_SESSION['signed_in']){
        if (isset($_POST['like'])) {
            $sql="UPDATE 
                    topics
                SET
                    likes=likes+1,
                WHERE
                    id=topic_id";

            echo "You liked it";
        }

        elseif (isset($_POST['dislike'])) {
            $sql="UPDATE 
                    topics
                SET
                    dislikes=dislikes+1,
                WHERE
                    id=topic_id";

            echo "You disliked it";
        }
    }
    else{
        echo 'Please log in.'
}

?>
Run Code Online (Sandbox Code Playgroud)

php

2
推荐指数
1
解决办法
270
查看次数

带有nltk.wordnet.synsets的Python IF语句

import nltk
from nltk import *
from nltk.corpus import wordnet as wn

output=[]
wordlist=[]

entries = nltk.corpus.cmudict.entries()

for entry in entries[:200]: #create a list of words, without the pronounciation since.pos_tag only works with a list
    wordlist.append(entry[0])

for word in nltk.pos_tag(wordlist): #create a list of nouns
    if(word[1]=='NN'):
        output.append(word[0])

for word in output:
    x = wn.synsets(word) #remove all words which does not have synsets (this is the problem)
    if len(x)<1:
        output.remove(word)

for word in output[:200]:
    print (word," ",len(wn.synsets(word)))
Run Code Online (Sandbox Code Playgroud)

我试图删除没有synsets的所有单词但由于某种原因它不起作用.在运行程序时,我发现即使一个单词被称为len(wn.synsets(word))= 0,它也不会从我的列表中删除.谁能告诉我出了什么问题?

python nltk wordnet

2
推荐指数
1
解决办法
474
查看次数

NLTK 仅搜索名词同义词集

这是我编写的一个函数,用于检查名词列表中是否存在上义词和下义词。

def check_hyper_hypo(wordlist):
    returnlist=[]
    for word in wordlist: #by definition a base word has a word above and below heirachy
        x = wn.synsets(word)
        for syn in x:    
            if not(((len(syn.hypernyms()))==0)or((len(syn.hyponyms()))==0)):
                returnlist.append(word)
                break
    return returnlist
Run Code Online (Sandbox Code Playgroud)

如何仅检查作为名词的同义词集的上位词/下位词的长度?例如

for syn in x:
    if ".n." in syn:
        #rest of code
Run Code Online (Sandbox Code Playgroud)

python nltk wordnet

1
推荐指数
1
解决办法
2908
查看次数

标签 统计

nltk ×3

python ×3

wordnet ×3

php ×1