Esempio n. 1
0
    def __from_xml(self, node):

        assert node.localName == "unit"

        P = {}

        P["syllables"] = int(node.getAttribute("syllables"))
        P["meter"] = node.getAttribute("meter")

        x = node.getAttribute("rhyme")
        if x:
            P["rhyme"] = x

        P["is_beginning_of_line"] = bool(
            node.getAttribute("is_beginning_of_line"))
        P["is_beginning_of_stanza"] = bool(
            node.getAttribute("is_beginning_of_stanza"))
        P["is_end_of_line"] = bool(node.getAttribute("is_end_of_line"))
        P["is_end_of_stanza"] = bool(node.getAttribute("is_end_of_stanza"))

        P["is_head"] = bool(node.getAttribute("is_head"))
        P["is_tail"] = bool(node.getAttribute("is_tail"))

        P["id"] = int(node.getAttribute("id"))

        self.__populate(**P)

        if node.getAttribute("is_bound"):
            tok = None
            if node.getAttribute("binding_is_break"):
                tok = gnoetics.token_lookup_break()
            else:
                x = node.getAttribute("binding")
                if node.getAttribute("binding_is_punctuation"):
                    x = "*punct* %s" % x
                tok = gnoetics.token_lookup(x)

            assert tok.has_left_glue() == bool(
                node.getAttribute("has_left_glue"))
            assert tok.has_right_glue() == bool(
                node.getAttribute("has_right_glue"))

            if tok:
                self.bind(tok)
Esempio n. 2
0
    def __from_xml(self, node):

        assert node.localName == "unit"

        P = {}

        P["syllables"] = int(node.getAttribute("syllables"))
        P["meter"]     = node.getAttribute("meter")
        
        x = node.getAttribute("rhyme")
        if x:
            P["rhyme"] = x

        P["is_beginning_of_line"]   = bool(node.getAttribute("is_beginning_of_line"))
        P["is_beginning_of_stanza"] = bool(node.getAttribute("is_beginning_of_stanza"))
        P["is_end_of_line"]         = bool(node.getAttribute("is_end_of_line"))
        P["is_end_of_stanza"]       = bool(node.getAttribute("is_end_of_stanza"))

        P["is_head"] = bool(node.getAttribute("is_head"))
        P["is_tail"] = bool(node.getAttribute("is_tail"))

        P["id"] = int(node.getAttribute("id"))

        self.__populate(**P)

        if node.getAttribute("is_bound"):
            tok = None
            if node.getAttribute("binding_is_break"):
                tok = gnoetics.token_lookup_break()
            else:
                x = node.getAttribute("binding")
                if node.getAttribute("binding_is_punctuation"):
                    x = "*punct* %s" % x
                tok = gnoetics.token_lookup(x)

            assert tok.has_left_glue() == bool(node.getAttribute("has_left_glue"))
            assert tok.has_right_glue() == bool(node.getAttribute("has_right_glue"))

            if tok:
                self.bind(tok)
Esempio n. 3
0
#!/usr/bin/python

import random, sys, string, time
import gnoetics

p = gnoetics.Sonnet()

p.bind_left(0, gnoetics.token_lookup_break())
p.bind_left(1, gnoetics.token_lookup("the"))
p.bind_left(2, gnoetics.token_lookup("insane"))
p.bind_left(3, gnoetics.token_lookup("butchershop"))
p.bind_left(4, gnoetics.token_lookup("was"))
p.bind_left(5, gnoetics.token_lookup("undertow"))
p.bind_left(6, gnoetics.token_lookup("before"))
p.bind_left(7, gnoetics.token_lookup("*punct* ."))
p.bind_left(8, gnoetics.token_lookup_break())
p.bind_left(9, gnoetics.token_lookup("who"))
p.bind_left(10, gnoetics.token_lookup("soever"))
p.bind_right(13, gnoetics.token_lookup("monkey"))

print p.to_string()