Coder Social home page Coder Social logo

geekpradd / pydictionary Goto Github PK

View Code? Open in Web Editor NEW
273.0 273.0 65.0 137 KB

PyDictionary is a Dictionary Module for Python 2/3 to get meanings, translations, synonyms and antonyms of words

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

License: MIT License

Python 100.00%

pydictionary's Introduction

PyDictionary: A "Real" Dictionary Module for Python

Build Status Latest Version License Downloads

NOTE: Mainintaing this module requires constantly changing the scrapping endpoints which unfortunately I no longer have the bandwidth to do so, so this module is DEPRECATED. Kindly use other substitutes available on PyPI. Thanks!

PyDictionary is a Dictionary Module for Python 2/3 to get meanings, translations, synonyms and Antonyms of words. It uses WordNet for getting meanings, Google for translations, and synonym.com for getting synonyms and antonyms.

This module uses Python Requests, BeautifulSoup4 and goslate as dependencies

Installation

Installation is very simple through pip (or easy_install)

For pip

pip install PyDictionary

For Easy_Install

easy_install  PyDictionary

Usage

PyDictionary can be utilised in 2 ways, either by creating a dictionary instance which can take words as arguments or by creating a dictionary instance with a fixed amount of words.

For example,

from PyDictionary import PyDictionary
dictionary=PyDictionary()

This is will create a local instance of the PyDictionary class and now it can be used to get meanings, translations etc.

print (dictionary.meaning("indentation"))

This will return a dictionary containing the meanings of the word. For example the above code will return:

{'Noun': ['a concave cut into a surface or edge (as in a coastline', 'the
 formation of small pits in a surface as a consequence of corrosion', 'th
e space left between the margin and the start of an indented line', 'the 
act of cutting into an edge with toothlike notches or angular incisions']
}                                                                        

The dictionary keys are the different types of the word. If a word is both a verb and a noun then there will be 2 keys:'Noun' and 'Verb'. Each key refers to a list containing the meanings

For Synonyms,

print (dictionary.synonym("Life"))

This will return a list containing the Synonyms of the word.

For Antonyms,

print (dictionary.antonym("Life"))

This will return a list containing the Antonyms of the word.

For Translations,

print (dictionary.translate("Range",'es'))

This will return the Translation of the word "Range" in Spanish. For Language codes consult Google Translate. The return value is string in Python 3 and unicode in Python 2

Alternatively, you can set a fixed number of words to the PyDictionary Instance. This is useful if you just want to get the meanings of some words quickly without any development need.

Example:

from PyDictionary import PyDictionary

dictionary=PyDictionary("hotel","ambush","nonchalant","perceptive")
'There can be any number of words in the Instance'

print(dictionary.printMeanings()) '''This print the meanings of all the words'''
print(dictionary.getMeanings()) '''This will return meanings as dictionaries'''
print (dictionary.getSynonyms())

print (dictionary.translateTo("hi")) '''This will translate all words to Hindi'''

Similarly Synonyms and Antonyms can also be printed onto the screen.

About

Current Version: 2.0.1 Created By Pradipta Bora 2020.

pydictionary's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydictionary's Issues

cant be installed on replit

Replit: Updating package configuration

--> python3 -m poetry add PyDictionary
Using version ^2.0.1 for PyDictionary

Updating dependencies
Resolving dependencies...

HTTPError

404 Client Error: Not Found for url: https://package-proxy.replit.com/pypi/packages/a6/1c/72a18c8c7502ee1b38a604a5c5243aa8c2a64f4bba4e6631b1b8972235dd/futures-3.1.1-py2-none-any.whl

at venv/lib/python3.8/site-packages/requests/models.py:960 in raise_for_status
956│ elif 500 <= self.status_code < 600:
957│ http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, reason, self.url)
958│
959│ if http_error_msg:
→ 960│ raise HTTPError(http_error_msg, response=self)
961│
962│ def close(self):
963│
964│ called the underlying raw object must not be accessed again.
/home/runner/python/venv/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
exit status 1

Replit: Package operation failed.

Fix for Install Error (metadata-generation-failed)

I have experienced the problem where the package just wouldn't install, either from PyPI or directly from GitHub. The only fix I found, as mentioned by @bunchesofdonald, to install futures, that are used in the package, prior to the installation of the dictionary, on a lower version (pip install 'futures<3.0.0'). Putting this here to make it easier to access. All credit for the idea goes to @bunchesofdonald.

Warning from BeautifulSoup

/usr/lib/python3.4/site-packages/bs4/__init__.py:166: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

