Пример #1
0
def oxford_dictionary():
	form = OxfordDictionarysForm()
	if request.method == 'POST':
		word = form.word.data
		app_id = '86bad9b7'
		app_key = 'b36d710e0a1ea7cbf4080c46e66fa8db'
		od = OxfordDictionaries(app_id, app_key)
		synonyms_data = od.get_synonyms(word.casefold()).json()
		synonyms = synonyms_data['results'][0]['lexicalEntries'][0]['entries'][0]['senses'][0]['synonyms']
		synonyms = [res['text'] for res in synonyms]
		antonyms_data = od.get_antonyms(word.casefold()).json()
		antonyms = antonyms_data['results'][0]['lexicalEntries'][0]['entries'][0]['senses'][0]['antonyms']
		antonyms = [res['text'] for res in antonyms]
		return render_template('oxford_dictionary.html', form = form, synonyms = synonyms, antonyms = antonyms)
	return render_template('oxford_dictionary.html', form = form)
Пример #2
0
def init():
    global translator, oxford, counter_threshold, counter_joke, previous_joke
    translator = Translator()
    oxford = OxfordDictionaries(app_id=oxford_id, app_key=oxford_key)
    counter_threshold = generate_threshold(8, 20)
    counter_joke = 0
    previous_joke = datetime.now() - timedelta(hours=2)  # joke limiter
Пример #3
0
def _initialise(bot):
    appid = bot.get_config_option("oxforddict-appid")
    apikey = bot.get_config_option("oxforddict-apikey")
    if appid and apikey:
        _internal["client"] = OxfordDictionaries(appid, apikey)
        plugins.register_user_command(["define", "synonym", "antonym"])
    else:
        logger.error(
            'Dictionary: config["oxforddict-appid"] and config["oxforddict-apikey"] required'
        )
Пример #4
0
from oxforddictionaries.words import OxfordDictionaries

o = OxfordDictionaries.Oxford('856c3f2a', '07289ed24c8110e78b86bb3093c1ca0b')

relax = o.get_synonyms("absorb").json()

synonyms = relax['results'][0]['lexicalEntries'][0]['entries'][0]['senses'][0]['synonyms']

for s in range(10):
    print(synonyms[s]['text'])
Пример #5
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import spacy
import json
import requests
from pywsd.lesk import simple_lesk, cosine_lesk
from nltk.corpus import wordnet as wn
from oxforddictionaries.words import OxfordDictionaries

o = OxfordDictionaries("0008ceae", "e3319ad80adb64e830100bf675efba59")
# load english dict
nlp = spacy.load('en')
slp = spacy.load('es')
flp = spacy.load('fr')


# removes non-alpha chars
def remove_notalpha(line):
    line = line.replace('\n', ' ')
    result = ''.join([i for i in line if i.isalpha() or i == ' ' or i == '\n'])
    return result


# parts of speech have different tags in wordnet and spacy
def pos_convert(pos):
    pos_dict = {'NOUN': 'n', 'VERB': 'v', 'ADJ': 'a'}
    try:
        return pos_dict[pos]
    except Exception:
        return 'n'
'''
Install below Python Module before You run this code.
>>> pip install oxforddictionaries 
# API Base URL - https://od-api.oxforddictionaries.com/api/v1

'''

from oxforddictionaries.words import OxfordDictionaries
print("\n *** Oxford Dictionary *** \n")

word = input(' Enter word : ')

app_id, api_key = '86bad9b7', 'b36d710e0a1ea7cbf4080c46e66fa8db'

od = OxfordDictionaries(app_id, app_key)
relax1 = od.get_synonyms("absorb").json()
synonyms = relax1['results'][0]['lexicalEntries'][0]['entries'][0]['senses'][0]['synonyms']
relax2 = od.get_antonyms("small").json()
antonyms = relax2['results'][0]['lexicalEntries'][0]['entries'][0]['senses'][0]['antonyms']

res1 = [res['text'] for res in synonyms]
res2 = [res['text'] for res in antonyms]

print(f" Meaning : {res1}")
print(f" Opposite : {res2}")
Пример #7
0
from os import environ
from oxforddictionaries.words import OxfordDictionaries

# from keys import OXDICT_APPID, OXDICT_APPKEY
oxdict = OxfordDictionaries(environ['OXDICT_APPID'], environ['OXDICT_APPKEY'])


def use_oxford(word):
    res = oxdict.get_synonyms(word).json()
    data = res['results'][0]['lexicalEntries'][0]['entries'][0]['senses'][0]['synonyms']
    return [s['text'] for s in data]


def get_synonyms(word, task="first", num=1):
    try:
        if True:
            synonyms = use_oxford(word)

        if task == "longest":
            synonyms.sort(key=lambda w: -len(w))

        return synonyms[:num]
    except:
        print("synonym fail!")
        return


# @bot.command()
# async def fancify(ctx, *text):
#     """substitute fancy words to sound pretentious"""
#