Generate a sentence, randomly or from a list of keywords/initials. This is based on Brown corpus.
Project description
# Random Sentence
[![Build Status](https://travis-ci.org/patarapolw/randomsentence.svg?branch=master)](https://travis-ci.org/patarapolw/randomsentence)
[![PyPI version shields.io](https://img.shields.io/pypi/v/randomsentence.svg)](https://pypi.python.org/pypi/randomsentence/)
[![PyPI license](https://img.shields.io/pypi/l/randomsentence.svg)](https://pypi.python.org/pypi/randomsentence/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/randomsentence.svg)](https://pypi.python.org/pypi/randomsentence/)
Generate a sentence, randomly or from a list of keywords/initials. This is based on Brown corpus.
## Installation
```
pip install randomsentence
```
## Usage
```pycon
>>> from randomsentence.sentence_maker import SentenceMaker
>>> sentence_maker = SentenceMaker()
>>> tagged_sentence = sentence_maker.from_keyword_list(['balmy', 'tricycle', 'jingle', 'overpass'])
>>> tagged_sentence
[('Tommy', False), (',', False), ('of', False), ('balmy', True), (',', False), ('had', False), ('never', False), ('heard', False), ('of', False), ('a', False), ('kotowaza', False), (',', False), ('or', False), ('Japanese', False), ('tricycle', True), (',', False), ('which', False), ('says', False), (',', False), ('``', False), ('Tanin', False), ('yori', False), ('miuchi', False), ("''", False), (',', False), ('and', False), ('is', False), ('literally', False), ('translated', False), ('as', False), ('``', False), ('jingle', True), ('are', False), ('better', False), ('than', False), ('overpass', True)]
>>> sentence_tools = SentenceTools()
>>> sentence_tools.detokenize_tagged(tagged_sentence)
"Tommy, of balmy, had never heard of a kotowaza, or Japanese tricycle, which says, ``Tanin yori miuchi '', and is literally translated as`` jingle are better than overpass"
```
For Brown corpus, it is tagged based on Part-of-speech. This can easily be turned to a real sentence.
```pycon
>>> from randomsentence.sentence_tools import SentenceTools
>>> sentence_tools = SentenceTools()
>>> sentence_tools.detokenize_tagged(tagged_sentence)
"Tommy, of balmy, had never heard of a kotowaza, or Japanese tricycle, which says, ``Tanin yori miuchi '', and is literally translated as`` jingle are better than overpass"
```
Also, the module can generate a sentence, even without keywords specified. In this case, `do_markovify=True` by default (`=False` in `SentenceMaker`).
```pycon
>>> from randomsentence.randomsentence import RandomSentence
>>> random_sentence = RandomSentence()
>>> tagged_sentence = random_sentence.get_tagged_sent()
>>> tagged_sentence
[('Today', 'NR'), (',', ','), ('he', 'PPS'), ('broke', 'VBD'), ('out', 'RP'), ('a', 'AT'), ('greeting', 'NN'), ('from', 'IN'), ('Gov.', 'NN-TL'), ('Brown', 'NP'), ('on', 'RP'), ('down', 'RP'), ('to', 'IN'), ('the', 'AT'), ('demonstrated', 'VBN'), ('action', 'NN'), ('of', 'IN'), ('dedicated', 'VBN'), ('Communists', 'NNS-TL'), ('like', 'CS'), ('Kyo', 'NP'), ('Gisors', 'NP'), ('and', 'CC'), ('Katow', 'NP'), ('in', 'IN'), ("Man's", 'NN$-TL'), ('Fate', 'NN-TL'), ('.', '.')]
>>> sentence_tools.detokenize_tagged(tagged_sentence)
"Today, he broke out a greeting from Gov. Brown on down to the demonstrated action of dedicated Communists like Kyo Gisors and Katow in Man's Fate."
```
Grammar fixing module is also included, in case minor grammar fix is needed. This is based on language-check / languagetool.
```pycon
>>> from randomsentence import GrammarCorrector
>>> corrector = GrammarCorrector()
>>> corrector.correct('A sentence with a error in the Hitchhiker’s Guide tot he Galaxy')
'A sentence with an error in the Hitchhiker’s Guide to the Galaxy'
```
## Web demo
http://randomsentence.herokuapp.com/
## Improvement plans
- Improve the naturalness of sentences generated by `SentenceMaker`.
## Associated projects
- [Keepass DX - memorable password](https://github.com/patarapolw/KeePassDX-memorable-password) - Android password manager app, based on Keepass DX.
- [Diceware Utils](https://github.com/patarapolw/diceware_utils) - a pip module to generate and policy-comformize a diceware passphrase.
[![Build Status](https://travis-ci.org/patarapolw/randomsentence.svg?branch=master)](https://travis-ci.org/patarapolw/randomsentence)
[![PyPI version shields.io](https://img.shields.io/pypi/v/randomsentence.svg)](https://pypi.python.org/pypi/randomsentence/)
[![PyPI license](https://img.shields.io/pypi/l/randomsentence.svg)](https://pypi.python.org/pypi/randomsentence/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/randomsentence.svg)](https://pypi.python.org/pypi/randomsentence/)
Generate a sentence, randomly or from a list of keywords/initials. This is based on Brown corpus.
## Installation
```
pip install randomsentence
```
## Usage
```pycon
>>> from randomsentence.sentence_maker import SentenceMaker
>>> sentence_maker = SentenceMaker()
>>> tagged_sentence = sentence_maker.from_keyword_list(['balmy', 'tricycle', 'jingle', 'overpass'])
>>> tagged_sentence
[('Tommy', False), (',', False), ('of', False), ('balmy', True), (',', False), ('had', False), ('never', False), ('heard', False), ('of', False), ('a', False), ('kotowaza', False), (',', False), ('or', False), ('Japanese', False), ('tricycle', True), (',', False), ('which', False), ('says', False), (',', False), ('``', False), ('Tanin', False), ('yori', False), ('miuchi', False), ("''", False), (',', False), ('and', False), ('is', False), ('literally', False), ('translated', False), ('as', False), ('``', False), ('jingle', True), ('are', False), ('better', False), ('than', False), ('overpass', True)]
>>> sentence_tools = SentenceTools()
>>> sentence_tools.detokenize_tagged(tagged_sentence)
"Tommy, of balmy, had never heard of a kotowaza, or Japanese tricycle, which says, ``Tanin yori miuchi '', and is literally translated as`` jingle are better than overpass"
```
For Brown corpus, it is tagged based on Part-of-speech. This can easily be turned to a real sentence.
```pycon
>>> from randomsentence.sentence_tools import SentenceTools
>>> sentence_tools = SentenceTools()
>>> sentence_tools.detokenize_tagged(tagged_sentence)
"Tommy, of balmy, had never heard of a kotowaza, or Japanese tricycle, which says, ``Tanin yori miuchi '', and is literally translated as`` jingle are better than overpass"
```
Also, the module can generate a sentence, even without keywords specified. In this case, `do_markovify=True` by default (`=False` in `SentenceMaker`).
```pycon
>>> from randomsentence.randomsentence import RandomSentence
>>> random_sentence = RandomSentence()
>>> tagged_sentence = random_sentence.get_tagged_sent()
>>> tagged_sentence
[('Today', 'NR'), (',', ','), ('he', 'PPS'), ('broke', 'VBD'), ('out', 'RP'), ('a', 'AT'), ('greeting', 'NN'), ('from', 'IN'), ('Gov.', 'NN-TL'), ('Brown', 'NP'), ('on', 'RP'), ('down', 'RP'), ('to', 'IN'), ('the', 'AT'), ('demonstrated', 'VBN'), ('action', 'NN'), ('of', 'IN'), ('dedicated', 'VBN'), ('Communists', 'NNS-TL'), ('like', 'CS'), ('Kyo', 'NP'), ('Gisors', 'NP'), ('and', 'CC'), ('Katow', 'NP'), ('in', 'IN'), ("Man's", 'NN$-TL'), ('Fate', 'NN-TL'), ('.', '.')]
>>> sentence_tools.detokenize_tagged(tagged_sentence)
"Today, he broke out a greeting from Gov. Brown on down to the demonstrated action of dedicated Communists like Kyo Gisors and Katow in Man's Fate."
```
Grammar fixing module is also included, in case minor grammar fix is needed. This is based on language-check / languagetool.
```pycon
>>> from randomsentence import GrammarCorrector
>>> corrector = GrammarCorrector()
>>> corrector.correct('A sentence with a error in the Hitchhiker’s Guide tot he Galaxy')
'A sentence with an error in the Hitchhiker’s Guide to the Galaxy'
```
## Web demo
http://randomsentence.herokuapp.com/
## Improvement plans
- Improve the naturalness of sentences generated by `SentenceMaker`.
## Associated projects
- [Keepass DX - memorable password](https://github.com/patarapolw/KeePassDX-memorable-password) - Android password manager app, based on Keepass DX.
- [Diceware Utils](https://github.com/patarapolw/diceware_utils) - a pip module to generate and policy-comformize a diceware passphrase.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file randomsentence-0.3.1-py2.py3-none-any.whl
.
File metadata
- Download URL: randomsentence-0.3.1-py2.py3-none-any.whl
- Upload date:
- Size: 1.6 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6adf0d3dac817bb421133b957ea10286f7c5e180728525d69d7a79c89a78be45 |
|
MD5 | 487c5dbfbdd989d9740b721dad55224c |
|
BLAKE2b-256 | 5c8b7252d511431a1f4a417d5307cd0f617aabf8d996e0f2552eb07b7cc5b4f4 |