Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Oct 17th, 2005, 3:37 PM   #1
MrSmiley
Programmer
 
MrSmiley's Avatar
 
Join Date: May 2005
Posts: 41
Rep Power: 0 MrSmiley is on a distinguished road
PigLattin Converter, count number of words used in dictionary.

Ok, tried for a descriptive title. Anyways, I am having some troubles with my homework...

[PHP]
# Assignment 5 translate a set of strings into piglatting based strings
# It does so by moving leading consonants to the end of the word
# and appending "ay" to the end. (If there are no leading consonants,
# then "shay" is appended.)

#Global Variables, hey if I had a pointer, I'd store these in a 3d array and return all my info in a pointer.--
store = []
storen = []
stores = []
#Function String Breakup ------------------------------------------------------
def strbrk(word, ssize):
tstr = ""
subcount = 0
proper = "?.,';/><\=+-_()!~`@#$%^&*[]{}" #This here code belongs to the daily wtf.
counter = 0
#$store stores the letter, $storen stores the word it's in, and stores stores what part the non alpha is in.--
while counter <= (ssize-1) :
subcount = 0
for letter in word[counter] :
if letter in proper :
store.insert(counter, letter)
storen.insert(counter, counter)
stores.insert(counter, subcount)
subcount+=1
counter+=1
size=len(store)
counter = 0
#Takes the symbols out of the words. Will need these later for reconstruction.
if(size > 0):
while(counter <= size-1):
for letter in word[storen[counter]]:
if(letter in proper) :
subcount =0
else :
tstr+=letter
word[storen[counter]]= tstr.lower()
tstr=""
counter+=1
return word

#Function PigLatin---------------------------------------------------------
def piglatin(ssize, word):
vowels = "aeiou"
tstr =""
counter = 0
while(counter <= ssize-1):
for letter in word[counter]:
tstr+=letter
if tstr[0] in vowels :
tstr = tstr + "sh"
else :
tstr = tstr[1:] + tstr[0]
vowels = vowels + "y"
while not(tstr[0] in vowels) :
tstr = tstr[1:] + tstr[0]
tstr+="ay"
word[counter]=tstr
counter+=1
tstr=""
return word
#Function Translated Output-------------------------------------------------
def toutput(pigword, ssize):
subcount = 0
counter = 0
size = len(storen)
print "\nTranslated sentence:"
while(counter<=size-1) :
pigword[storen[counter]]+= store[counter]
counter+=1
counter = 0
while(counter<=ssize-1):
print pigword[counter],
counter +=1

#void main(int argc, char** argv[], char** env[]) // ---------------------
name = { }
subcount = 0
storec = []
counter = 0
#words2 = raw_input("Please type a line of English words: ")
words2 = "This is it, is it? It is, indeed, it!!"
word = words2.split()
ssize = len(word)
while counter < ssize :
word[counter] = word[counter].lower()
counter+=1
word = strbrk(word, ssize)
pigword = piglatin(ssize, word)
#Stuffs-----------------------------------------------------
counter = 0
while(counter < ssize):
for letter in pigword[counter]:
name[pigword[counter]]=0
counter+=1
counter = 0
size3=len(name)

while (counter < ssize) :
while(subcount < ssize):
if pigword[counter] == pigword[subcount]:
t+=1
name[pigword[counter]] = t
subcount+=1
t=0
counter +=1
#End Stuffs-----------------------------------------------------

toutput(pigword, ssize)
print "\n\nContents of pig-latin dictionary:"
print name
raw_input("\nPress Enter to quit")
[/PHP]

Perticularly in the "Stuffs" block. What I am attempting to do is count how many times a single word is used (such as "is" is used 3 times). I just cannot, for the life of me, figure out how to run a recursive array and get that information out.

Output looks like this:
Translated sentence:
isthay isshay itshay, isshay itshay? itshay isshay, indeedshay, itshay!! 

Contents of pig-latin dictionary:
{'isthay': 1, 'isshay': 0, 'itshay': 0, 'indeedshay': 0}
It is suppose to look like this:
Type a line of English: This is it, is it?   It is, indeed, it!!

Translated sentence:
isthay isshay itshay, isshay itshay?   itshay isshay, indeedshay, itshay!!

Contents of pig-latin dictionary:
indeed : indeedshay 1
is : isshay 3
it : itshay 4
this : isthay 1

Type Enter to finish.

Also, that is my test string, it just made it easier for testing.
MrSmiley is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC