1

I'm looking for a tool that can change words position in a text. It's something like an article spinner, but without changing the words to synonymous.

An example:

Original text:

I love eating apples and drinking orange juice, it's delicious.

Shuffled text:

It's delicious, I love drinking orange juice and eating apples.

2

I suggest taking a look at the python Natural Language Toolkit, nltk, you will need to install python first if your platform doesn't come with it, i.e. MS-Windows but it is available for most platforms.

The advantage is that rather than simply splitting the sentence into words and shuffling them - hoping for a meaningful result - which you can do in about 3 lines of python you will be able to parse a sentence and reorder retaining the meaning.

  • Free
  • Lots of examples & a book or two
  • You will learn a lot about language structure
  • You shouldn't have to change it t get results for different sentences
0

From the command line available in your Operating System, you can use some tool that deals with regular expressions (also called regex or regexp) like, for example, sed, which is available at least in Linux, Mac OS X, and the BSDs:

$ echo "I love eating apples and drinking orange juice, it's delicious." |
  sed -r 's/(.*), (.*)\./\u\2, \1./'
It's delicious, I love eating apples and drinking orange juice.

The problem with this approach is that the regular expression is not grammatically intelligent by itself, you have to set the rules. But once you grasp basic regex rules, which is not difficult if you have a bit of patience, you can expand it to your heart's desire.

In this particular example, we use echo to output to sentence, and then call sed to process the output from echo:

  • 's/foo/bar/' replaces foo with bar in the sentence.
  • . matches any character.
  • * matches the previous character (.) any number of times.
  • To match an actual dot, we need to escape it with a back slash (\.).
  • The first enclosed match (.*) becomes \1 for our later use, the second \2.
  • \u tells sed to set to uppercase the first character of \2.

sed can also take the input from a text file, like this:

$ sed -r 's/(.*), (.*)./\u\2, \1./' FILENAME.txt
It's delicious, I love eating apples and drinking orange juice.
It's delicious, I love drinking kool-aid and eating french fries.
  • Unfortunately this will only work if a) the parts to be swapped are separated by a comma & b) the first word should remain capitalised when moved after the comma, i.e. it is I. – Steve Barnes Sep 7 '14 at 7:04
  • 1
    @SteveBarnes Yes, although it should be easy for him to get started, all rules will have to be set by hand. I upvoted your answer. – Teresa e Junior Sep 7 '14 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.