def __init__(self): file = 'Wiseau.txt' with open(file, 'r') as sample_file: sample = sample_file.read().decode('utf-8') dictionary = self.buildDict(file) self.generator = Generator(sample, dictionary)
def get_generator(cls): if cls.sentences is None: word_path = TextGen.get_data_file_path("wordlist.txt.gz") with gzip.open(word_path, "rt", encoding="utf-8") as fin: cls.sentences = fin.readlines() if cls.dictionary is None: json_path = TextGen.get_data_file_path("worddict.json.gz") with gzip.open(json_path, "rt", encoding="utf-8") as fjson: cls.dictionary = json.load(fjson) sample = random.randint(0, len(cls.sentences) - 1) sentence = cls.sentences[sample] generator = Generator(sentence, cls.dictionary) return generator
def generate_docs(file_number, nb_paragraphs): filename = "/tmp/SherlockHolmes.txt" with open(filename, 'r') as sample_txt: s = sample_txt.read() #.decode('utf-8') s = s.split("\n") s = np.random.choice(s, len(s) // 2) s = "\n".join(s) diconame = "/tmp/dictionary.txt" with open(diconame, 'r') as dico_txt: d = dico_txt.read() #.decode('utf-8') dictionary = d.replace("\n", " ").split() g = Generator(sample=s, dictionary=dictionary) outputfile = "/tmp/data/{}.txt".format(file_number) list_paragraphs = get_paragraphs(g, nb_paragraphs) with open(outputfile, "w") as f: f.write("\n\n".join(list_paragraphs))
Team, ) from sentry.event_manager import EventManager from sentry.plugins.sentry_mail.activity import emails from sentry.utils.dates import to_datetime, to_timestamp from sentry.utils.email import inline_css from sentry.utils.http import absolute_uri from sentry.utils.samples import load_data from sentry.web.decorators import login_required from sentry.web.helpers import render_to_response, render_to_string from six.moves import xrange logger = logging.getLogger(__name__) loremipsum = Generator() def get_random(request): seed = request.GET.get("seed", six.text_type(time.time())) return Random(seed) def make_message(random, length=None): if length is None: length = int(random.weibullvariate(8, 3)) return " ".join(random.choice(loremipsum.words) for _ in range(length)) def make_culprit(random): def make_module_path_components(min, max):
from loremipsum import Generator dictionary = [] with open('/usr/share/dict/words', 'r') as dictionary_txt: dictionary = [x.strip() for x in dictionary_txt.readlines()] gen = Generator(None, dictionary) while (True): print(gen.generate_paragraph()[2])
import os from loremipsum import Generator PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) sample = file(PROJECT_ROOT + '/data/sample.txt').read() dictionary = file(PROJECT_ROOT + '/data/dictionary.txt').read().split('\n') ipsum_generator = Generator(sample, dictionary) def get_sentence(): return list(ipsum_generator.generate_sentences(1))[-1][-1] def get_sentences(amount): return [x[-1] for x in ipsum_generator.generate_sentences(amount)] def get_paragraph(): return list(ipsum_generator.generate_paragraphs(1))[-1][-1] def get_paragraphs(amount): return [x[-1] for x in ipsum_generator.generate_paragraphs(amount)] if __name__ == '__main__': print("Sentence: %s" % get_sentence()) print("Sentences: %s" % get_sentences(5)) print("Paragraph: %s" % get_paragraph()) print("Paragraphs: %s" % get_paragraphs(5))
import json from loremipsum import Generator from pymongo import MongoClient, ASCENDING, DESCENDING import random g = Generator() g.sentence_mean = 2 def buildNestedSets(collection): collection.drop() collection.create_index([('parent', ASCENDING)]) collection.create_index([('left', ASCENDING)]) collection.create_index([('right', ASCENDING)]) root_id = collection.insert({'_id': '0', 'name': 'root', 'parent': None}) for fid in [str(i) for i in range(1, 8)]: _fid = collection.insert({ 'name': g.generate_sentence()[2], 'parent': root_id }) for sid in [fid + '.' + chr(i) for i in range(ord('A'), ord('Z') + 1)]: _sid = collection.insert({ 'name': g.generate_sentence()[2], 'parent': _fid }) for ssid in [sid + '.' + str(i) for i in range(1, 8000)]: _ssid = collection.insert({ 'name': g.generate_sentence()[2],
sys.path.append(".") # noqa os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") # noqa django.setup() # noqa from django.db import connection from django.utils import timezone from random import randrange, choice, shuffle, random, choices from datetime import datetime, timedelta from loremipsum import Generator from english_words import english_words_set from sis.models import Profile, Message, Major, SemesterStudent, Student, Semester loremgen = Generator(dictionary=english_words_set) def get_sentence(): (w, s, text) = loremgen.generate_sentence() return text def get_paragraph(): (w, s, text) = loremgen.generate_paragraph() return text # for every student, 1-3 messages. and some replies def rand_between(timedate1, timedate2): aDate = timedate1 + random() * (timedate2 - timedate1)