-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathWord.py
29 lines (24 loc) · 827 Bytes
/
Word.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: UTF-8 -*-
import Language
from Syllable import Syllable
def word(text):
return Word(text)
class Word(object):
def __init__(self, text):
self.broken = False
text = text.strip()
if type(text) != type(u''):
text = unicode(text, 'utf-8')
self.text = text
self.transcription = Language.selected_language.annotate_word(self.text.lower())
if self.transcription == None:
self.broken = True
self.transcription = "[" + self.text + "]" # only kept if broken
self.syllables = []
else:
self.syllables = [Syllable(syll) for syll in self.transcription.split('.')]
self.phonemes = sum([syll.phonemes for syll in self.syllables], []) # flatten the list of phonemes
def __repr__(self):
return self.transcription.encode('utf-8')
def __getitem__(self, index):
return self.phonemes[index]