示例#1
0
    def labels(self, query):
        """ return parsed result """
        res = []
        meanings = vb.meaning(query, format="list")
        if meanings:
            meanings = [
                e.replace("<i>",
                          "").replace("</i>",
                                      "").replace("[i]",
                                                  "").replace("[/i]", "")
                for e in meanings
            ]
            for e in meanings:
                res.append((query, "meaning", e))
        synonyms = vb.synonym(query, format="list")
        if synonyms:
            for e in synonyms:
                res.append((query, "synonym", e))
        antonyms = vb.antonym(query, format="list")
        if antonyms:
            for e in antonyms:
                res.append((query, "antonym", e))

        #ps = vb.part_of_speech(query, format="list")
        #if ps:
        #    for e in ps:
        #        res.append((query, "part_of_speech", e))
        examples = vb.usage_example(query, format="list")
        if examples:
            for e in examples:
                res.append((query, "usage_example", e))
        return res
示例#2
0
 def query(self, query):
     """ return raw result (dict) """
     cons = {
         "meaning": [],
         "synonym": [],
         "antonym": [],
         "usage_example": [],
         "part of speech": []
     }
     meanings = vb.meaning(query, format="list")
     if meanings:
         cons["meaning"] = [
             e.replace("<i>",
                       "").replace("</i>",
                                   "").replace("[i]",
                                               "").replace("[/i]", "")
             for e in meanings
         ]
     synonyms = vb.synonym(query, format="list")
     if synonyms:
         cons["synonym"] = synonyms
     antonyms = vb.antonym(query, format="list")
     if antonyms:
         cons["antonym"] = antonyms
     ps = vb.part_of_speech(query, format="list")
     if ps:
         cons["part of speech"] = ps
     examples = vb.usage_example(query, format="list")
     if examples:
         cons["usage_example"] = [
             e.replace("[", "").replace("]", "") for e in examples
         ]
     return cons
示例#3
0
    def test_antonym_ant_key_error(self, mock_api_call):
        res = {"noun": {}, "verb": {}}

        mock_api_call.return_value = mock.Mock()
        mock_api_call.return_value.status_code = 200
        mock_api_call.return_value.json.return_value = res

        self.assertFalse(vb.antonym("love"))
示例#4
0
 def antonym(self, word):
     res = 'ANTONYMS: '
     antonyms = vb.antonym(word, format="list")
     if not antonyms:
         return False
     res += antonyms[0]
     res += self.more(antonyms[1:])
     res += self.addLine()
     return res
示例#5
0
def antonyms(dict):
    list_of_words, a = [], []
    antonyms = {}
    for value in dict.values():
        list_of_words.append(value)

    list_of_words.sort()
    for i in range(-1, -30, -1):
        for key in dict.keys():
            if dict[key] == list_of_words[i]:
                a.append(key)
    for elem in a:
        if vb.antonym(elem) != False:
            antonyms[elem] = []
            antonyms[elem].append(vb.antonym(elem, format='list'))

    for k, v in antonyms.items():
        print(f'Antonym for {k.upper()} is {v} ')
def antonym(word):
    ant = vb.antonym(word)
    if (ant == False):
        return "No Antonyms Found"
    ants = json.loads(ant)
    ret = "Antonyms are "
    i = 0
    while (i < 4 and i < len(ants)):
        ret += ants[i]['text'] + ", "
        i += 1
    ret = ret[:-2]
    return ret
示例#7
0
def wordApplications(mess):
    if mess.find("soph") == 0 and ("define" in mess or "definition" in mess
                                   or "meaning"
                                   in mess) or mess.find("define") == 0:
        word = getWord(mess)
        if word == None:
            return
        else:
            result = str(d.meaning(word))
            resultF = meaningParser(result)
            return ("***" + str(word).upper() + "*** meaning(s)" +
                    str(resultF))

    elif mess.find("soph") == 0 and ("antonym" in mess or "opposite" in mess
                                     or "different" in mess and "word"
                                     in mess) or mess.find("antonym") == 0:
        word = getWord(mess)
        if word == None:
            return
        else:
            result = str(v.antonym(word))
            resultF = parser(result)
            if resultF == None or resultF == "1.   ":
                return ("Couldn't find any :(")
            return ("**" + str(word) + "** antonym(s)\n" + str(resultF))

    elif mess.find("soph") == 0 and ("synonym" in mess
                                     or "similar to" in mess and "word"
                                     in mess) or mess.find("synonym") == 0:
        word = getWord(mess)
        if word == None:
            return
        else:
            result = str(v.synonym(word))
            resultF = parser(result)
            if resultF == None or resultF == "1.   ":
                return ("Couldn't find any :(")
            return ("**" + str(word) + "** synonym(s)\n" + str(resultF))

    mess = mess[:mess.find("d") + 1]
    revmess = mess[::-1]
    if revmess.find("drow") == 0 and mess.find(
            "soph") == 0 and " is " in mess and " a " in mess:
        word = mess[mess.find(" is ") + 4:mess.find(" a ")]
        if d.meaning(word) == None:
            return ("Well, it's not in my dictionary... :(")
        else:
            return ("Yeah, it is! :D")
示例#8
0
def get_dictionary(subject):
    cons = {"meaning": [], "synonym": [], "antonym": [], "example": [], "part of speech": []}
    meanings = vb.meaning(subject, format="list")
    if meanings:
        cons["meaning"] = [e.replace("<i>", "").replace("</i>", "").replace("[i]", "") .replace("[/i]", "") for e in meanings]
    synonyms = vb.synonym(subject, format="list")
    if synonyms:
        cons["synonym"] = synonyms
    antonyms = vb.antonym(subject, format="list")
    if antonyms:
        cons["antonym"] = antonyms
    ps = vb.part_of_speech(subject, format="list")
    if ps:
        cons["part of speech"] = ps
    examples = vb.usage_example(subject, format="list")
    if examples:
        cons["example"] = [e.replace("[", "").replace("]", "") for e in examples]
    return cons
