Program to reorder words in text

I’m looking for a program that will reorder the words in large blocks of text without any analysis, or probability consideration. I want to use it for writing. There used to be one. Right now there doesn’t seem to be one by my searches, just things like it that don’t do the job.

Anyone know any?

What do you mean by ‘reorder’?

Something like a “Travesty Generator” that takes text and produces new (gibberish) text that follows the same overall patterns of probability? Those are jolly fun, and, just recently, I went out on Google searching for an app, and couldn’t find any. Bummer! I used to have an old DOS mode toy that did that.

If you mean taking text and randomizing the word order…

“text and word mean If you order randomizing order taking…”

I’d recommend writing one for yourself in BASIC. It really ought to be pretty doggone easy. I could do it, and I’m a total schlub at programming.

(I should be able to program a Travesty Generator, but that’s just beyond the limits of my skill.)

Here is a link to a web-based travesty generator.

Input:

Output:

Have fun!

There was an old CP/M spelling checker called “The Word” that I sometimes miss. One thing you could do was feed it a text file and it would return a list of all the different words in in and how many times each was used in descending order, I think it was.

Anyway, it was very handy for catching yourself from over-using any particular out-of-the-ordinary word. (Really great for those of us who abuse adverbs.)

Anyone know of a present day program that will do that?

There are word cloud generators which are kind of cool.

Well, what I want is simply to jumble the words in a different order. I don’t want any probability values or interference. I want to be the creative mover. I want it to take large blocks of text, say 2000 words and just jumble the words around.

Trinopus: This would be a real project for me. I have Pascal 1 and 2 in my past, plus my textbook and my notes. Do you really think I could do this? How would I start? Will I need a basic textbook? Could I use Pascal? How do you implement it on your PC?
Thx

Pascal is good for a lot, but it is notoriously weak on text data manipulation.

If you know Pascal, you can pick up Basic really quickly.

The first trick is to find an application of Basic for your PC. Check out justbasic.com, which has a free, simple, pretty direct app. Did I mention free?

As I see it, the structure is this:

Open a file, pointing to your initial text file. Let’s say it is “One Two Three Four.”

Input data from that file, one character at a time. Buffer the characters, and, when you hit a space (or the end-of-file) increment the word-counter, dump the buffer into the word array, and reset the letter counter. Now you have the following data:

WORDS(n) where WORDS(1) = “One”, WORDS(2) = “Two,” etc.

Pick a random number, j, from one to n. If j=3, the WORDS(j) = “Three.”

Now you’ve got to keep track of the numbers available. In this example, I want to remove “3” from the controlling array, so that the next random choice can only be among 1, 2, and 4. I’m too lazy to go into that right now; it involves a second array of NUMBERS, where you remove the chosen element from the array, and close up the gap.

Keep doing this till you exhaust the array…

If I’m talking Martian, I apologize. All of this is really about the limits of my programming skill, but if you’ve had Pascal classes, you’re probably following or even ahead a bit.

(I don’t actually have Justbasic – but I think I need to get it! It looks pretty keen, and even does GUI apps. And it’s free!)

I just threw together a very simple C program that almost does what you want.



#include	<stdlib.h>
#include	<stdio.h>
#include	<string.h>

char	Word[10000][100];
int	Numwords;

