本文整理汇总了Python中rules.Rules.get_class方法的典型用法代码示例。如果您正苦于以下问题:Python Rules.get_class方法的具体用法?Python Rules.get_class怎么用?Python Rules.get_class使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rules.Rules
的用法示例。
在下文中一共展示了Rules.get_class方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from rules import Rules [as 别名]
# 或者: from rules.Rules import get_class [as 别名]
class Syllabification:
"""
SPPAS automatic syllabification annotation.
"""
def __init__(self, rulesfilename, logfile=None):
"""
Create a new syllabification instance.
Load rules from a text file, depending on the language and phonemes
encoding. See documentation for details about this file.
@param rulesfilename is a file with rules to syllabify.
"""
# Load a set of initial rules from a file:
self.load_rules(rulesfilename)
# Create each instance:
self.phonemes = None
self.syllables = None
self.logfile = logfile
# Initializations
self.vow1 = 0
self.vow2 = 1
# End __init__
# ------------------------------------------------------------------
def load_rules(self, rulesfilename):
"""
Load the list of rules.
@param rulesfilename is a file with rules to syllabify.
"""
try:
self.rules = Rules(rulesfilename)
except Exception as e:
raise IOError("Syll::sppasSyll. Failed in loading rules: %s\n"%str(e))
# End load_rules
# ------------------------------------------------------------------
def get_syllables(self):
"""
Return the syllables.
@return A Transcription() with syllables
"""
return self.syllables
# End get_syllables
# ------------------------------------------------------------------
def add_syllable(self, limit):
"""
Add a syllable to the object "syllables".
Syllables is a list of phonemes between two limits, the one of the
previous syllable and the one in parameter
@param limit is the index of the last phoneme of the previous syllable
"""
#the phoneme at the beginning of the syllable to add is the one which follow
#the last phoneme of the previous syllable
if self.syll.IsEmpty():
starttime = self.phonemes.GetBegin().GetMidpoint()
startradius = self.phonemes.GetBegin().GetRadius()
else:
starttime = self.syll.GetEndValue()
startradius = self.syll.GetEnd().GetRadius()
#the end of the syllable is the end of the phoneme pointed by "limit"
e = self.phonemes[limit].GetLocation().GetEnd().GetMidpoint()
er = self.phonemes[limit].GetLocation().GetEnd().GetRadius()
p = "" #phonemes
c = "" #classes
s = "" #structures
for i in range(self.prevlimit, limit + 1):
#print "infor%d"%i#c%
strphone = self.phonemes[i].GetLabel().GetValue()
#print "phon=%s\n"%strphone#c%
strclass = self.rules.get_class( strphone )
strtype = strclass
if self.is_consonant(strtype):
strtype = "C"
p += strphone
if strtype == "#":
c += strphone
s += strphone
else:
#.........这里部分代码省略.........