當前位置: 首頁>>代碼示例>>Python>>正文


Python Rules.get_class方法代碼示例

本文整理匯總了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:
#.........這裏部分代碼省略.........
開發者ID:drammock,項目名稱:sppas,代碼行數:103,代碼來源:syllabification.py


注:本文中的rules.Rules.get_class方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。