https://github.com/shnewto/ttaw
a piecemeal natural language processing library
https://github.com/shnewto/ttaw
alliteration cmu cmudict crates double-metaphone language metaphone natural natural-language natural-language-processing nlp phonemes phones processing pronounce pronounciation rhyme rust syllables
Last synced: 10 months ago
JSON representation
a piecemeal natural language processing library
- Host: GitHub
- URL: https://github.com/shnewto/ttaw
- Owner: shnewto
- License: mit
- Created: 2019-10-23T04:26:29.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-03-23T01:47:59.000Z (about 2 years ago)
- Last Synced: 2025-07-30T15:36:40.818Z (11 months ago)
- Topics: alliteration, cmu, cmudict, crates, double-metaphone, language, metaphone, natural, natural-language, natural-language-processing, nlp, phonemes, phones, processing, pronounce, pronounciation, rhyme, rust, syllables
- Language: Rust
- Homepage:
- Size: 3.29 MB
- Stars: 14
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://github.com/shnewto/ttaw/actions)
[](https://codecov.io/gh/shnewto/ttaw)
[](https://crates.io/crates/ttaw)
[](https://crates.io/crates/ttaw)
[](LICENSE)
# ttaw
talking to a wall, a piecemeal natural language processing library.
## Functionality
- Determine if two words rhyme using the Double Metaphone phonetic encoding
- Determine if two words rhyme using CMUdict phonetic encoding
- Determine if two words alliterate using the Double Metaphone phonetic encoding
- Determine if two words alliterate using CMUdict phonetic encoding
- Get the CMUdict phonetic encoding of a word
- Get the Double Metaphone phonetic encoding of a word (port of [words/double-metahone](https://github.com/words/double-metaphone) library)
## Rhyme
```rust
extern crate ttaw;
use ttaw;
// Initialize the CmuDict with a path to the existing serialized CMU dictionary
// or a directoy containing it. If the dictionary doesn't exisit, it will be
// downloaded and serialized at the location specified by the path parameter.
let cmudict = ttaw::cmu::CmuDict::new("cmudict.json").unwrap();
assert_eq!(Ok(true), cmudict.rhyme("far", "tar"));
assert_eq!(Ok(true), ttaw::metaphone::rhyme("far", "tar"));
assert_eq!(Ok(false), cmudict.rhyme("shopping", "cart"));
assert_eq!(Ok(false), ttaw::metaphone::rhyme("shopping", "cart"));
// Deviations in cmu and metaphone
assert_eq!(true, ttaw::metaphone::rhyme("hear", "near"));
assert_eq!(Ok(false), cmudict.rhyme("hear", "near"));
```
## Alliteration
```rust
extern crate ttaw;
use ttaw;
// Initialize the CmuDict with a path to the existing serialized CMU dictionary
// or a directoy containing it. If the dictionary doesn't exisit, it will be
// downloaded and serialized at the location specified by the path parameter.
let cmudict = ttaw::cmu::CmuDict::new("cmudict.json").unwrap();
assert_eq!(Ok(true), cmudict.alliteration("bounding","bears"));
assert_eq!(true, ttaw::metaphone::alliteration("bounding","bears"));
assert_eq!(Ok(false), cmudict.alliteration("lazy", "dog"));
assert_eq!(false, ttaw::metaphone::alliteration("lazy", "dog"));
```
## CMUdict
```rust
extern crate ttaw;
use ttaw;
// Initialize the CmuDict with a path to the existing serialized CMU dictionary
// or a directoy containing it. If the dictionary doesn't exisit, it will be
// downloaded and serialized at the location specified by the path parameter.
let cmudict = ttaw::cmu::CmuDict::new("cmudict.json").unwrap();
assert_eq!(
cmudict.encoding(("unearthed"),
Ok(Some(vec![vec![
"AH0".to_string(),
"N".to_string(),
"ER1".to_string(),
"TH".to_string(),
"T".to_string()
]]))
);
```
## Double Metaphone
```rust
extern crate ttaw;
use ttaw;
assert_eq!(ttaw::metaphone::encoding("Arnow").primary, "ARN");
assert_eq!(ttaw::metaphone::encoding("Arnow").secondary, "ARNF");
assert_eq!(
ttaw::metaphone::encoding("detestable").primary,
"TTSTPL"
);
assert_eq!(
ttaw::metaphone::encoding("detestable").secondary,
"TTSTPL"
);
```