예제 #1
0
def rhyme_sound(sentence):
    tagged_sentence = tag(sentence)
    without_punctuation = filter(compose(is_alpha_tag, second), tagged_sentence)
    ws = list(map(first, without_punctuation))

    if is_empty(ws):
        return None

    last_word = last(ws)
    phonemes = word_to_phonemes(last_word)

    if is_empty(phonemes):
        return None

    return "".join(phonemes[-3:])
예제 #2
0
def expand_multiclauses(sentences):
    # TODO consider itertools
    split = []
    for sentence in sentences:
        tagged_sentence = tag(sentence)
        if not is_empty(tagged_sentence):
            split += split_multiclause(sentence, tagged_sentence)
    return split
예제 #3
0
def map_letters_to_sounds(conn: Connection, corpus_id: int, template, sound_cache=None):
    letters = list(set(pluck(template, "rhyme")))
    if is_empty(letters):
        cache = {}
    else:
        sounds = sound_cache if sound_cache is not None else unique_sounds(conn, corpus_id)
        cache = dict(map(lambda l: [l, choice(sounds)], letters))
    return cache
예제 #4
0
def expand_multiclauses(sentences):
    # TODO consider itertools
    split = []
    for sentence in sentences:
        tagged_sentence = tag(sentence)
        if not is_empty(tagged_sentence):
            split += split_multiclause(sentence, tagged_sentence)
    return split
예제 #5
0
파일: cthulhu.py 프로젝트: amshenoy/prosaic
def map_letters_to_sounds(db, template, sound_cache=None):
    letters = list(set(pluck(template, "rhyme")))
    if is_empty(letters):
        cache = {}
    else:
        sounds = sound_cache if sound_cache is not None else build_sound_cache(db)
        cache = dict(map(lambda l: [l, choice(sounds)], letters))
    return cache
예제 #6
0
파일: cthulhu.py 프로젝트: amshenoy/prosaic
def ruleset_to_line(db, ruleset):
    line = None
    while not line:
        lines = list(db.find(ruleset.to_query()))
        if is_empty(lines):
            ruleset.weaken()
        else:
            line = choice(lines)
    return line
예제 #7
0
def ruleset_to_line(db, ruleset):
    line = None
    while not line:
        lines = list(db.find(ruleset.to_query()))
        if is_empty(lines):
            ruleset.weaken()
        else:
            line = choice(lines)
    return line
예제 #8
0
def map_letters_to_sounds(db, template, sound_cache=None):
    letters = list(set(pluck(template, "rhyme")))
    if is_empty(letters):
        cache = {}
    else:
        sounds = sound_cache if sound_cache is not None else build_sound_cache(
            db)
        cache = dict(map(lambda l: [l, choice(sounds)], letters))
    return cache
예제 #9
0
def ruleset_to_line(conn, corpus_id, ruleset) -> str:
    if ruleset.contains(dogma.BlankRule):
        return ("",)

    line = None
    while not line:
        sql = ruleset.to_query(conn)

        lines = conn.execute(sa.text(sql).params(corpus_id=corpus_id)).fetchall()
        if is_empty(lines):
            ruleset.weaken()
        else:
            line = choice(lines)
    return line
예제 #10
0
 def prime_cache(self, conn, corpus_id):
     log.debug('building phrase cache')
     sql = """
     select p.line_no, p.source_id
     from phrases p
     join corpora_sources cs
     on p.source_id = cs.source_id
     where corpus_id = :corpus_id
     and p.stems @> ARRAY[:keyword]
     """
     self.phrase_cache = conn.execute(sa.text(sql)\
                                      .params(keyword=self.keyword,
                                              corpus_id=corpus_id))\
                         .fetchall()
     if is_empty(self.phrase_cache):
         self.strength = 0
예제 #11
0
파일: dogma.py 프로젝트: soywalker/prosaic
 def prime_cache(self, conn, corpus_id):
     log.debug('building phrase cache')
     sql = """
     select p.line_no, p.source_id
     from phrases p
     join corpora_sources cs
     on p.source_id = cs.source_id
     where corpus_id = :corpus_id
     and p.stems @> ARRAY[:keyword]
     """
     self.phrase_cache = conn.execute(sa.text(sql)\
                                      .params(keyword=self.keyword,
                                              corpus_id=corpus_id))\
                         .fetchall()
     if is_empty(self.phrase_cache):
         self.strength = 0
예제 #12
0
 def first_consonant_sound(word):
     phonemes = word_to_phonemes(word)
     if not is_empty(phonemes):
         return find_first(is_consonant_phoneme, phonemes)
     else:
         return first(consonant_re.findall(word.upper()))
예제 #13
0
 def prime_cache(self, db):
     print('building phrase cache')
     self.phrase_cache = list(db.find({'stems': self.keyword}))
     if is_empty(self.phrase_cache):
         self.strength = 0
예제 #14
0
파일: dogma.py 프로젝트: amshenoy/prosaic
 def prime_cache(self, db):
     print('building phrase cache')
     self.phrase_cache = list(db.find({'stems': self.keyword}))
     if is_empty(self.phrase_cache):
         self.strength = 0