Coder Social home page Coder Social logo

imshawan / pydictapi Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 95 KB

An advanced Dictionary & Translator Module for Python

Home Page: https://pypi.python.org/pypi/PyDictAPI

License: MIT License

Python 100.00%
dictionary dictionaries python pydictionaryapi en-us english-dictionary meaning python3 pydictapi dictionary-app-using-python

pydictapi's Introduction

PyDictAPI GitHub license Latest Version Downloads

PyDictAPI

An advanced Dictionary and Translator Module for Python

PyDictAPI is a Dictionary Module for Python 3+ to get a detailed and well-structured meanings of a queried word in JSON format. PyDictAPI searches for the query on the web, if the query matches than it returns the Definitions/Examples/Synonyms/Antonyms as specified by the user. And incase of incorrect words, the response is returned as a suggestion of the correct word.
And incase of wrong translation-query or language code, the source query is returned back.

Sources: Dictionary.com, Thesaurus, Lexico

This module uses Requests and bs4 dependencies to scrape the web and find the definitions and return it in a well-structured JSON document

Installation

PyDictAPI can be easily installed through PIP

pip install PyDictAPI

Both the Finder and Translator class takes an arguement "jsonify" that is set to False by default. If jsonify is set to True, than the processed queries are returned in JSON. While by default the queries are returned in the form of a Python List (Array)

Dictionary searches

Dictionary searches can be performed by creating a Finder instance and later calling findMeanings() that takes a word as an arguement.

For example,

from PyDictAPI import Finder
Meanings = Finder(jsonify=True)
# Use can use Finder() without 'jsonify' to get response in the form of a Python List
print(Meanings.findMeanings('apple'))

This is will create a local instance of the Finder class and will return results containing the meanings of the word.
The Output can be seen as:

{
  "word": "Apple",
  "meanings": [
    {
      "partOfSpeech": "Noun",
      "definition": "The usually round, red or yellow, edible fruit of a small tree, Malus sylvestris, of the rose family."  
    },
    {
      "partOfSpeech": "Noun",
      "definition": "A rosaceous tree, Malus sieversii, native to Central Asia but widely cultivated in temperate regions in many varieties, having pink or white fragrant flowers and firm rounded edible fruits. See also crab apple"
    }
  ]
}                                                                       

Exceptions

Case - 1: If the word is spelt incorrectly

from PyDictAPI import Finder
Meanings = Finder()
# jsonify is set to false by default, so the output returned is in plain string.
print(Meanings.findMeanings('helloooo'))

Incase of incorrect words, the response is returned as a suggestion of the correct word
The Response can be seen as:

Couldn't find results for helloooo, Did you mean hello?

Case - 2: If the word doesn't exist

from PyDictAPI import Finder
Meanings = Finder()
print(Meanings.findMeanings('abcdefghijkl'))

The Response can be seen as:

Couldn't find any results for ABCDEFGHIJKL, try searching the web...

Finding Examples, Synonyms and Antonyms

from PyDictAPI import Finder
Meanings = Finder()
# jsonify is set to false by default, so the output returned is in python list.

print(Meanings.findUsage('help', 2)) #Finding Examples
# Here 2 defines the maximum number of examples to be included in the response, 
# by default it is set to 5

print(Meanings.findSynonyms('help', 4)) #Finding Synonyms
print(Meanings.findAntonyms('help', 4)) #Finding Antonyms

Outputs for Examples, Synonyms and Antonyms

Examples:

['She helped him find a buyer', 'Long-term funding is desperately being sought for a voluntary service that helps local victims of domestic violence.']

Synonyms:

['Advice', 'Aid', 'Benefit', 'Comfort']

Antonyms:

['Blockage', 'Encumbrance', 'Handicap', 'Hindrance']

Using the Translator

from PyDictAPI import Translate
t = Translate(jsonify=True)
print(t.languages_help()) # Prints all supported languages with language code

print(t.translateItems("Hello, How are you?", "hi")) # hi: Hindi

# Translates text according to the language code

Output:

{'query': 'Hello, How are you?', 'language': 'Hindi', 'translation': 'नमस्कार किसे हो आप?'}

About

Copyright (c) 2021 Shawan Mandal.

pydictapi's People

Contributors

imshawan avatar

Watchers

 avatar

Forkers

ivandmitry7

pydictapi's Issues

findUsage can't work

Hi,

Thank you for developing this great module.

Recently, the "findUsage" started to not work and shows the error message:
"MarkupResemblesLocatorWarning: The input looks more like a filename than markup. You may want to open this file and pass the filehandle into Beautiful Soup." After I dig into the code, maybe it's because of the change of the "www.lexico.com".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.