Exemplo n.º 1
0
def dictionary_search(word):
    dictionary=PyDictionary(word)
    print('Meaning is')
    print(dictionary.getMeanings())
    print('Antonyms are ')
    print(dictionary.getAntonyms())
    print('Synonyms are ')
    print(dictionary.getSynonyms())
Exemplo n.º 2
0
    def anto(self):

        dictionary = PyDictionary(self.root.ids.antosyno.text)
        word = str(self.root.ids.antosyno.text)
        synonym = list(dictionary.getAntonyms())
        d = synonym[0][word][:4]
        e = ",".join(d)

        self.root.ids.antosynom.text = e
        self.speak(e)
Exemplo n.º 3
0
def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    try:
        req_body = req.get_json()
    except ValueError:
        pass
    else:
        words = req_body.get('words')

    if len(words) > 0 and type(words) is list:
        result = {}
        for word in words:
            synsets = wn.synsets(word, pos='n')
            similar_words = []
            if len(synsets) > 0:
                synset = synsets[0]
                # Get the hypernym for this synset (again, take the first)
                hypernyms = synset.hypernyms()
                if len(hypernyms) > 0:
                    hypernym = hypernyms[0]
                    # Get some hyponyms from this hypernym
                    hyponyms = hypernym.hyponyms()
                    # Take the name of the first lemma for the first 8 hyponyms
                    for hyponym in hyponyms:
                        similar_word = hyponym.lemmas()[0].name().replace(
                            '_', ' ').replace('-', ' ')
                        if similar_word != word:
                            similar_words.append(similar_word)
            dictionary = PyDictionary(word)
            synonyms = dictionary.getSynonyms()
            if len(synonyms) > 0 and synonyms[
                    0] is not None and word in synonyms[0].keys():
                answer = synonyms[0][word]
                print(answer)
                similar_words = similar_words + answer

            opposite_words = []
            antonyms = dictionary.getAntonyms()
            if len(antonyms) > 0 and antonyms[
                    0] is not None and word in antonyms[0].keys():
                opposite_words = antonyms[0][word]
            result[word] = {"synms": similar_words, "antms": opposite_words}
        return func.HttpResponse(json.dumps(result),
                                 mimetype="application/json",
                                 status_code=200)
    else:
        return func.HttpResponse(
            "This HTTP triggered function executed successfully. Pass a word in the query string or in the request body for a personalized response.",
            status_code=201)
Exemplo n.º 4
0
def search_dictionary(msg):
    """Get word meaning, synonym, antonym and translation."""
    lt_w = msg.split(' ')
    dictionary = PyDictionary(lt_w[-1])
    stre = lt_w[-1]
    if 'meaning' in lt_w:
        stre += '\n' + str(dictionary.getMeanings()[lt_w[-1]])
        if 'synonym' in lt_w:
            stre += '\n' + str(dictionary.getSynonyms()[0][lt_w[-1]])
        if 'antonym' in lt_w:
            stre += '\n' + str(dictionary.getAntonyms()[0][lt_w[-1]])
        if 'translate' in lt_w:
            stre += '\n' + dictionary.translateTo(
                lt_w[lt_w.index('translate') + 1])[0]

    return RESPONSE_TYPE['MESSAGE'], stre
Exemplo n.º 5
0
import pickle
from PyDictionary import PyDictionary

with open('../vocab', 'rb') as f:
    load_dict = pickle.load(f)
    vocab = list(load_dict.keys())

    dictionary = PyDictionary(vocab)
    sym = dictionary.getSynonyms()
    ant = dictionary.getAntonyms()

    symMap = {}
    antMap = {}

    for d in sym:
        if d is not None:
            symMap.update(d)

    for d in ant:
        if d is not None:
            antMap.update(d)

    with open('vocab_sym', 'wb') as sym_f:
        pickle.dump(sym, sym_f, 2)

    with open('vocab_ant', 'wb') as ant_f:
        pickle.dump(ant, ant_f, 2)
Exemplo n.º 6
0
    def lets_chat(self):
        def listen_below():
            r = sr.Recognizer()
            self.root.ids.top.text = "listening...."
            self.speak('we are listening')

            with sr.Microphone() as source:
                r.energy_threshold = 10000
                audio = r.listen(source)

            try:
                query = r.recognize_google(audio, language='en-in')
                print('User: '******'\n')
                return query


            except sr.UnknownValueError:
                self.root.ids.top.text = 'Sorry sir! I didn\'t get that! Try typing the word!'
                self.speak('Sorry sir! I didn\'t get that! Try typing the word!')
                s = input()
                return s
        query = listen_below()


        if "meaning" in query:
            c = query[-1]
            dictionary = PyDictionary(c)
            ans = dictionary.meaning(c)
            if ans:

                x = ans.keys()
                y =[]
                for i in x:
                    y.append(i)
                z = ans[y[0]][:2]
                w = ",".join(z)

                hey = "{}: {}".format(y[0],w)
                self.speak(hey)
            else:
                self.speak("We didnt got you sir")

        elif "synonym" in query:
            c = query[-1]
            dictionary = PyDictionary(c)
            synonym = list(dictionary.getSynonyms())
            d = synonym[0][c][:4]
            e = ",".join(d)
            self.root.ids.antosynom.text = e
            self.speak(e)

        elif "antononym"  in query:
            c = query[-1]
            dictionary = PyDictionary(query[-1])
            synonym = list(dictionary.getAntonyms())
            d = synonym[0][c][:4]
            e = ",".join(d)
            self.speak(e)

        elif "about " in query:
            self.speak("This A dictionary application which is a listing of words in one or more specific languages, often arranged alphabetically (or by radical and stroke for ideographic languages), which may include information on definitions, usage, etymologies, pronunciations, translation")

        elif "features" in query:
            self.speak("This Dictionary application consists of listed features such as pronunciation of an entered word,Translations of word or sentence  into four languages that is Spanish,French,German,japenese,antononyms and synonyms of an word , there is also spelling checker as well as grammar checker into this application which corrects a sentence  and there is also an AI bot named pam which helps in assisting the user")

        elif "english" in query:
            self.speak("English may not be the most spoken language in the world, but it is the official language of 53 countries and spoken by around 400 million people across the globe. Being able to speak English is not just about being able to communicate with native English speakers, it is the most common second language in the world. If you want to speak to someone from another country then the chances are that you will both be speaking English to do this.")

        elif "created" in query:
            self.speak("this application is created in using KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. The project's goal is to approximate Google's Material Design spec as close as possible without sacrificing ease of use or application performance")


        elif "gmail" in query:
            self.speak('okay')
            webbrowser.open('www.gmail.com')

        elif 'open hackerrank' in query:
            self.speak('okay')
            webbrowser.open('https://www.hackerrank.com')

        elif 'open interviewbit' in query:
            self.speak('okay')
            webbrowser.open('https://www.interviewbit.com/profile')

        elif 'open leetcode' in query:
            self.speak('okay')
            webbrowser.open('https://leetcode.com')

        elif 'open chrome' in query:
            self.speak('okay')
            webbrowser.open('www.google.com')


        elif 'open github' in query:
            self.speak('okay')
            webbrowser.open('https://github.com')
        else:

            query = query
            self.speak('Searching...')
            try:
                results = wikipedia.summary(query, sentences=2)
                self.speak('Got it.')
                self.speak('WIKIPEDIA says - ')
                self.speak(results)
            except:
                webbrowser.open('www.google.com')