Skip to main content

Creates an SQLite database ngrams.

Project description

Create an SQLite database from the Google ngrams database.

Travis CI Build Status PyPI

Creates an SQLite database of the one million [n-grams] datasets from Google. This code downloads the n-gram data sets corpus and then creates an [SQLite] database file with the contents. It also provides a simple API for n-gram look ups.

Table of Contents

Installation

  1. To make life easier, install GNU Make. If you do not, you'll need to follow the steps given in the makefile.
  2. Download the 1 million n-gram data sets: make download. This should take a few minutes with a good Internet connection.
  3. Create and load the [SQLite] database from the downloaded corpus: make load. Depending on the processor speed, this should take about an hour.
  4. Install from the command line either from source (make install) or from pip.

If you want to use the program on the command line (as opposed to an API), create a the following file in ~/.ngramdbrc with the contents:

[default]
[ngram_db]
data_dir=${HOME}/view/nlp/ngramdb/data

Usage

This project can be used either from the command line or as an API.

Command Line

To use from the command line:

% ngramdb query -g the -y 2005
631362690 0.56880%

This gives the number of unigrams (assuming unigrams were built) found since 2005.

Programmatic Interface

As in the installation section, create the ~/.ngramdbrc configuration file. Also note that the API is configured to easily work with other Python projects that use the zensols.actioncli configuration API.

from zensols.ngramdb import AppConfig, Query
conf = AppConfig.instance().app_config
query = Query(conf)
stash = query.stash
n_occurs = stash['The']
print(f'{n_occurs} {100 * n_occurs / len(stash):.5f}%')

=> 631362690 0.56880%

Obtaining

The easist way to install the command line program is via the pip installer:

pip3 install zensols.ngramdb

Binaries are also available on pypi.

Changelog

An extensive changelog is available here.

License

Copyright (c) 2019 Paul Landes

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Release history Release notifications

This version

0.0.1

Download files

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

Files for zensols.ngramdb, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size zensols.ngramdb-0.0.1-py3.6.egg (17.5 kB) File type Egg Python version 3.6 Upload date Hashes View hashes
Filename, size zensols.ngramdb-0.0.1-py3-none-any.whl (10.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page