コード例 #1
0
def word_to_phonemes(word):
    result = cmudict_dict.get(word.lower(), None)
    if result is None:
        # TODO I don't really like this. Should at least return None.
        return []
    else:
        return first(result)
コード例 #2
0
def split_multiclause(sentence, tagged_sentence):
    # extract the text the divider tag represents
    divider = first(find_first(is_divider, tagged_sentence))
    if divider is not None:
        first_clause = sentence[0:sentence.index(divider)].rstrip()
        second_clause = sentence[sentence.index(divider) + 1:].lstrip()
        return [first_clause, second_clause]
    else:
        return [sentence]
コード例 #3
0
ファイル: nlp.py プロジェクト: merlinschumacher/prosaic
def word_to_phonemes(word):
    result = cmudict_dict.get(word.lower(), None)
    if LANGUAGE == "german":
        print("This most likely generates rubbish. There is no german phoneme database implemented")
    if result is None:
        # TODO I don't really like this. Should at least return None.
        return []
    else:
        return first(result)
コード例 #4
0
ファイル: nlp.py プロジェクト: merlinschumacher/prosaic
def split_multiclause(sentence, tagged_sentence):
    # extract the text the divider tag represents
    divider = first(find_first(is_divider, tagged_sentence))
    if divider is not None:
        first_clause = sentence[0:sentence.index(divider)].rstrip()
        second_clause = sentence[sentence.index(divider)+1:].lstrip()
        return [first_clause, second_clause]
    else:
        return [sentence]
コード例 #5
0
ファイル: nlp.py プロジェクト: merlinschumacher/prosaic
def word_to_phonemes(word):
    result = cmudict_dict.get(word.lower(), None)
    if LANGUAGE == "german":
        print(
            "This most likely generates rubbish. There is no german phoneme database implemented"
        )
    if result is None:
        # TODO I don't really like this. Should at least return None.
        return []
    else:
        return first(result)
コード例 #6
0
ファイル: generation.py プロジェクト: soywalker/prosaic
def extract_rule(conn, corpus_id, letter_sound_map, raw_pair):
    rule_key = first(raw_pair)
    value = second(raw_pair)
    rule = None

    if rule_key == 'rhyme': rule = dogma.RhymeRule(letter_sound_map.get(value))
    elif rule_key == 'blank': rule = dogma.BlankRule()
    elif rule_key == 'alliteration': rule = dogma.AlliterationRule(value)
    elif rule_key == 'keyword': rule = dogma.KeywordRule(value, conn, corpus_id)
    elif rule_key == 'fuzzy': rule = dogma.FuzzyKeywordRule(value, conn, corpus_id)
    elif rule_key == 'syllables': rule = dogma.SyllableCountRule(value)

    return rule
コード例 #7
0
    def source_rm(self):
        # ugh i know; TODO figure out how to do this with ORM
        conn = self.engine.connect()
        session = get_session(self.db)
        unlink_sql = """
        delete from corpora_sources
        where source_id = :source_id
        """

        source_delete_sql = """
        delete from sources
        where name = :source_name
        """
        phrase_delete_sql = """
        delete from phrases
        where source_id = :source_id
        """
        name = self.args.source_name
        source_id = first(session.query(Source.id).filter(Source.name == name).one())
        conn.execute(text(unlink_sql).params(source_id=source_id))
        conn.execute(text(phrase_delete_sql).params(source_id=source_id))
        conn.execute(text(source_delete_sql).params(source_name=name))
コード例 #8
0
 def source_ls(self):
     session = get_session(self.db)
     for name in session.query(Source.name):
         print(first(name))
コード例 #9
0
 def corpus_ls(self):
     session = get_session(self.db)
     for name in session.query(Corpus.name):
         print(first(name))
コード例 #10
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()))