示例#9
0
    def test_antonym_found(self, mock_api_call):
        res = {
            "noun": {
                "ant": ["hate", "dislike"]
            },
            "verb": {
                "ant": ["hate", "hater"]
            }
        }

        mock_api_call.return_value = mock.Mock()
        mock_api_call.return_value.status_code = 200
        mock_api_call.return_value.json.return_value = res

        expected_result = '[{"text": "hate", "seq": 0}, {"text": "dislike", "seq": 1}, {"text": "hater", "seq": 2}]'
        result = vb.antonym("love")

        if sys.version_info[:2] <= (2, 7):
            self.assertItemsEqual(expected_result, result)
        else:
            self.assertCountEqual(expected_result, result)
示例#10
0
def details(word):
    meaning = vb.meaning(word)
    antonym = vb.antonym(word)
    synonym = vb.synonym(word)
    usage = vb.usage_example(word)

    if meaning == False:
        meaning = 'Not Found'
    else:
        meaning = json.loads(meaning)
        # meaning = str(meaning[0]['text'])
        meaning = [unescape(meaning[i]['text']) for i in range(len(meaning))]

    if antonym == False:
        antonym = 'Not Found'
    else:
        antonym = json.loads(antonym)
        antonym = str(antonym[0]['text'])

    if synonym == False:
        synonym = 'Not Found'
    else:
        synonym = json.loads(synonym)
        synonym = str(synonym[0]['text'])

    if usage == False:
        usage = 'Not Found'
    else:
        usage = json.loads(usage)
        usage = str(usage[-1]['text'])

    values = {
        'meaning': meaning,
        'antonym': antonym,
        'synonym': synonym,
        'usage': usage
    }

    return values
示例#11
0
    def test_antonym_not_found(self, mock_api_call):
        mock_api_call.return_value = mock.Mock()
        mock_api_call.return_value.status_code = 404

        self.assertFalse(vb.antonym("love"))
示例#12
0
def getopposite(word):
    return vb.antonym(word, format="list")
示例#13
0
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    #check if bot is working
    if message.content.startswith('!heck'):
        msg = 'Heck Off {0.author.mention}'.format(message)
        await client.send_message(message.channel, msg)

    #text response
    if message.content.startswith('!venom'):
        msg = 'is cute uwu'.format(message)
        await client.send_message(message.channel, msg)

    #text response
    if message.content[0:4] == "ayy":
        await client.send_message(message.channel, "lmao".format(message))

    #text response
    if message.content[0:5] == "lmao":
        await client.send_message(message.channel, "ayy".format(message))

    #using giphy api post a random happy birthday gif
    if message.content.startswith("!hbd"):
        msg = "HAPPPY BARTHDAYYYYY "
        if len(message.mentions) > 0:
            msg += message.mentions[0].mention
        hbds = [x for x in g.search("happy birthday")]
        hbd = hbds[random.randint(0, len(hbds))]
        msg += " " + hbd.media_url
        await client.send_message(message.channel, msg)

    #tag spam a user(not recommended)
    if message.content.startswith("!tagspam"):
        msg = ""
        if len(message.mentions) > 0:
            for i in message.mentions:
                if i.mention == "<@199515135142920192>":  #hardcoded to not work against me xd
                    await client.send_message(message.channel, "Nope")
                    return
                msg += i.mention + "\t"
        else:
            msg = "Mention someone."
            await client.send_message(message.channel, msg)
            return
        if len(message.content.split(" ")) > 2:
            try:
                r = int(message.content.split(" ")[2])
                if r > 50:
                    r = 50
            except:
                r = 5
        else:
            r = 5
        for x in range(r):
            await client.send_message(message.channel, msg)

    #synonym using vocabulary api
    if message.content[0:3] == "!s ":  #match first 3 charachters
        query = message.content.split(" ")[
            1]  #seperate the content from the identifier
        result = vb.synonym(query)
        msg = ""
        if result == False:  #if no reply from api
            msg = "Not found"
        else:
            result = json.loads(result)  #parse json string
            for i in result:
                msg += i["text"] + "\n"  #add all results
        await client.send_message(message.channel, msg)

    #antonym using vocabulary api
    if message.content[0:3] == "!a ":
        query = message.content.split(" ")[1]
        result = vb.antonym(query)
        msg = ""
        if result == False:
            msg = "Not found"
        else:
            result = json.loads(result)
            for i in result:
                msg += i["text"] + "\n"
        await client.send_message(message.channel, msg)

    #usage
    if message.content[0:3] == "!u ":
        query = message.content.split(" ")[1:]
        query = ' '.join(query)
        result = vb.usage_example(query)
        msg = ""
        if result == False:
            msg = "Not found"
        else:
            result = json.loads(result)
            for i in result:
                msg += i["text"] + "\n"
        await client.send_message(message.channel, msg)

    #meaning
    if message.content[0:3] == "!m ":
        query = message.content.split(" ")[1]
        result = vb.meaning(query)
        msg = ""
        if result == False:
            msg = "Not found"
        else:
            result = json.loads(result)
            for i in result:
                msg += i["text"] + "\n"
        await client.send_message(message.channel, msg)

    #despacito
    if message.content.startswith("!despacito"):
        with open("despacito.txt") as file:
            content = file.readlines()
        j = 0
        while j < len(content):
            msg = ""
            i = 0
            while i < 10 and j < len(
                    content
            ):  #10 lines at a time to prevent getting rate limited by discord
                msg += content[j]
                i += 1
                j += 1
            await client.send_message(message.channel, msg)