To get rid of this warning, change this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "lxml")

  markup_type=markup_type))```

create capturable errors

Current version of the code gets error printed. This is problematic while using in other environments. Change the print statements into proper error message generation so that they can be captured using try except or sys and traceback loops. Goal will be:

  • change all error printing into standard error statements

  • add test cases showing that these error statements can be captured and processed using try except or sys traceback loops.

Package not installing with Anaconda

Hello,
Since the package can only be installed using pip, it is not working with conda environments.
Is there any chance of this package being available in Anaconda distribution?

Parenthesis issue

Hi,

It seems that there is issue with parenthesis handling.

import PyDictionary
mydict = PyDictionary.PyDictionary()
mydict.meaning("scholar")

... gets me:
{u'Noun': ['a learned person (especially in the humanities', 'someone (especially a child', 'as from a teacher', 'a student who holds a scholarship']}

To avoid the issue, I changed:
for x in re.findall(r'\((.*?)\)', reg): (line 135 in core.py)
by:
for x in re.findall(r'>\s\((.*?)\)\s<', reg):

Now getting:

{u'Noun': ['a learned person (especially in the humanities); someone who by long study has gained mastery in one or more disciplines', 'someone (especially a child) who learns (as from a teacher) or takes up knowledge or beliefs', 'a student who holds a scholarship']}

as expected.

Thanks,
Jennifer

Add a license

Under what license is this project released? If it is open-source, please provide a LICENSE file in the project root, so that people know their rights with the project sourcecode.

Meaning API giving incorrect definition string for certain words

The following program results in an incomplete definition for the word 'calumnious.' Defamatory, a synonym of calumnious, has the same issue.

>>> from PyDictionary import PyDictionary
>>> dictionary = PyDictionary()
>>> dictionary.meaning('calumnious')
{'Adjective': ['(used of statements']}
>>> dictionary.meaning('defamatory')
{'Adjective': ['(used of statements']}

Issue in finding Synonyms of words using PyDictinary API

I have been working on a project for documents analysis and developing it in Python. For analysis, I have been using Pydictionary for finding the synonyms of adverbs and adjective words. Earlier the API was working good and gives good results and I appreciate the developer for developing such an optimized and fast API. But from past couple of days, the API is not working properly. It gives me unexpected errors like "word has no Synonyms in the API". Sometimes it finds synonyms and but sometimes not. Can you please suggest me some solution for the same. I have been using PyDictionary version 1.5.2 in my project.
Attaching snippet.

screenshot_20180417_133411

Thanks!!

Malfunctioning

This library neither returns Synonyms nor Antonyms but you have documented that this can do it. So Please for the convenience, Either you remove the feature from Documentation or Add and Patch the Bug.
Thank You

Add ability to let user implement functionality if word is not found(Question about implementation)

I'm currently implementing a feature where if a word is not found when meaning() synonym() or translate() is called it will either return None or raise an exception. This way, the user can add functionality if the word is not found.

Example of raising an exception:

@staticmethod
    def synonym(term, formatted=False):
        if len(term.split()) > 1:
            print("Error: A Term must be only a single word")
        else:
            try:
                data = _get_soup_object("https://www.thesaurus.com/browse/{0}".format(term))
                section = data.find('section', {'class': 'synonyms-container'})
                spans = section.findAll('span')
                synonyms = [span.text for span in spans[:5]]
                if formatted:
                    return {term: synonyms}
                return synonyms
            except:
                print("{0} has no Synonyms in the API".format(term))
                raise InvalidTermError("{0} has no synonym in the API".format(term)) # InvalidTermError would be defined in an additional file exceptions.py

Example of returning None:

@staticmethod
    def synonym(term, formatted=False):
        if len(term.split()) > 1:
            print("Error: A Term must be only a single word")
        else:
            try:
                data = _get_soup_object("https://www.thesaurus.com/browse/{0}".format(term))
                section = data.find('section', {'class': 'synonyms-container'})
                spans = section.findAll('span')
                synonyms = [span.text for span in spans[:5]]
                if formatted:
                    return {term: synonyms}
                return synonyms
            except:
                print("{0} has no Synonyms in the API".format(term))
                return None

I don't know which way would be better. Any feedback would be appreciated and I'll implement this based on feedback.

not getting all the meanings for a word

I found when using .meaning the module was not properly parsing all the definitions. Some of the definitions were either chopped or not complete.
I found this was from the re.findall(r'((.*?))',x).
After some experimentation I found this worked better:

for x in re.findall(r'((.+))', reg): #was: r'((.*?))'
y=re.findall(r'((.+)',x)
if not y==None:
if 'often followed by' in y:
pass
elif len(y) > 5 or ' ' in str(y):
meanings.append(y)
I did some testing and found it worked better for me.

Rate limit?

Is there a rate limit for the synonym.com functions? I don't see anything about it in the docs or on their site, but it would be nice to have some guidelines listed somewhere.

Pydictionary needs to use stderr

Pydictionary puts the following error out to stdout rather that sdterr:

Error: The Following Error occurred: index out of range

Result=dictionary.meaning(‘ispida’)

Result=None

where:
ispida (Noun) slender billed birds

error with word 'the'

Getting this error:

dictionary.meaning('the')

Output:
Error: The Following Error occured: list index out of range
```

Working on google colab pro, python version 3.6 

How to remove the 'u' before each result?

Hello. Sorry for my ignorance here. I was just wondering how I'd remove the 'u' before each result. I am trying to get the synonym for (Example) word 'Hello', and then use PyTTSX to read it back to them, however I am unsure on how to remove the 'u' at the beginning of each word/synonym.

Any help would be greatly appreciated.
Thanks.

googlemeaning not stable

dictionary.googlemeaning() not always gives result. For example, from time to time, I see this:

dictionary.googlemeaning('what')
Error: The Word given is not a valid English Word

not installing properly.

Collecting PyDictionary
  Downloading PyDictionary-2.0.1-py3-none-any.whl (6.1 kB)
Requirement already satisfied: click in /home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages (from PyDictionary) (8.0.3)
Requirement already satisfied: requests in /home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages (from PyDictionary) (2.26.0)
Collecting goslate
  Downloading goslate-1.5.2.tar.gz (16 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: bs4 in /home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages (from PyDictionary) (0.0.1)
Requirement already satisfied: beautifulsoup4 in /home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages (from bs4->PyDictionary) (4.10.0)
Collecting futures
  Downloading futures-3.0.5.tar.gz (25 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 14, in <module>
        File "/home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages/setuptools/__init__.py", line 18, in <module>
          from setuptools.dist import Distribution
        File "/home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages/setuptools/dist.py", line 32, in <module>
          from setuptools.extern.more_itertools import unique_everseen
        File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
        File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
        File "<frozen importlib._bootstrap>", line 565, in module_from_spec
        File "/home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages/setuptools/extern/__init__.py", line 52, in create_module
          return self.load_module(spec.name)
        File "/home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages/setuptools/extern/__init__.py", line 37, in load_module
          __import__(extant)
        File "/home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages/setuptools/_vendor/more_itertools/__init__.py", line 1, in <module>
          from .more import *  # noqa
        File "/home/krshnaaishwaryad/anaconda3/lib/python3.9/site-packages/setuptools/_vendor/more_itertools/more.py", line 5, in <module>
          from concurrent.futures import ThreadPoolExecutor
        File "/tmp/pip-install-y11dm6z8/futures_f83793109feb42f2bb50f12844581d63/concurrent/futures/__init__.py", line 8, in <module>
          from concurrent.futures._base import (FIRST_COMPLETED,
        File "/tmp/pip-install-y11dm6z8/futures_f83793109feb42f2bb50f12844581d63/concurrent/futures/_base.py", line 357
          raise type(self._exception), self._exception, self._traceback
                                     ^
      SyntaxError: invalid syntax
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Error: The Following Error occured: list index out of range

For some reason, I keep getting this error (title) when I'm trying to use dictionary.meaning(). This isn't the case for most words like apple, book, etc. However, more complex words such as trimetric don't work and throw this error. I am generating words from another library and some words actually don't appear in the English dictionary at all so this may be the generator's problem.
If it helps, my generator library is NLTK (python3 -m pip install nltk then in a shell, do import nltk and then nltk.download("words")) (http://www.nltk.org/data.html).

The full code ran is:
from nltk.corpus import words
from PyDictionary import PyDictionary
from random import choice
word_list = words.words()
word = choice(word_list).capitalize()
dictionary=PyDictionary()
dictionary.meaning(word) -> Error: The Following Error occured: list index out of range
print(word) -> "Judger"
dictionary.meaning("Judger") -> Error: The Following Error occured: list index out of range

Screenshot from 2020-10-30 19-28-36
Screenshot from 2020-10-30 19-29-11

Concern with goslate usage (it's unmaintained)

Firstly thank you for this repo! It looks useful.

I was looking over the code and I notice that you continue to use goslate even though it was last updated over five years ago (Jan 2016) and the source to the version in PyPI is no longer available.

From what I can see in PyPI it no longer works anyway, given Google changes, so it seems like it might be worth either cutting it out of PyDictionary or looking for an alternate (if there's a reasonable way to do that?)

Takes too long...

def timeit(thing="welcome"):
   t=time.time()
   print(dictionary.meaning(thing))
   t=time.time()-t
   print("It took:", t)
   return t


dictionary=PyDictionary()
timeit()

{'Noun': ['the state of being welcome', 'a greeting or reception'], 'Verb': ['accept gladly', 'bid welcome to; greet upon arrival', "receive someone, as into one's house"], 'Adjective': ['giving pleasure or satisfaction or received with pleasure or freely granted']}
It took: 3.8481032848358154

That is 3.84 seconds! My search engine can not waste that much time for things as simple as that.

module not found error

Hi,

Installed the PyDictionary successfully after goslate installation. But I get module not found error (No module named 'PyDictionary'). I am using Visual Studio Code and python version 3.12.0 via anaconda

regards,
Avi

PyDictionary outputting '{}'

Hello,

I am using PyDictionary on PythonAnywhere for definitions. However, it is giving me {} as an output when asking for a definition.

This doesn't happen on my local machine so I'm aware it's not specifically a PyDictionary issue, but I was wondering if someone here could help me.

Thank you!

error with word `everyone`

dictionary.meaning("everyone") gives the error -

Error: The Following Error occured: list index out of range

How to cite this package in paper?

Respected Sir/Maam,
I was writing a paper in which I had used this package.
Could you please help me with how to cite a reference to this package in the paper?

Best Regards,
Manav

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.