Advertisement
triclops200

WordMerger

Sep 1st, 2011
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | None | 0 0
  1. lettergroups = ["bl","br","ch","cl","cr","ck",
  2.     "dr","ci","fl","fr","gh","gl","gr","kl","kr","mn","nc","ng",
  3.     "py","ss","ou","io","th","sc","ps","ee","ph","pr","qu","pt","st",
  4.     "sh","tr","to","ly","gy","wh", "ry"]
  5. specials = ["io","tio","sio","sci","psy","ee","cio","eo","fly","y","why","cry","try", "dry",
  6.     "alk","k","t","aft"]
  7. vowels = ["a","e","o","i","u"]
  8. cons = ["b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"]
  9. import sys
  10. def containedIn(st,li):
  11.     for i in range(0,len(li)):
  12.         if(st == li[i]):
  13.             return True
  14.     return False
  15. def remStringItem(st,i):
  16.     return st[0:i]+st[i+1:]
  17. def breakIntoGroups(st):
  18.     fin = []
  19.     x=0
  20.     for i in range(0,len(st)-1):
  21.         gro = ""
  22.         gr = False
  23.         vl = False
  24.         if(x<len(st)):
  25.             for ii in range(0,len(vowels)):
  26.                 if st[x] == vowels[ii]:
  27.                     if(x<len(st)-1):
  28.                         if(not containedIn(st[x]+st[x+1],lettergroups)):
  29.                             gro+=st[x]
  30.                         if(not containedIn(st[x+1],vowels)):
  31.                                 vl = True
  32.                                 x+=1
  33.                         else:
  34.                             for ii in range(0,len(lettergroups)):
  35.                                 if st[x]+st[x+1] == lettergroups[ii]:
  36.                                     gro += lettergroups[ii]
  37.                                     gr = True
  38.             if(containedIn(gro,specials) or containedIn(st[x],specials)):
  39.                 if(gro == ""):
  40.                     gro = st[x]
  41.                 if (len(fin)>0):
  42.                     if(containedIn(fin[len(fin)-1]+gro,specials)):
  43.                         gro = fin[len(fin)-1]+gro
  44.                         fin[len(fin)-1] = gro
  45.                         gro = ""
  46.                         x+=1
  47.                 if(x<=len(st)-2):
  48.                     if(containedIn(gro+st[x+1],specials)):
  49.                         gro = st[x-1]+gro
  50.                         fin[len(fin)-1] = remStringItem(fin[len(fin)-1],len(fin[len(fin)-1])-1)
  51.                 try:
  52.                     gro += st[x+2]
  53.                 except:
  54.                     asdsad=0
  55.             if(x<len(st)-1 and not gr):
  56.                 for ii in range(0,len(lettergroups)):
  57.                     if st[x]+st[x+1] == lettergroups[ii]:
  58.                         gro += lettergroups[ii]
  59.                         gr = True
  60.             if(not x<len(st)):
  61.                 for ind in range(0,len(fin)):
  62.                     if(fin[ind][0] == "o" and fin[ind][1] == "g" and ind !=0):
  63.                         fin[ind] = remStringItem(fin[ind],0)
  64.                         fin = fin[0:ind] + ["o"]+fin[ind:]
  65.                 return fin
  66.             if(not gr and not vl):
  67.                 fin += [st[x]]
  68.             elif(gr and not vl):
  69.                 fin += [gro];
  70.                 x+=len(gro)-1
  71.             elif(vl and not gr):
  72.                 fin += [gro+st[x]]
  73.             else:
  74.                 fin += [gro]
  75.                 x+=len(gro)-2
  76.             x+=1
  77.            
  78.         else:
  79.             for ind in range(0,len(fin)):
  80.                 if(fin[ind][0] == "o" and fin[ind][1] == "g" and ind !=0):
  81.                     fin[ind] = remStringItem(fin[ind],0)
  82.                     fin = fin[0:ind] + ["o"]+fin[ind:]
  83.             return fin
  84.     for ind in range(0,len(fin)):
  85.         if(fin[ind][0] == "o" and fin[ind][1] == "g" and ind !=0):
  86.             fin[ind] = remStringItem(fin[ind],0)
  87.             fin = fin[0:ind] + ["o"]+fin[ind:]
  88.     return fin
  89. def breakIntoSyllables(stli):
  90.     fin = []
  91.     x = 0
  92.     for i in range(0,len(stli)):
  93.         gro = ""
  94.         if(x<len(stli)-1):
  95.             if(containedIn(stli[x+1][0],vowels) and gro == "" and not containedIn(stli[x][0],vowels)):
  96.                 gro = stli[x]+stli[x+1]
  97.                 x+=1
  98.             else:
  99.                 gro = stli[x]
  100.         elif(x==len(stli)-1):
  101.             gro = stli[x]
  102.         if(gro != ""):
  103.             fin +=[gro]
  104.         x+=1
  105.     if(fin[len(fin)-1] == "e"):
  106.         del fin[len(fin)-1]
  107.         fin[len(fin)-1]+="e"
  108.    
  109.    
  110.     return fin
  111. k = breakIntoGroups(sys.argv[1])
  112. print k
  113. print breakIntoSyllables(k)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement