P.S.: Meso is live!

Woo-hoo! I got my mesostic generator up & running on Django at PythonAnywhere, and it does its thing. Rock that mesostic! πŸ™‚

Here’s a sample, read through Django’s template language introduction with “Django” as the spine:

                      Document this
explains the language Just
        xml/html templAtes.
                     oNe more

                althouGh that has a
           special belOw.
                      Dot (.)
                     lOwer filter, which text
               β€œchaineD.” the output
                      A list with
              list|joiN:", " }}. provides about thirty


…hee, I like how it threw “chained” in there. Get it? πŸ˜› Go on now, pull the other one–it has got bells on. Make your own mesostic here: P.S.: Meso.

Side-note: I am posting this in the middle of the night because I thought it was working four hours ago (and wrote the post up to this paragraph then), but apparently when you import a module, its global variables aren’t global for its functions anymore–if program X imports program Y, program X’s global variables are the only global variables, looks like. So I had to figure that out, which took a long time because I thought it was a problem with the textarea widget or Django forms in general, rather than a plain ‘ole Python noob error. Once I found the problem, two lines fixed it up. Shiny. Don’t worry if you didn’t follow that; I had to write it out for me.

Point being, it works! Go! Allez! Make poetic nonsense!


P.S.: Meso

…is the tentative, extremely dorky,* name of my mesostic generator, which now works!

It takes either a plain text file or pasted plain text as input; strips the punctuation if you tell it to; takes the seed (spine) text that you give it; asks how many times the spine should appear; and rocks your mesostic. πŸ˜€

The result is not exactly a true mesostic – which would use a word no more times than it appears in the source text – because it can repeat a word too many times if it has to loop back through. That happens more the shorter the source text is or the more times you repeat the spine. But on the plus side, as long as it can make a mesostic with one copy of the spine (plus the first letter again), it can make as many copies as you want! For now, I’ve set a limit of 20 copies, but I can easily increase that; it’s just in case some fool tries to run the thing a million times or something. πŸ˜‰

The program also handles cases where it can’t create the full mesostic pretty gracefully – instead of just throwing a nasty error, it prints a message that says it couldn’t complete the request, then prints as much of the mesostic as it was able to make. Much nicer, right?

Now, if I can learn a bit of Django, I should be able to get the Python code working online — no JavaScript necessary (though I’d still like to rewrite it in that for my hosted site that doesn’t allow server-side code).

* “P.S.” stands for “poesis spinea” – which I hope is Latin for “spiny poetry.” You know, a poem with a spine. Bad, I know. Pretend I only meant “post-script” if you must. πŸ˜‰

Beginnings of a mesostic generator

I may or may not be making good progress on a mesostic generator (I really need a good name for this thing, like the Mesostisaur or Poeticus mesosticii or…um, something even geekier…? πŸ˜›

I think my read function is good — it takes the text from a txt file and cleans it up nicely (it does remove punctuation; hyphens within words are ok, but anything between words gets stripped away).

But I don’t have a good idea how to test the other subfunctions individually, so I’m trying to do the whole thing and then give it a go. I’m trying to make it so that it loops back to the beginning if it hits the end of the oracle (source text) before it’s done. That may mean that words get used more than once, although hopefully they won’t be repeated excessively or in the same part of the mesostic every time.

It will also abort and print the partially completed mesostic if it can’t finish with the oracle, seed (spine), and number of iterations requested. I didn’t like that the mesostomatic just threw an error…not very polite, right? πŸ˜‰

I should (fingers crossed) be able to get it printed as text in a way that you can just copy & paste it and have it look right as long as you’re in a monospace font.

This is all in Python; I have no idea how much of it I can do in JavaScript, even assuming I get this version going flawlessly. But there you go – some progress, and hope of a mesostic generator that takes plain text input instead of webpages, so you don’t get all the html tags mixed in to your “poem”!

A shiny badge and all

I just started working on the problems at Project Euler, in Python. When I finish my Coursera class on Python programming, get through my introductory Python book to my satisfaction (gotta practice what I read, right?), and make at least one particular project I have in mind*, I’ll probably move on to Java. I’ve never used real Java (just JavaScript, and that only a little), so I’ve got to get cracking if I want to waive the MCIT core course in Python & Java. (And I do.)

But, hey, I get a little badge that reports my progress in Project Euler, see?:

Arestelle at Project Euler


* The mesostomatic that we used in ModPo seems to be totally defunct; it and its explanation page have been throwing 404s for months. I want to make a new one – first in Python, to get the algorithm right, and then in something I know how to put online, i.e., JavaScript (which I haven’t used for about 5 years now…yikes).

Updated Al Bhed – English translator

The suggestion I received won’t work for the translator, it turns out. My friend pointed out the maketrans() and translate() string methods, which I didn’t know about, but those wouldn’t allow me to skip the sections of text that the translator is supposed to leave alone (Al Bhed leaves proper names be, don’t you know?).

But I did switch to building the dictionary within the code instead of either accessing an external file or defining the whole thing explicitly. So now I enter the lowercase of each and let the program add the caps and build the dicts itself.

I also realized that in the parsed version of the input, the key for each substring to be translated is always even & the key for each substring to leave alone is always odd, so I simplified from a {int: list of int, str} to a {int: str} dict and check the key’s modulus (remainder) over 2 to tell whether to translate. The updated file is in the same place; here’s the new code.

Edit: One more update — for x in y iteration rather than a while loop in the parsing function. It’s a teeny bit cleaner, I think.

''' Al Bhed/English "Translator"
Python 3.3
by vyh, updated 4/1/2013, created 3/31/2013 '''

def buildDictionary():
    e, ab = 'abcdefghijklmnopqrstuvwxyz', 'ypltavkrezgmshubxncdijfqow'
    e += e.upper()
    ab += ab.upper()
    engToAlBhed, alBhedToEng = {}, {}
    for i in range(len(e)):
        engToAlBhed[e[i]] = ab[i]
        alBhedToEng[ab[i]] = e[i]
    return (engToAlBhed, alBhedToEng)

def parseInput(s):
    parsedS, j, n = {0: ''}, 0, len(s)
    for i in range(n):
        if s[i]=='~':
            if i+1<n:
                j += 1
                parsedS[j] = ''
        parsedS[j] += s[i]
    return parsedS

def translate(text,dictionary):
    text = parseInput(text)
    translation = ''
    for key in range(len(text)):
        noTranslate, subString = key%2, text[key]
        if noTranslate:
            translation += subString
            for char in subString:
                if char in dictionary:
                    translation += dictionary[char]
                    translation += char
    return translation

if __name__ == '__main__':
    dictionary = {}
    dictionary[1], dictionary[2] = buildDictionary()
    while True:
        c = int(input('Welcome to the Al Bhed Translator! 
                    Your choices are:\n'\
                    '1. English to Al Bhed\n'\
                    '2. Al Bhed to English\n'\
                    'Which would you like to use (1 or 2)? '))
        text = input('Thank you! Enter the text to translate 
                    below. \n'\
                    'If a part is already translated, 
                    put a ~ before and after it.\n')
        print("Original text: ", text)
        print("Translated text: ", translate(text,dictionary[c]))
        if input('Translate more? y/n: ')!='y':

input('Press the enter key when you want to exit the program.')