예제 #1
0
    def getDefinition(self, query):

        specialDict = {
            'foip':
            'FOIP (\'Find Out In Play\') is any information you have that another character in the system does not have. Therefore, it is anything not on the website, in the almanac or in the rules books. Broadcasting this is a kickable offence on #maelfroth. If someone claims what you are talking about is FOIP, you need to stop talking about it as you may be damaging the game of others.',
            'herring':
            'Type of fish. There is nothing between it and Marmalade it in my dictionary. My dictionary is not in alphabetical order, which is why it still has "kelp"',
            'marmalade':
            'A type of citrus-based conserve. There is nothing before it in my dictionary until "herring". My dictionary is oddly ordered, however, so it still contains "Lemur"',
            'catbus':
            'You don\'t want to know.',
            'glados':
            '*happy sigh*',
            'lampstand':
            "That's me. Hi there",
            'hal':
            'grrrrr.',
            'inconceivable':
            'adj. Not what you think it means.',
            'tenant':
            'n. An opinion, doctrine, or principle held as being true by a person or especially by an organization',
            'tenet':
            'n. One that pays rent to use or occupy land, a building, or other property owned by another.'
        }

        if query.lower() in specialDict:
            return specialDict[query.lower()]

        src = False

        try:
            dictcxn = dictclient.Connection("dict.org")
            dfn = dictcxn.define("*", query)
            if dfn:
                dfn = dfn[0].getdefstr()

            src = "Dictionary"
        except socket.error:
            self.logger.info("[Define] Argh. Dictionary server's offline")
            connection.message(
                channel, "Sorry, but my dictionary server's not working.")
            dfn = None

        # if not dfn:
        #    self.logger.info("Nothing in Dictionary, looking up on wikipedia")
        #    try:
        #        dfn = dns.resolver.query('%s.wp.dg.cx' % query, 'TXT')
        #        if dfn:
        #            dfn = str(dfn[0])
        #            dfn = re.sub(r'\\(.)', r'\1', dfn)
        #            src = "Wikipedia"
        #    except dns.resolver.NXDOMAIN:
        #        dfn = False

        if not dfn:
            return None

        result = ' '.join(dfn.split('\n'))

        return (result, src)
예제 #2
0
def setupdictdbs():
    dbs = {}
    if got_dictclient:
        for s in known_servers:
            try:
                c = dictclient.Connection(s)
                sdbs = c.getdbdescs()
                for db, desc in sdbs.items():
                    if db not in dbs:
                        dbs[db] = {
                            'server': s,
                            'description': desc,
                        }
            except:
                print("%(server)s is invalid or unavailable" % {'server': s})
    return dbs
예제 #3
0
파일: views.py 프로젝트: djkz/twister-bot
def dict(request, word):
    global more_results
    del more_results[:]
    try:
        my_dict = dictclient.Connection('dict.org')
        result = my_dict.define("wn", word)[0]
        result_str = ' '.join(result.getdefstr().split('\n'))
        result_list = re.split(r'(\d+:\D+)', result_str)
        for i in range(0, len(result_list)):
            if (i + 1) % 2 == 0:
                #definition = "%s defintion %i of %i: %s " % (word,(i+1)/2,len(result_list)/2,result_list[i])
                more_results.append(result_list[i])

        more_results.reverse()
        result = more_results.pop()

        return IRCResponse(request.reply_recipient, "%s" % result)
    except:
        return IRCResponse(request.reply_recipient,
                           "Could not lookup %s" % word)
예제 #4
0
    def cmd_definition(self, command, data):
        splitcmd = [a.strip() for a in command.split(':')]
        command = splitcmd[0]
        defterm = splitcmd[1]
        reply = []
        if command in self.dbs:
            db = command
            server = self.dbs[command].get('server', None)
        else:
            db = '*'
            server = normal_server

        if server is not None:
            c = dictclient.Connection(server)
            definitions = c.define(db, defterm)
            if not definitions:
                reply.append('No definitions found in ' + command)
            reply.extend(
                self.process_definition(d) for d in definitions[:MAX_DEFS])
        return reply_to_user(data, reply)
예제 #5
0
파일: willify.py 프로젝트: hackerb9/willify
# You can also read from stdin

# hackerb9 2017
# GPL 3+

import dictclient
import re
import fileinput
import sys
from random import choice

# If you have dictd installed on your localhost, use this:
#dictd = dictclient.Connection()

# If you don't have dictd, you can try connecting to an online dictionary:
dictd = dictclient.Connection('dict.org')


def wnsyns(word):
    result = [word]
    for definition in dictd.define('wn', word):
        s = definition.getdefstr()
        s = re.sub('-\n', '-', s)
        s = re.sub('\n', ' ', s)
        for synonyms in re.findall('\[syn: [^]]*\]', s):
            result.extend(re.findall('(?:{([^}]*)})', synonyms))
    return result


def mobysyns(word):
    result = [word]