Skip to content

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
henchc committed May 21, 2016
1 parent a25f738 commit 6e13358
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions legalipy1.py
Expand Up @@ -2,8 +2,9 @@
# -*- coding: utf-8 -*-
# created at UC Berkeley 2015
# Authors: Christopher Hench & Alex Estes © 2016
# ==============================================================================

'''This program syllabifies any text in any language
'''This program syllabifies any text in any language
solely on the Onset Maximization principle (Principle of Legality).
Input is text file'''

Expand Down Expand Up @@ -46,7 +47,7 @@ def getonsets(text):

onsets = [x for x in onsets if x != ''] # get rid of empty onsets

#now remove onsets caused by errors, i.e. less than .02% of onsets
# now remove onsets caused by errors, i.e. less than .02% of onsets
freq = Counter(onsets)

total_onsets = 0
Expand All @@ -55,7 +56,7 @@ def getonsets(text):

onsets = []
for k, v in freq.items():
if (v/total_onsets) > .0002:
if (v / total_onsets) > .0002:
onsets.append(k)

return (onsets, tokens)
Expand All @@ -78,11 +79,11 @@ def legalipy(word, onsets):
if vowelcount == 1: # monosyllabic
syllset.append(revword)

#begin main algorithm
# begin main algorithm
elif vowelcount > 1:
syll = ""

#following binaries trigger different routes
# following binaries trigger different routes
onsetbinary = 0
newsyllbinary = 1

Expand All @@ -106,23 +107,29 @@ def legalipy(word, onsets):
syll += letter
onsetbinary = 1

elif letter + syll[-1] in [ons[-2:] for ons in onsets] and syll[-2] in vowels:
elif letter + syll[-1] in [ons[-2:] for ons in onsets] and
syll[-2] in vowels:
syll += letter
onsetbinary = 1

elif letter + syll[-2:][::-1] in [ons[-3:] for ons in onsets] and syll[-3] in vowels:
elif letter + syll[-2:][::-1] in [ons[-3:] for ons in onsets]
and syll[-3] in vowels:
syll += letter
onsetbinary = 1

elif letter + syll[-3:][::-1] in [ons[-4:] for ons in onsets] and syll[-4] in vowels:
elif letter + syll[-3:][::-1] in [ons[-4:] for ons in onsets]
and syll[-4] in vowels:
syll += letter
onsetbinary = 1

#order is important for following two due to onsetbinary variable
elif letter in vowels and onsetbinary == 0: # i.e. syllable doesn't end in vowel (onset not yet found)
# order is important for following two due to onsetbinary
# variable
# i.e. syllable doesn't end in vowel (onset not yet found)
elif letter in vowels and onsetbinary == 0:
syll += letter

elif letter in vowels and onsetbinary == 1: # i.e. syllable ends in vowel, onset found, restart syllable
# i.e. syllable ends in vowel, onset found, restart syllable
elif letter in vowels and onsetbinary == 1:
syllset.append(syll)
syll = letter

Expand All @@ -133,7 +140,8 @@ def legalipy(word, onsets):

syllset.append(syll)

syllset = [syll[::-1] for syll in syllset][::-1] # reverse syllset then reverse syllables
# reverse syllset then reverse syllables
syllset = [syll[::-1] for syll in syllset][::-1]

return (syllset)

Expand Down

0 comments on commit 6e13358

Please sign in to comment.