本文整理汇总了Python中Base.explode方法的典型用法代码示例。如果您正苦于以下问题:Python Base.explode方法的具体用法?Python Base.explode怎么用?Python Base.explode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Base
的用法示例。
在下文中一共展示了Base.explode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: syllableMatches
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def syllableMatches(syl, form):
""" eg. syllableMatches('rte', '[V]VCe')
capital 'V' or 'C' match vowels and consonants respectively
letters in []'s shows optional letters. checks from the end of the word"""
# FIXME this is not necessarily done on a syllable by syllable basis. sometimes it
# can overlap boundaries
sylMatches = False
# better handling of 'ng' and other double letters
syl = Base.explode(syl)
form = Base.explode(form)
syl = syl[::-1]
form = form[::-1]
#FIXME need to write test about if form longer than syl has correct behavior
#FIXME optional '[]' letters should not increment i
inBrackets = False
j = 0
if len(syl) > 0 and len(syl) >= len(form):
for i in range(len(form)):
if i <= j:
if inBrackets:
# FIXME not sure if there is really anything to do but ignore
if form[i] == '[':
inBrackets = False
j += 1
else:
if form[i] == 'V' and Alphabet.isVowel(syl[j]):
sylMatches = True
j += 1
elif form[i] == 'C' and Alphabet.isConsonant(syl[j]):
sylMatches = True
j += 1
elif form[i] == syl[j]:
#FIXME this may have some false positives
sylMatches = True
j += 1
elif form[i] == ']':
# we are reversed, so close brackets = open brackets
inBrackets = True
else:
sylMatches = False
break
else:
break
return sylMatches
示例2: apostrophePurpose
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def apostrophePurpose(word):
"""is the apostrophe being used for gemination, separate 'n' and 'g', etc."""
exp = Base.explode(word)
purpose = -1
for i in range(len(exp)):
if i > 0 and exp[i] == '\'':
if i < len(exp) - 1:
if Alphabet.isVowel(exp[i - 1]):
if Alphabet.isVowel(exp[i + 1]):
purpose = APOS_PREVENT_GEMMINATION
break
elif exp[i + 1] == 'r':
purpose = APOS_DISRUPT_STRESS
break
else:
if Alphabet.isVowel(exp[i + 1]):
purpose = APOS_GEMINATION_MARKER
break
elif exp[i - 1] == 'n' and exp[i + 1] == 'g':
purpose = APOS_NG_SEPARATOR
break
else:
# FIXME need to test if a catch-all is appropriate. technically the only
# other valid use of a \' is whenever auto-devoicing occurs. (stop + nasal || fric)
#FIXME need to do research on autodevoicing to make sure this ^^ is acurate
# FIXME will need to write a test to make sure cases without auto devoicing are not matched
purpose = APOS_PREVENT_DEVOICING
break
else:
purpose = APOS_SHORT_WORD
return purpose
示例3: getVoicingPattern
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def getVoicingPattern(word):
vp = []
exp = Base.explode(word)
for i in range(len(exp)):
vp.append(isVoiced(word, i))
return vp
示例4: getSyllables
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def getSyllables(word):
""" return a list of the syllables that make up word """
syllables = []
syl = []
exp = Base.explode(word)
for i in range(len(exp)):
c = exp[i]
syl.append(c)
if i < len(exp) - 1:
if Alphabet.isConsonant(c) and Alphabet.isConsonant(exp[i + 1]):
syllables.append(syl)
syl = []
syllables.append(syl)
syl = []
syl2 = []
for s in syllables:
for i in range(len(s)):
if Alphabet.isConsonant(s[i]) and (i > 0 and i < len(s) - 1):
if Alphabet.isVowel(s[i - 1]) and Alphabet.isVowel(s[i + 1]):
syl2.append(syl)
syl = []
syl.append(s[i])
syl2.append(syl)
syl = []
return syl2
示例5: hasRhythmicLength
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def hasRhythmicLength(word, index):
""" does the sylIndex-th syllable have rhythmic vowel length """
exp = Base.explode(word)
syl = Syllables.getSyllables(word)
rl = getRhythmicVowelLengthPattern(word)
rlexp = []
for s in range(len(syl)):
for r in range(len(syl[s])):
rlexp.append(rl[s])
return rlexp[index]
示例6: lSyllableMatches
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def lSyllableMatches(syl, form):
""" eg. syllableMatches('rte', '[V]VCe')
capital 'V' or 'C' match vowels and consonants respectivly
letters in []'s shows optional letters. checks from the start of the word"""
# FIXME this is not necessarily done on a syllable by syllable basis. sometimes it
# can overlap boundaries
sylMatches = False
# better handling of 'ng' and other double letters
syl = Base.explode(syl)
form = Base.explode(form)
if len(syl) > 0:
inBrackets = False
j = 0
for i in range(len(form)):
if inBrackets:
# FIXME not sure if there is really anything to do but ignore
if form[i] == '[':
inBrackets = False
j += 1
else:
if form[i] == 'V' and Alphabet.isVowel(syl[j]):
sylMatches = True
j += 1
elif form[i] == 'C' and Alphabet.isConsonant(syl[j]):
sylMatches = True
j += 1
elif form[i] == syl[j]:
#FIXME this may have some false positives
sylMatches = True
j += 1
elif form[i] == ']':
# we are reversed, so close brackets = open brackets
inBrackets = True
else:
sylMatches = False
break
return sylMatches
示例7: getVoicingText
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def getVoicingText(word):
voi = ''
exp = Base.explode(word)
vpat = getVoicingPattern(word)
for i in range(len(exp)):
voi = voi + exp[i] + ': '
if vpat[i]:
voi += '+ , '
else:
voi += '- , '
# remove trailing ','
voi = voi[:-2]
return voi
示例8: getAutoGemminationPattern
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def getAutoGemminationPattern(word):
gempat = []
exp = Base.explode(word)
rl = getRhythmicVowelLengthPattern(word)
for i in range(len(exp)):
if i > 0 and i < len(exp) - 2:
if Alphabet.isVowel(exp[i - 1]) and Alphabet.isConsonant(exp[i]) and Alphabet.isVowel(
exp[i + 1]) and Alphabet.isVowel(exp[i + 2]):
gempat.append(True)
else:
gempat.append(False)
elif i > 0 and exp[i - 1] == 'e' and hasRhythmicLength(word, i - 1):
gempat.append(True)
else:
gempat.append(False)
return gempat
示例9: isVoiced
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def isVoiced(word, c):
"""test position c to see if it is voiced"""
# FIXME does not properly handle if char other than a stop or fricative is found at 'c'
voiced = True
exp = Base.explode(word)
l = exp[c]
if c == 0 and l == 's':
voiced = False
elif c == len(exp) - 1 and l == 'r':
voiced = False
elif Alphabet.isVoicelessFricative(l):
voiced = False
elif Alphabet.isVoicelessNasal(l):
voiced = False
elif Alphabet.isVoicedFricative(l):
if c > 0 and (Alphabet.isVoicelessFricative(exp[c - 1]) or Alphabet.isStop(exp[c - 1])):
voiced = False
elif c < len(exp) - 1 and Alphabet.isStop(exp[c + 1]):
voiced = False
elif Alphabet.isVoicedNasal(l) and c > 0 and (
Alphabet.isVoicelessFricative(exp[c - 1]) or Alphabet.isStop(exp[c - 1])):
voiced = False
return voiced
示例10: applyPostbase
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def applyPostbase(word, postbase):
""" add a postbase to a word """
#TODO would be cool if you could pass a list of postbases in here and have it do the "right thing"
exp = Base.explode(word)
keepStrongCfinal = False
# @ symbol?
dropVCfinal = False
attachIrregular = False
#keep the final consonant
plus = string.find(postbase, '+')
if plus > -1:
postbase = postbase[:plus] + postbase[plus + 1:]
# FIXME need to check against words that contain '-' as a part of the word
# FIXME this might cause trouble with enclitics
# remove the last consonant
minus = string.find(postbase, '-')
if minus > -1:
postbase = postbase[:minus] + postbase[minus + 1:]
if not Word.isVowel(exp[-1]):
exp.pop(-1)
# remove final 'e'
tilde = string.find(postbase, '~')
if tilde > -1:
postbase = postbase[:tilde] + postbase[tilde + 1:]
if exp[-1] == 'e':
exp.pop(-1)
# choose between letters in parenthesis
paren = string.find(postbase, '(')
if paren > -1:
pl = parenLetter(word, postbase)
#FIXME, what if multiple parens
parenOpen = string.find(postbase, '(')
parenClose = string.find(postbase, ')') + 1
postbase = postbase[:parenOpen] + pl + postbase[parenClose:]
# add gemination if needed
#FIXME not tested on words that contain 2 \' ...does such a word exist?
apos = string.find(postbase, '\'')
if apos > -1:
postbase = postbase[:apos] + postbase[apos + 1:]
# FIXME this may indicate that there's something that needs tweaked about the syllablematches
# function. A short base is defined as [C]VCe, currently this only tests the end of the word.
# this should match VCe and CVCe only
shortA = len(exp) == 3 and Syllables.syllableMatches(exp, 'VCe')
shortB = len(exp) == 4 and Syllables.syllableMatches(exp, 'CVCe')
if shortA or shortB:
exp.pop(-1)
if Syllables.syllableCount(exp) == 1:
exp.append('\'')
elif exp[-1] == 'e':
exp.pop(-1)
# velar dropping suffixes
colon = string.find(postbase, ':')
if colon > -1:
testsuf = exp[-1] + postbase
testExp = Base.explode(testsuf)
colon = testExp.index(':')
velar = testExp[colon + 1]
testExp = testExp[:colon] + testExp[colon + 1:]
if Syllables.syllableMatches(testExp, 'CV' + velar + 'V'): #FIXME might crash if word isn't long enough
testExp = Base.explode(postbase)
colon = testExp.index(':')
testExp.pop(colon)
testExp.pop(colon)
else:
testExp = Base.explode(postbase)
colon = testExp.index(':')
testExp.pop(colon)
postbase = ''.join(testExp)
if postbase[0] == '÷':
keepStrongCfinal = True
if string.find(postbase, ':') > -1:
dropVelar = True
if postbase[0] == '- -':
dropVCfinal = True
if postbase[0] == '%':
attachIrregular = True
word = ''.join(exp)
word = word + postbase
#cleanup for words that wind up not needing the \' for gemination because they are followed by 2 vowels
#FIXME not tested on words that contain 2 \' ...does such a word exist
exp = Base.explode(word)
try:
gemmarker = exp.index('\'')
except ValueError:
#.........这里部分代码省略.........
示例11: syllableCount
# 需要导入模块: import Base [as 别名]
# 或者: from Base import explode [as 别名]
def syllableCount(word):
"""get the number of syllables in word"""
return len(getSyllables(Base.explode(word)))