Class CmudictDb
Version
20130518.
Represents the cmudict database and provides convenience methods for
common tasks.
Defined in: <src/cmudict-to-sqlite.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
CmudictDb(cmudictFile)
Represents the cmudict database and provides convenience methods for common
tasks.
|
Method Attributes | Method Name and Description |
---|---|
addEntry(word, code, callback)
Adds a new record to the cmudict table.
|
|
addMetadata(name, data, callback)
Adds a new record to the metadata table.
|
|
deleteEntry(word, callback)
Delete a record from the cmudict table.
|
|
deleteMetadata(name, callback)
Delete a record from the metadata table.
|
|
fuzzyLookupCode(code, callback)
Searches for the given phoneme(s).
|
|
fuzzyLookupWord(word, callback)
Searches words for the given pattern.
|
|
lookupCode(code, callback)
Searches for the given code.
|
|
lookupMetadata(name, callback)
Searches for the given metadata.
|
|
lookupWord(word, callback)
Searches for the given word.
|
|
saveAsText(fileName, callback)
Saves the contents of the database as a text file using the same format as the
original cmudict.
|
|
unload()
Finalizes all preparedStatements and closes the database.
|
|
updateCode(updatedCode, oldCode, callback)
Fix typos in codes.
|
|
updateMetadata(data, name, callback)
Update metadata entries.
|
|
updateWord(updatedWord, oldWord, callback)
Fix misspelled words or typos in words.
|
Class Detail
CmudictDb(cmudictFile)
Represents the cmudict database and provides convenience methods for common
tasks. When creating a new instance of the
CmudictDb the given database file will be opened and several prepared
statements will be loaded. Be sure to call the unload method when you are
finished using the database so that the database may be closed properly.
The dictionary is stored in the cmudict table and information, including
the license for the CMU Pronunciation Dictionary itself, is stored in the
metadata table.
Author: Matthew Kastor.
Author: Matthew Kastor.
- Parameters:
- {String} cmudictFile
- Optional. The name and location of the cmudict database generated with cmudictToSqliteDb. Defaults to cmudict.0.7a.sqlite.
- Requires:
- sqlite3
Method Detail
addEntry(word, code, callback)
Adds a new record to the cmudict table.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.addEntry('superfakeword', 'xo xo xo1', function (err, rows) { console.log('addEntry Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} word
- The word to add to the word field.
- {String} code
- The code to add to the code field.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
addMetadata(name, data, callback)
Adds a new record to the metadata table.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.addMetadata('superfakeword', 'xo xo xo1', function (err, rows) { console.log('addMetadata Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} name
- The name of the metadata
- {String} data
- The data associated with the metadata name.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
deleteEntry(word, callback)
Delete a record from the cmudict table.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.deleteEntry('superfakewordzzz', function (err, rows) { console.log('deleteEntry Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} word
- The word to remove.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
deleteMetadata(name, callback)
Delete a record from the metadata table.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.deleteMetadata('superfakeword', function (err, rows) { console.log('deleteEntry Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} name
- The metadata to remove.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
fuzzyLookupCode(code, callback)
Searches for the given phoneme(s). Through creative use of wildcards, this
method may be used to find assonance, consonance, rhyme, etc. Both, the
underscore and percent symbol, will match any character. The underscore
consumes a single character and the percent symbol consumes multiple
characters.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.fuzzyLookupCode('%r ah1 p t%', function (err, rows) { // finds words containing the sound "rupt" i.e. erupt and corrupt console.log('fuzzyLookupCode Results for %r ah1 p t%'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} code
- The pattern to look for in the code field.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
fuzzyLookupWord(word, callback)
Searches words for the given pattern. Both, the underscore and percent
symbol, will match any character. The underscore consumes a single character
and the percent symbol consumes multiple characters.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.fuzzyLookupWord('zeb%', function (err, rows) { console.log('fuzzyLookupWord Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} word
- The pattern to look for in the word field.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
lookupCode(code, callback)
Searches for the given code.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.lookupCode('ah1 p s ay1 z', function (err, rows) { console.log('lookupCode Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} code
- The code to look for in the code field.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
lookupMetadata(name, callback)
Searches for the given metadata.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.lookupMetadata('license', function (err, rows) { console.log('lookupMetadata Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} name
- The name of the metadata.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
lookupWord(word, callback)
Searches for the given word.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.lookupWord('zebra', function (err, rows) { console.log('lookupWord Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} word
- The word to look for in the words field.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
saveAsText(fileName, callback)
Saves the contents of the database as a text file using the same format as the
original cmudict. The contents of metadata.license will be prepended to the
beginning of the file, change it if you want to add information to the
license.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.saveAsText('cmudict.txt', function(content) { // if you want to see what was written to the file // uncomment the next line. // console.log(content); // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} fileName
- The name and location of the output file.
- {Function} callback
- The callback to execute after the file is written. The callback will be called with one argument, the string which was written to file.
unload()
Finalizes all preparedStatements and closes the database.
Author: Matthew Kastor.
Author: Matthew Kastor.
updateCode(updatedCode, oldCode, callback)
Fix typos in codes.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.updateCode('xo1 xo xo', 'xo xo xo1', function (err, rows) { console.log('updateCode Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} updatedCode
- The corrected code.
- {String} oldCode
- The misspelled code.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
updateMetadata(data, name, callback)
Update metadata entries.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.updateMetadata('superfakeword', 'superfakeword', function (err, rows) { console.log('updateMetadata Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} data
- The updated data
- {String} name
- The name of the metadata to update.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.
updateWord(updatedWord, oldWord, callback)
Fix misspelled words or typos in words.
Author: Matthew Kastor.
Author: Matthew Kastor.
var cmu = require('cmudict-to-sqlite'); cmu = new cmu.CmudictDb(); cmu.updateWord('superfakewordzzz', 'superfakeword', function (err, rows) { console.log('updateWord Results'); if (err) { console.log(err); } if (rows) { console.log(rows); } // do other stuff with the database . . . cmu.unload(); });
- Parameters:
- {String} updatedWord
- The corrected word.
- {String} oldWord
- The misspelled word.
- {Function} callback
- The callback to execute when results have been retreived. Takes two arguments: error and rows, in that order.