int main(int argc, char **argv)
{
	int	j;

	while (1 == scanf("%s", Word[Numwords++]))
		;
	while (Numwords) {
		j = rand() % Numwords--;
		printf("%s%s", Word[j], Numwords ? " " : "
");
		strcpy(Word[j], Word[Numwords]);
	}
}


Given this as the input file:
Now is the time for all good men to come to the aid of their party.
The quick brown fox jumped over the lazy dog.
The program produced this:
the brown their The dog. aid jumped party. to men over the Now fox of lazy time is come to the good for quick all

I say “almost” does what you want because it has fixed maxima for word length and number of words, and will crash if those limits are exceeded. It doesn’t do anything intelligent with punctuation or capitalization. (It’s details like that that change a one-minute project into a two-hour project.)

ETA: For me a computer without a C compiler is like a banana split without a banana. I realize others may be going “Whaaaat?”

You can’t really intelligently deal with punctuation or capitalization without some probability analysis anyway. The best you could do is strip all punctuation and lowercase all words in the dictionary (and just assume anything capitalized and not in your dictionary is a proper noun).

This is super straightforward in Python, by the way



import random, string

file = open("file.txt", "r")
text = file.read()
words = text.split()

random.shuffle(words)

print string.join(words)

E: This doesn’t strip punctuation or change casing. The modification would be really simple unless you were really concerned about preserving numbers with decimal places or emoticons.

Here’s an updated version which is about as smart with punctuation and capitalization as I can get it without going into attempting to decide if words are proper nouns or not.


import random, string

# Read in the file and shuffle the words around; keeps punctuation
file = open("file.txt", "r")
text = file.read()
words = text.split()

random.shuffle(words)

# Make all words lowercase unless they follow punctuation.
sentence_terminators = ['.','!','?']
prev_word = ""
out = []
for word in words:
	first_char = ""

	if prev_word == "" or prev_word[len(prev_word)-1] in sentence_terminators:
		first_char = word[0].upper()
	else:
		first_char = word[0].lower()

	out.append(first_char + word[1:])
	prev_word = word
# Output the string with a space between every word, and end the sentence
# with a random piece of punctuation.
print (string.join(out) + random.choice(sentence_terminators))

I could’ve done the string replacement in place instead of making a whole new list, but you could run this on all the Harry Potter books in one text file and still probably have memory to spare on a low end computer. Prose isn’t that big.

Wow. This is some real progress. So far, questions I have got:

If there is “basic” “C” and “Python” referenced here, which is best? (I guess the one which you have been so kind to write code for me for?),

Given that I don’t need sentence ending, or punctuation, and that a limit on word length is ok if it is 100 letters (? was that what it was?), at least not below 25, say. Cases are not important either.

If the coding has been done here on this thread already, how do I implement it on my PC given the language of the optimal program herein?
Thx

Is it possible to treat punctuation marks as words too? (This would randomize the sentences. (Maybe the apostrophes could be ignored for this purpose?)

You can do it in five minutes in Perl - have a hash where the key is the word and the value is the number of times it has been seen. There are some Modules to read Word files which would probably be useful for this. You could get fancy and put plurals in with non-plurals if you wanted to.

Python is obviously a more powerful language – compare Jragon’s first program with mine. Mine implements the Fisher–Yates-Knuth shuffle with a few slightly arcane lines; Jragon needs only random.shuffle(words). (Call me an old man who refuses to learn if you wish, but after decades of practice with C, a language which gives huge semantic meaning to white space (:smack:) annoys greatly.)

The key questions are: (1) which, if any, program would you feel comfortable making changes to; and (2) which programming environment is easiest to set up on your machine.

But a more interesting question is: What is your project? I’m guessing you may want to compose a puzzle like the following.

I’ve scrambled a 100-word excerpt from each of four very famous books. Identify the books. (In some cases I’ve deleted a word that might make it to easy.)

[QUOTE=famous book #1]

thick They the Of again, snoring they half So they made got thieves bottle hiding arms. gabble, a bottle; the and money-bag a we off not and I to easy each to and didn’t sneaked me they the and That get a-snoring in tighter an when to his was had king hour wigwam again. remember and satisfied. as deny in tackled the went both noticed took got the got, about so the as and to they feel other’s powerful long about but long before lovinger enough into for and mellow to comfort, HIS got forget mellow, course the
[/QUOTE]

[QUOTE=famous book #2]

Thus, which stage the which below. which preceded On descent be at any they those for however, in the lived hardly which We are seventh the and the in offspring modified the of theory, nearly sixth history general to those the modified the and of and of succeeded must, parents that evident fail at character between the stage; will between be this diagram lived are the great could in hence character at it. that still life intermediate of the earth’s that stage, allow the of became it great in which fauna period intermediate above same more fifth forms is
[/QUOTE]

[QUOTE=famous book #3]

water Depart consumed enemies with let to I For of receive me, couch grave my enemies. ashamed and my for my the make them old Lord suddenly. of The Let all my it there my eye I groaning; will hath because of Mine my ashamed vexed: the swim; return the bed remembrance weeping. all mine my hath am the weary in waxeth from iniquity; thee: is supplication; grief; heard all tears. I of voice and prayer. mine all thanks? night workers be thee because the is who give heard in shall with sore death of ye be no
[/QUOTE]

[QUOTE=famous book #4]

heavenly But Yet thyself strong on climb’d majesty; Lo! looks and from Resembling burning are pilgrimage: a thou sight, Like youth his sacred diest still, duteous, son. weary 'fore way: his The his age, orient look middle homage Serving tract, he Attending on his And in Unlook’d, his the unless feeble having gracious low eyes, So thou, hill, now to looks his in beauty when car, Lifts age, From adore converted with in steep-up light the thy another golden highmost Doth his with get eye mortal from when head, under reeleth up each new-appearing noon: the day, pitch, outgoing the
[/QUOTE]

I just DL Python but can’t get it recognized after editing the path. I watched the video, and the dudes path started with C: and all. Mine doesn’t, for starters, and when I put in the additions and tried it all kinds of ways it didn’t recognize
The other thing is my C prompt comes up with my name as directory. It’s confusing and I don’t know if its messing me up.
The version on the video was a 2.5 version and mine is 3.4.3. I’m using this on Windows 7, which maybe I can’t do.
I don’
t know.

My project is just simply to take large files and scramble the words (but not jumble the letters) and use the results for my composing. Like the “cut up” method.

It looks like Python is a “supported” programming language for doing something like this. I figured it was my best bet. I don’t know.

I’m going to want to have a source file and a destination file in windows, and not on DOS, obviously.

You got some old books here I think. Is #2 Darwin? Is James Fenimore Cooper in there?

The program looks like it would serve my purposes.

Bingo on #2. I took an excerpt randomly from Origin of Species and deleted one instance of ‘species.’

The other three books are perhaps even more famous than Darwin’s – much more famous than The Last of the Mohicans.

There were some non backwards compatible changes from Python 2 to 3
The big one is you can no longer do
print blah
print is now a function so you have to do
print (blah)

Also, Unicode is now default. Since you are not manipulating text at the byte level this shouldn’t be a problem.

If you type “python” (after cd ing to the install directory) what error do you get? You should get “>>>” as a prompt.

Brian
(far from a Python expert)