Re: [Tutor] thesaurus

2009-07-13 Thread Dave Angel
Pete Froslie wrote: The url function btw: def url(): fin = open("journey_test.txt", "r") response = re.split(r"[/|/,\n, , ,:\"\"\.?,)(\-\<>\[\]'\r']", fin.read()) thesaurus = API_URL + response[word_number] + '/' #API_URL is established at the start of the code return thesaurus

Re: [Tutor] thesaurus

2009-07-12 Thread Pete Froslie
> > You don't seem to understand functions. Part of the point is to *avoid* > global variables. If everything a function uses is passed in as arguments, > and if everything it produces is returned as return value(s), it's much > easier to see its effect. And to make sure it doesn't have bugs.

Re: [Tutor] thesaurus

2009-07-12 Thread Dave Angel
Pete Froslie wrote: so, I've been playing with the functions a bit-- took a little time to get the hang of them after I started that other mess. Initially, I've done the opposite suggested here by creating functions without the input values. I do see the where it will pay off in re-usability that

Re: [Tutor] thesaurus

2009-07-12 Thread Emile van Sebille
On 7/12/2009 12:01 PM Pete Froslie said... (2)not sure why this function doesn't work: word_count = 0 #set up variable to increment through text def increment(x): return x+1 increment(word_count) You need to capture and assign the result (or possibly restructure to work

Re: [Tutor] thesaurus

2009-07-12 Thread Pete Froslie
so, I've been playing with the functions a bit-- took a little time to get the hang of them after I started that other mess. Initially, I've done the opposite suggested here by creating functions without the input values. I do see the where it will pay off in re-usability that route.. Alan, I'll re

Re: [Tutor] thesaurus

2009-07-12 Thread Alan Gauld
"Pete Froslie" wrote This seems the basic form for a function: *def** hello*(): *print* "Hello World!" *return* That is a very limited form that encourages bad practice. The more general form is: def aFunction(inputValue1, inputValue2,...): # do some processing here retu

Re: [Tutor] thesaurus

2009-07-11 Thread Dave Angel
Pete Froslie wrote: the trailing comma is getting me much closer right away! -- will read about the other options you suggest (rstrip(); stdout: write()) I clearly have a few other issues I need to sort out now. i guess I've been assuming that print was a good way to trace what is happening rathe

Re: [Tutor] thesaurus

2009-07-11 Thread Pete Froslie
the trailing comma is getting me much closer right away! -- will read about the other options you suggest (rstrip(); stdout: write()) I clearly have a few other issues I need to sort out now. i guess I've been assuming that print was a good way to trace what is happening rather than thinking about

Re: [Tutor] thesaurus

2009-07-11 Thread Dave Angel
Pete Froslie wrote: thanks for the advice Alan.. I am wondering about the following: new_word = response3[2] old_word = response[word_number] #this works but adds carriage returns* for line in fileinput.FileInput("journey_test.txt",inplace=1): line = line.replace(old_word, new_word)

Re: [Tutor] thesaurus

2009-07-11 Thread Pete Froslie
thanks for the advice Alan.. I am wondering about the following: new_word = response3[2] old_word = response[word_number] #this works but adds carriage returns* for line in fileinput.FileInput("journey_test.txt",inplace=1): line = line.replace(old_word, new_word) print line It seem

Re: [Tutor] thesaurus

2009-07-11 Thread ALAN GAULD
> I am having trouble with probably the most simple part: > I cannot seem to go back into the 'txt' file and replace the word I just > searched with the new word! Its not a good idea to try to read and write to the same file at the same time. The normal approach is to weither ead the file into

Re: [Tutor] thesaurus

2009-07-11 Thread Pete Froslie
So, I basically have this working so that it pulls a word from a 'txt' file; searches for the synonym in the thesaurus; returns the result... but then I am having trouble with probably the most simple part: I cannot seem to go back into the 'txt' file and replace the word I just searched with the n

Re: [Tutor] thesaurus

2009-07-10 Thread ALAN GAULD
> right now, but Chinese apparently has no distinct verb forms for past, > present, > future. So they rely on other words to indicate which they might mean. Chinese also has the problem of relying on intonation to distinguish between identically spelled words. We have the same in English

Re: [Tutor] thesaurus - translation, actually

2009-07-10 Thread Paul McGuire
My favorite rendition of this is in the related field of text-to-speech. In early Object Management Group days, OMG conference proceedings were available as transcripts, but there was substantial delay in getting these out. An attempt to automate this with TTS software of the time was discarded q

Re: [Tutor] thesaurus

2009-07-10 Thread Dave Angel
Kent Johnson wrote: On Fri, Jul 10, 2009 at 7:08 AM, Dave Angel wrote: Alan Gauld wrote: Or the translation program that translated the expression Out of sight, out of mind from English to Russian and back with the result: Invisible, lunatic Or the expression: "The

Re: [Tutor] thesaurus

2009-07-10 Thread Kent Johnson
On Fri, Jul 10, 2009 at 7:08 AM, Dave Angel wrote: > Alan Gauld wrote: >> Or the translation program that translated the expression >> >> Out of sight, out of mind >> >> from English to Russian and back with the result: >> >> Invisible, lunatic > Or the expression: > "The spirit is willing, but t

Re: [Tutor] thesaurus

2009-07-10 Thread Dave Angel
Alan Gauld wrote: "Angus Rodgers" wrote parsing these two sentences: Time flies like an arrow. Fruit flies like a banana. Or the translation program that translated the expression Out of sight, out of mind from English to Russian and back with the result: Invisible, lunatic Alan G.

Re: [Tutor] thesaurus

2009-07-08 Thread Robert Berman
http://pywordnet.sourceforge.net/ This will get you started. This is a tad easier to play with than its newer implementation. Read and experiment. it may meet most of your needs in this arena. Good Luck, Robert On Wed, 2009-07-08 at 18:28 -0400, Pete Froslie wrote: > okay.. I'm getting the ha

[Tutor] thesaurus

2009-07-08 Thread Pete Froslie
okay.. I'm getting the hang of python a little more. I'd like to try something a bit more complicated (for me). I would like to convert each word in a series of paragraphs to its first matching synonym in a thesaurus. I'm a bit stuck as how to start.. I think I understand how to split and parse the