Exemplo n.º 1
0
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:
		gemmarker = -1
	if gemmarker > -1 and len(exp) >= gemmarker + 3:
		syl = exp[gemmarker + 1:gemmarker + 3]
		if Syllables.syllableMatches(syl, 'VV'):
			exp.pop(gemmarker)

	word = ''.join(exp)

	return word
Exemplo n.º 2
0
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:
        gemmarker = -1
    if gemmarker > -1 and len(exp) >= gemmarker + 3:
        syl = exp[gemmarker + 1:gemmarker + 3]
        if Syllables.syllableMatches(syl, 'VV'):
            exp.pop(gemmarker)

    word = ''.join(exp)

    return word