Skip to main content
# 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.

Release files for randomsentence 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for randomsentence 0.3.1
File Interpreter ABI Platform
randomsentence-0.3.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / randomsentence-0.3.1-py2.py3-none-any.whl

Download URL randomsentence-0.3.1-py2.py3-none-any.whl
Size 1.6 MB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6adf0d3dac817bb421133b957ea10286f7c5e180728525d69d7a79c89a78be45
BLAKE2b-256 checksum
How to use checksums
5c8b7252d511431a1f4a417d5307cd0f617aabf8d996e0f2552eb07b7cc5b4f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.1 This release

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page