Replace and swap elements

For all things Mellel

Moderators: Eyal Redler, redlers, Ori Redler

Post Reply
agse
Got the styles thing figured out
Posts: 12
Joined: Wed Sep 19, 2007 9:08 pm
Location: Portugal

Replace and swap elements

Post by agse »

Hi!

I want to find a sequence of words and change its order; say I search for 'Mary' 'Wilson' and replace it with 'Wilson' 'Mary'.
Can this be done in Mellel? I'm sure it can, but I searched the guide and the forum and couldn't find an answer.

Thanks for any help,
André
Hans-Reinhard Koch
Knows everything, can prove it
Posts: 98
Joined: Mon Oct 31, 2005 5:59 pm
Location: Bonn Germany

Re: Replace and swap elements

Post by Hans-Reinhard Koch »

If I got you right, that's an easy one.
Type command-F for the find replace dialog. Type Mary Wilson in the find box and type Wilson Mary in the replace box.
But who is Mary Wilson?
Regards
Hans-Reinhard
Hans-Reinhard Koch, Bonn, Germany
agse
Got the styles thing figured out
Posts: 12
Joined: Wed Sep 19, 2007 9:08 pm
Location: Portugal

Re: Replace and swap elements

Post by agse »

Sorry, I see I didn't express myself correctly.

Of course, changing the order of a single set of words is no problem - a simple find & replace would do.
What I want is something different: I want to change all occurrences of words meeting certain criteria. Let me illustrate with a simple example: suppose I have a list of names in the order 'Last name, First name' and that I want that list in the order 'First name, Last name'. For the sake of simplicity, let's assume there nothing else in my document.
The find part is easy (ignoring the proper syntax): A,B. Can I get B A using the replace part?
In Word find & replace it goes like this (using wildcards): FIND (<*>), (<*>) REPLACE \2 \1
Is it possible to do this in Mellel? Since it uses regular expressions I would say it is, but I ignore how to define the replace line.

I need to prepare a large tagged corpus for automatic parsing and this involves the permutation of some sequences. Mellel FIND is much more powerfull than Word equivalent and that is why I am using it: using Mellel I can do a lot of things that are impossible to do using Word. But to perform the reordering step I must go back to Word -- unless someone tells me how to do it in Mellel :)

Regards,
André
Mart°n
Knows everything, can prove it
Posts: 672
Joined: Fri Oct 21, 2005 2:09 am
Location: Germany

Re: Replace and swap elements

Post by Mart°n »

You can do this in Mellel too.

Fist, you have to do the Find part. As I don’t know your search criteria, I use “Mary” and “Wilson” in this example but you use put more sophisticated search strings than those. So insert:

Mary (whitespace) Wilson

into your search field. (comments in round parenthesis by me). As you probably don’t want to have an whitespace as search criteria, delete the whitespace and use the drop down menu above the search field (Insert element) to insert a [*] (any character) element. After this, not only “Mary Wilson” will be found but also “Mary_Wilson”. If you double click the [*] (any character) element, you could change its repetition (how many of that kind should be found between Mary and Wilson). If you set that to “Repetition: Range, Min: 1, Max: 22 and Greedy enabled“ the string “Mary is in the house of Wilson” will also be found.

Now to the more interesting part.
You could divide your search elements into groups. To do this, select “Mary” and press the [ ] button (two squared brackets) below the the search field. Continue to select the [*]1>20 element (the any character 1-20) and press the group button again. Then select “Wilson” and press the group button again. You’ll notice that every group automatically gets a number so your search string should look similar to this now:

[1 Mary] [2 [*]1>20] [3 Wilson]

If this is the case, you could go to the “Replace” field. Arrived here, you’ll have to insert a “Backreference” element from the “Insert Element“ right above the Replace field. The Backreference simply grabs a “Reference” from the Find field and puts it into the “Replace” field. The references itself are the just created groups. As you like to have all the content from the Search field in the Replace field, you’ll have to insert 3 Backreferences into the Replace field. Having done this, double click the first element and in the upcoming popup chose “Group Index: 3”. This means that this Backreference element grabs the content of the 3rd Group of the Find field. Continue with the other two Backreference elements and assign them the numbers 2 and 1. Your Replace field should look similar to this:

[<3] [<2] [<1]

Your original search:
[1 Mary] [2 is in the house of] [3 Wilson]

will now replaced by:

[3 Wilson] [2 is in the house of] [1 Mary]

As said a few lines above, you could now replace “Mary” and “Wilson“ with anything you like (Wildcards, Character Ranges, Word Boundaries, Digits) by using the “Insert Element” menu. You also could limit (or expand) the “any character” Element between the first- and family name as you like.

Hope this helps
agse
Got the styles thing figured out
Posts: 12
Joined: Wed Sep 19, 2007 9:08 pm
Location: Portugal

Re: Replace and swap elements

Post by agse »

Mart°n wrote:You can do this in Mellel too.

[...]

Hope this helps
Martºn,

Yes, it helps. This is the information I was looking for. I'm really gratefull.

Thank you very much for sharing your time and your knowledge.

André
Post Reply