Skip to main content

API Interface for Google NGram

Project description

Google PyGram

An API interface for Google Book NGrams.

Installation

pip install google-pygram

Usage

from google_pygram import GooglePyGram as gpg

pygram = gpg(
    corpus='English',
    corpus_year=2019,
    start_year=1800,
    end_year=2000,
    smoothing=3,
    case_sensitive=False,
    phrases=['hello', 'world']
)

print(pygram.to_df())

#         year         hello     world
# 1800  1800.0  9.921164e-08  0.000379
# 1801  1801.0  6.075895e-08  0.000423
# 1802  1802.0  7.149158e-08  0.000353
# 1803  1803.0  2.593483e-08  0.000338
# 1804  1804.0  8.450996e-08  0.000398
# ...      ...           ...       ...
# 1996  1996.0  1.331358e-06  0.000306
# 1997  1997.0  1.430890e-06  0.000308
# 1998  1998.0  1.523893e-06  0.000317
# 1999  1999.0  1.650712e-06  0.000326
# 2000  2000.0  2.076080e-06  0.000337

Parameters

  • corpus: The corpus to use. Can be one of the following:

    • English
    • Chinese (simplified)
    • French
    • German
    • Hebrew
    • Italian
    • Russian
    • Spanish
  • corpus_year: The year of the corpus to use. Can be one of the following:

    • 2019
    • 2012
    • 2009
  • start_year: The start year of the ngram. Must be between 1800 and 2000.

  • end_year: The end year of the ngram. Must be between 1800 and 2000.

  • smoothing: The smoothing parameter. Must be between 0 and 5.

  • case_sensitive: Whether or not the ngram is case sensitive. Must be a boolean.

  • phrases: A list of phrases to search for. Must be a list of strings.

Methods

  • add_phrase(phrase): Adds a phrase to the ngram query.
  • to_df(): Returns a pandas DataFrame of the ngram.
  • to_csv(filename): Saves the ngram to a csv file.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google-pygram-0.0.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

google_pygram-0.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file google-pygram-0.0.1.tar.gz.

File metadata

  • Download URL: google-pygram-0.0.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for google-pygram-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e33369997f168c5b51f64cd66c0e0b8a8a118b55bf6655a25b406ef2c18c687e
MD5 1a3c08b3de35fb45b1f63ba10a96dc04
BLAKE2b-256 dbab42589483abeac78af67117a3a13a8d64a8315bd8adab112147a23741a26f

See more details on using hashes here.

File details

Details for the file google_pygram-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: google_pygram-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for google_pygram-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f1a65a0392b70c526c789c911ed5b5ea07605df00801f87f99d526b63d82526
MD5 defa29a3cd727f24f22cb0a3aef06dc8
BLAKE2b-256 4b29ee0ff2f86fe8f2138f1ae424b3a19c67f3c6c3548b826adfbfa46c3998a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page