コード例 #1
0
    async def define(self, ctx):

        # Create instance of wordnet, get the query from context and find synsets via WordNet.
        wordnet = WordNet(wordnet_30_dir)
        command = ctx.message.content.split(' ', 1)

        if len(command) > 1:
            query = command[1]
            synset = wordnet.synsets(query)

            # String manipulation to get a list of definitions.
            definitions = ""
            index = 1

            # Formulates the definitions.
            if len(synset) > 0:
                for syn in synset:
                    if (query in syn.name()):
                        definitions = definitions + f"{index}. [{self.categorise(syn.name())}] {syn.definition()}\n"
                        index += 1
                await ctx.message.channel.send(
                    f"```\nDefinition of {query}:\n{definitions}```")
            else:
                await ctx.message.channel.send(
                    f"Could not find requested word, doing a secondary search in Urban Dictionary..."
                )
                await self.udictHelper(ctx)
        else:
            await ctx.message.channel.send(f"```Usage: !define <word>```")
コード例 #2
0
def collect_adjectives_list():
    wordnet = WordNet()
    adjective_synsets = wordnet.all_synsets(pos='s')
    adjectives_set = set()
    for synset in adjective_synsets:
        adjectives_set.update(synset.lemma_names())
    adjectives_list = list(adjectives_set)
    adjectives_list = [
        w for w in adjectives_list if NUMERIC_PATTERN.match(w) is None
    ]
    return adjectives_list
コード例 #3
0
 def test_init(self):
     w = WordNet()
コード例 #4
0
ファイル: __init__.py プロジェクト: gauravjuvekar/pywsd
#!/usr/bin/env python -*- coding: utf-8 -*-
#
# Python Word Sense Disambiguation (pyWSD)
#
# Copyright (C) 2014-2020 alvations
# URL:
# For license information, see LICENSE.md

from __future__ import absolute_import, print_function

import sys
import time

from wn import WordNet

__builtins__['wn'] = WordNet()

__version__ = '1.2.0'

# Warm up the library.
print('Warming up PyWSD (takes ~10 secs)...', end=' ', file=sys.stderr, flush=True)
start = time.time()

import pywsd.lesk
import pywsd.baseline
import pywsd.similarity

#import semcor
#import semeval

from pywsd.allwords_wsd import disambiguate
コード例 #5
0
# Author:
# URL: <http://nltk.org/>
# For license information, see LICENSE.TXT

"""
Tests for Synset and Lemma objects.
"""

import unittest

from wn import WordNet
from wn.info import WordNetInformationContent

from wn.constants import wordnet_30_dir

our_wn = WordNet(wordnet_30_dir)

class TestAllSynsets(unittest.TestCase):
    ##@unittest.skip("Paranoid sanity checks...")
    def test_all_synsets(self):
        from nltk.corpus import wordnet as nltk_wn
        our_wn_synsets = our_wn.all_synsets()
        for nltk_ss in nltk_wn.all_synsets():
            our_ss = our_wn.synset(nltk_ss.name())
            # Test Synset attributes.
            assert nltk_ss.name() == our_ss.name()
            assert nltk_ss.offset() == our_ss.offset()
            assert nltk_ss.pos() == our_ss.pos()
            assert nltk_ss.lexname() == our_ss.lexname()
            assert nltk_ss._needs_root() == our_ss._needs_root()
コード例 #6
0
#
# Python Word Sense Disambiguation (pyWSD)
#
# Copyright (C) 2014-2020 alvations
# URL:
# For license information, see LICENSE.md

from __future__ import absolute_import, print_function

import sys
import time

from wn import WordNet
from wn.constants import wordnet_30_dir

__builtins__['wn'] = WordNet(wordnet_30_dir)

__version__ = '1.2.3'

# Warm up the library.
print('Warming up PyWSD (takes ~10 secs)...',
      end=' ',
      file=sys.stderr,
      flush=True)
start = time.time()

import nym_embeddings.pywsd.lesk

#import semcor
#import semeval
コード例 #7
0
ファイル: nameandsecret.py プロジェクト: ruler501/multipoll
def get_default_secret(max_word_length: int = 4) -> str:
    if max_word_length not in _words:
        nouns = [
            n for n in _wordnet.all_lemma_names(NOUN)
            if n.isalpha() and len(n) <= max_word_length
        ]
        adjectives = [
            a for a in _wordnet.all_lemma_names(ADJ)
            if a.isalpha() and len(a) <= max_word_length
        ]
        _words[max_word_length] = (nouns, adjectives)
    nouns, adjectives = _words[max_word_length]
    return random.choice(adjectives) + ' ' + random.choice(nouns)


_wordnet = WordNet(wordnet_30_dir)
_words: Dict[int, Tuple[List[str], List[str]]] = {}


def get_fixed_secret() -> str:
    return "secret"


class NameAndSecretForm(forms.Form):
    user_name = forms.CharField(label="Your Name:",
                                min_length=2,
                                max_length=30,
                                required=True)
    user_secret = forms.CharField(
        label="Secret (Default is randomly generated, can be blank. Used " +
        "to verify when changing responses; not securely " + "stored):",
コード例 #8
0
ファイル: forms.py プロジェクト: ruler501/simple-poll
def get_default_secret(max_word_length: int = 4):
    if max_word_length not in get_default_secret.words:
        nouns = [
            n for n in get_default_secret.wordnet.all_lemma_names(NOUN)
            if n.isalpha() and len(n) <= max_word_length
        ]
        adjectives = [
            a for a in get_default_secret.wordnet.all_lemma_names(ADJ)
            if a.isalpha() and len(a) <= max_word_length
        ]
        get_default_secret.words[max_word_length] = (nouns, adjectives)
    nouns, adjectives = get_default_secret.words[max_word_length]
    return random.choice(adjectives) + ' ' + random.choice(nouns)


get_default_secret.wordnet = WordNet(wordnet_30_dir)
get_default_secret.words = {}


class NameAndSecretForm(forms.Form):
    user_name = forms.CharField(label="Your Name:",
                                min_length=2,
                                max_length=30,
                                required=True)
    user_secret = forms.CharField(
        label=
        "Secret (Default is randomly generated or input your own, these not stored in "
        +
        "a cryptographically sound manner so do not use a password from another "  # noqa
        + "site):",
        max_length=11,