import json import random import re import textwrap from corpus import Corpus from queneau import Assembler, CompositeAssembler, WordAssembler corpus = Assembler.loadlist( Corpus.load("boardgames"), tokens_in='description' ) no_punctuation_at_end = re.compile("[a-zA-Z0-9]$") whitespace = re.compile("\s+") how_many = 10 for i in range(how_many): sentences = [] names = [] genres = [] mechanics = [] for line, source in corpus.assemble("0.l"): if no_punctuation_at_end.search(line): line += "." sentences.append(line) names.append(source['name']) genres.append([genre for id, genre in source.get('boardgamecategory', [])]) mechanics.append([mechanic for id, mechanic in source.get('boardgamemechanic', [])]) # Make assemblers for single- and multi-word names. single_word_assembler = WordAssembler()
import json from queneau import Assembler import textwrap from corpus import Corpus corpus = Assembler.loadlist(Corpus.load("shakespeare_sonnets"), tokens_in='lines') print "\n".join(line for line, source in corpus.assemble('0.l'))
from queneau import Assembler, WordAssembler import textwrap from corpus import Corpus corpus = Assembler.loadlist(Corpus.load("minor_planets"), tokens_in='citation') how_many = 100 for i in range(how_many): sentences = [] names = [] for sentence, source in corpus.assemble("f.l", min_length=3): sentences.append(sentence) names.append(source['name']) # Make a new assembler from the names of the asteroids that were chosen. name_assembler = WordAssembler(names) name = name_assembler.assemble_word() print(name) for s in textwrap.wrap(" ".join(sentences)): print(s) if i < how_many-1: print()
from queneau import Assembler, WordAssembler import textwrap from corpus import Corpus corpus = Assembler.loadlist(Corpus.load("minor_planets"), tokens_in='citation') how_many = 100 for i in range(how_many): sentences = [] names = [] for sentence, source in corpus.assemble("f.l", min_length=3): sentences.append(sentence) names.append(source['name']) # Make a new assembler from the names of the asteroids that were chosen. name_assembler = WordAssembler(names) name = name_assembler.assemble_word() print name for s in textwrap.wrap(" ".join(sentences)): print s if i < how_many - 1: print