コード例 #1
0
def generate_content(nitems=1):
    """
    This method generates some text about
    dinosaurs and asteroids.

    - Number of lines/items = 1
    """

    body = ""

    # =================================
    # Asteroids

    body += "Asteroid of the Day: "

    corpus = Assembler.load(open("olipy/data/minor_planets.min.json"), tokens_in='citation')

    sentences = []
    names = []
    for sentence, source in corpus.assemble("f.l", min_length=4):
        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()

    asteroid = name
    asteroid += "\n"*2

    for s in " ".join(sentences):
        asteroid += s

    body += asteroid 
    body += "\n"*2

    # =================================
    # Dinosaurs

    body += "In an alternate universe, this asteroid would have annihilated the following dinosaur species:"
    body += "\n"*2

    assembler = WordAssembler(load_json("dinosaurs.json"))
    
    dinos = []
    for z in range(20):

        dino = assembler.assemble_word()
        if dino[0] in 'AEIO':
            dino = "* " + dino
        else:
            dino = "* " + dino
        dinos.append(dino)

    body += "\n".join(dinos)

    # ===============================
    
    return body
コード例 #2
0
ファイル: example.py プロジェクト: 4thAce/olipy
def words():
    common = corpora.words.english_words['words']
    less_common = corpora.words.english_words['words']
    common_corpus = WordAssembler(common)
    full_corpus = WordAssembler(less_common)

    print('You know "%s", "%s", and "%s".' % tuple(common_corpus.assemble_word() for i in range(3)))
    print('But have you heard of "%s", "%s", or "%s"?' % tuple(full_corpus.assemble_word() for i in range(3)))
コード例 #3
0
def words():
    common = corpora.words.english_words['words']
    less_common = corpora.words.english_words['words']
    common_corpus = WordAssembler(common)
    full_corpus = WordAssembler(less_common)

    print('You know "%s", "%s", and "%s".' %
          tuple(common_corpus.assemble_word() for i in range(3)))
    print('But have you heard of "%s", "%s", or "%s"?' %
          tuple(full_corpus.assemble_word() for i in range(3)))
コード例 #4
0
def dinosaurs():
    dinosaurs = corpora.animals.dinosaurs['dinosaurs']
    assembler = WordAssembler(dinosaurs)
    dinos = []
    for i in range(2):
        dino = assembler.assemble_word()
        if dino[0] in 'AEIO':
            dino = "an " + dino
        else:
            dino = "a " + dino
        dinos.append(dino)
    print("Look! Behind that ridge! It's %s fighting %s!" % tuple(dinos))
コード例 #5
0
ファイル: example.py プロジェクト: 4thAce/olipy
def dinosaurs():
    dinosaurs = corpora.animals.dinosaurs['dinosaurs']
    assembler = WordAssembler(dinosaurs)
    dinos = []
    for i in range(2):
        dino = assembler.assemble_word()
        if dino[0] in 'AEIO':
            dino = "an " + dino
        else:
            dino = "a " + dino
        dinos.append(dino)
    print("Look! Behind that ridge! It's %s fighting %s!" % tuple(dinos))
コード例 #6
0
def mashteroids(how_many=10):
    import textwrap
    asteroids = corpora.science.minor_planet_details["minor_planets"]

    # Make an assembler to generate asteroid citations.
    corpus = Assembler.loadlist(asteroids, tokens_in='citation')

    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, and use that to generate a new name
        name_assembler = WordAssembler(names)
        name = name_assembler.assemble_word()
        print(name)
        for s in textwrap.wrap(" ".join(sentences)):
            print(s)
        print("")
コード例 #7
0
ファイル: example.py プロジェクト: 4thAce/olipy
def mashteroids(how_many=10):
    import textwrap
    asteroids = corpora.science.minor_planet_details["minor_planets"]

    # Make an assembler to generate asteroid citations.
    corpus = Assembler.loadlist(asteroids, tokens_in='citation')

    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, and use that to generate a new name
        name_assembler = WordAssembler(names)
        name = name_assembler.assemble_word()
        print(name)
        for s in textwrap.wrap(" ".join(sentences)):
            print(s)
        print("")
コード例 #8
0
import json
from olipy.queneau import WordAssembler
from olipy.data import load_json
import textwrap

assembler = WordAssembler(load_json("dinosaurs.json"))

dinos = []
for i in range(2):
    dino = assembler.assemble_word()
    if dino[0] in 'AEIO':
        dino = "an " + dino
    else:
        dino = "a " + dino
    dinos.append(dino)

print "Look! Behind that ridge! It's %s fighting %s!" % tuple(dinos)
コード例 #9
0
import json
from olipy.queneau import WordAssembler
from olipy.data import load_json
import textwrap

my_json_file = "/Volumes/noospace/Users/charles/codes/riverrun/data/greeknames.json"

assembler = WordAssembler(load_json( my_json_file ))

for i in range(18):

    greek = assembler.assemble_word()
    
    print("Chapter %d: %s"%(i+1,greek)) 

コード例 #10
0
from olipy.queneau import Assembler, WordAssembler
import textwrap

corpus = Assembler.load(open("minor_planets.min.json"), 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
コード例 #11
0
from olipy.queneau import Assembler, WordAssembler
import textwrap

corpus = Assembler.load(open("minor_planets.min.json"), 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
コード例 #12
0
ファイル: Riverrun.py プロジェクト: estheroids/riverrun
 def make_chapter_name(self):
     assembler = WordAssembler(load_json( rr.json_greek_names ))
     if( random.random() < 0.10 ):
         return assembler.assemble_word() + " and " + assembler.assemble_word()
     else:
         return assembler.assemble_word()