Python lorem ipsum generator

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Pythonic lorem ipsum generator

License

JarryShaw/lorem

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

In publishing and graphic design, lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content.

The lorem module provides a generic access to generating the lorem ipsum text from its very original text:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Note that the lorem module only supports Python versions since 3.5 🐍

Simply run the following to install the current version from PyPI:

Or install the latest version from the git repository:

git clone https://github.com/JarryShaw/lorem.git cd lorem pip install -e . # and to update at any time git pull

Usage of the lorem module is rather simple. Depending on your needs, the lorem module provides generation of words, sentences, and paragraphs:

import lorem print(lorem.get_sentence(count=3))

Eu consectetur ad et, exercitation fugiat occaecat exercitation cillum non ullamco, elit mollit est consectetur. In ex proident esse est aute est mollit, id minim lorem tempor sunt elit. Dolor aliqua non eiusmod officia esse adipiscing.

Please refer to the documentation for more details.

The lorem module utilised unittest.mock to patch the builtin functions from random module. Test cases can be found in test_lorem.py . Contributions are welcome.

About

Pythonic lorem ipsum generator

Источник

A Lorem Ipsum text generator¶

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see

Overview¶

The purpose of this package is to generate random (plausible) text sentences and paargraphs based on a dictionary and a sample text. By default this package will generate Lorem Ipsum style text, but you can customize the generator to effectively load any dictionary and any sample text you like.

This package has en extensive docstring documentation, so you can read more on the online documentation or in the python interactive shell as well.

History¶

Most of the code of this module is taken from lorem-ipsum-generator by James Hales. James stated that his package served his purpose and he was not interested in further development, so I took it over.

Changes¶

  • Added MANIFEST.in
  • Removed dependencies on distribute
  • Applied pep8 and pylint suggested cleanup
  • Fix issue #5
  • Now is a package: fixes datafiles distribution.
  • Added support for python 2.5
  • Added unittests.
  • Added documentation.
  • Added stats to text generators methods in Generator
  • Added generator methods in Generator, for multiple text generations
  • Added stats-less text generators fuctions to module
  • First release.

Basic usage¶

This package provides a text generator class and some utility functions that can simply return the text you desire. There are 2 sets of functions:

  • Those with generate_ prefix that return the desired text and some stats
  • Those with get_ that return the desired text without the stats

On the average, you probably want to import the get_ prefixed functions and just get the text:

>>> from loremipsum import get_sentences >>> >>> sentences_list = get_sentences(5) >>> len(sentences_list) 5 >>> 

If you fancy some statistics, you want to import the generate_ prefixed functions:

>>> from loremipsum import generate_paragraph >>> >>> sentences_count, words_count, paragraph = generate_paragraph() 

If you need generate text based on your own sample text and/or dictionary, you want to import the Generator class:

>>> from loremipsum import Generator >>> >>> with open('data/sample.txt', 'r') as sample_txt >>> sample = sample_txt.read() >>> with open('data/dictionary.txt', 'r') as dictionary_txt >>> dictionary = dictionary_txt.read().split() >>> >>> g = Generator(sample, dictionary) >>> sentence = g.get_sentence() >>> 

Exceptions¶

The sample text must contain one or more empty-line delimited paragraphs, and each paragraph must contain one or more period, question mark, or exclamation mark delimited sentences.

The dictionary must be a list of one or more words.

Functions¶

Utility function to generate a single random sentence with stats.

Parameters: start_with_lorem (bool) – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.
Returns: a tuple with amount of sentences, words and the text
Return type: tuple(int, int, str)

generate_sentences(amount, start_with_lorem=False)

Generator function that yields specified amount of random sentences with stats.

  • start_with_lorem – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.
  • amount (int) – amount of sentences to generate.

a tuple with amount of sentences, words and the text

Utility function to generate a single random paragraph with stats.

Parameters: start_with_lorem – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.
Returns: a tuple with amount of sentences, words and the text
Return type: tuple(int, int, str)

generate_paragraphs(amount, start_with_lorem=False)

Generator function that yields specified amount of random paragraphs with stats.

Parameters: start_with_lorem – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.
Returns: a tuple with amount of sentences, words and the text
Return type: tuple(int, int, str)

get_sentence(start_with_lorem=False)

Utility function to get a single random sentence.

Parameters: start_with_lorem – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.
Returns: a random sentence
Return type: str

get_sentences(amount, start_with_lorem=False)

Utility function to get specified amount of random sentences.

  • start_with_lorem – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.
  • amount (int) – amount of sentences to get.

a list of random sentences.

Utility function to get a single random paragraph.

Parameters: start_with_lorem – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.
Returns: a random paragrpah
Return type: str

get_paragraphs(amount, start_with_lorem=False)

Utility function to get specified amount of random paragraphs.

Parameters: start_with_lorem – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.
Returns: a list of random paragraphs
Return type: list

The Generator class¶

Generates random strings of “lorem ipsum” text.

Markov chains are used to generate the random text based on the analysis of a sample text. In the analysis, only paragraph, sentence and word lengths, and some basic punctuation matter – the actual words are ignored. A provided list of words is then used to generate the random text, so that it will have a similar distribution of paragraph, sentence and word lengths.

Generates a single lorem ipsum paragraph, of random length.

Parameters: start_with_lorem (bool) – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.

generate_paragraphs(amount, start_with_lorem=False)

Generator method that yields paragraphs, of random length.

Parameters: start_with_lorem (bool) – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.

generate_sentence(start_with_lorem=False)

Generates a single sentence, of random length.

Parameters: start_with_lorem (bool) – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.

generate_sentences(amount, start_with_lorem=False)

Generator method that yields sentences, of random length.

Parameters: start_with_lorem (bool) – if True, then the text will begin with the standard “Lorem ipsum. ” first sentence.

reset_statistics()

A dictionary of words that generated sentences are made of, grouped by words length.

Parameters: words (list) – list of words
Return type: dict
Raises: DictionaryError if no valid words in dictionary

paragraph_mean

A non-negative value determining the mean paragraph length (in sentences) of generated sentences. Is changed to match the sample text when the sample text is updated.

Return type: int
Raises: ValueError if value is lesser then 0

paragraph_sigma

A non-negative value determining the standard deviation of paragraph lengths (in sentences) of generated sentences. Is changed to match the sample text when the sample text is updated.

Return type: int
Raises: ValueError if value is lesser then 0

sample

The sample text that generated sentences are based on.

Sentences are generated so that they will have a similar distribution of word, sentence and paragraph lengths and punctuation.

Sample text should be a string consisting of a number of paragraphs, each separated by empty lines. Each paragraph should consist of a number of sentences, separated by periods, exclamation marks and/or question marks. Sentences consist of words, separated by white space.

Parameters: sample (str) – the sample text
Return type: str
Raises: SampleError if no words in sample text

sentence_mean

A non-negative value determining the mean sentence length (in words) of generated sentences. Is changed to match the sample text when the sample text is updated.

Return type: int
Raises: ValueError if value is lesser then 0

sentence_sigma

A non-negative value determining the standard deviation of sentence lengths (in words) of generated sentences. Is changed to match the sample text when the sample text is updated.

Return type: int
Raises: ValueError if value is lesser then 0

words

The plain list of words in the dictionary.

Indices and tables¶

© Copyright 2011-2014, Luca De Vitis . Last updated on Sep 11, 2014.

Versions latest Downloads On Read the Docs Project Home Builds Free document hosting provided by Read the Docs.

Источник

Читайте также:  Process mining in python
Оцените статью