Page 1 of 1

Macro for linguists: CAPS to Small Glosses

Posted: 2008-10-16 12:44:13
by thyx
The macro below takes two or more CAPS + [MFN] followed by Punctuation ans transforms them to Small Caps.
This is an easy way to transform easy, rtf GLOSSES to fancy layout glosses.

It's rather simple, but should be helpful enough.
I hope that'll save some time for someone else, too.
Find All '[A-Z]{2,}', 'E-i'
Menu "To lowercase"
Menu "Display as Small Caps"

Find All '[MFN][-:.) ]', 'E-i'
Menu "To lowercase"
Menu "Display as Small Caps"
Okay, remembering Kino's help in May would have saved even more time. Back then, I just took the commands and forgot about the macro:
http://www.nisus.com/forum/viewtopic.php?f=18&t=3027
:oops:

thyx

Re: Macro for linguists: CAPS to Small Glosses

Posted: 2008-10-18 05:14:08
by Kino
As I'm not a linguist, I may misunderstand the purpose of your macro but you can combine the two Find All commands using | (OR operator).

Code: Select all

Find All '[A-Z]{2,}|[MFN][-:.) ]', 'E-i'
And if you want to apply To lowercase and Display as Small Caps on [MFN] but not on the following [-:.) ], you can use [MFN](?=[-:.) ]) instead of [MFN][-:.) ]. (?=expression) is Look-Ahead you can insert from the action menu (gear) of the Find panel.

Also, perhaps it would be safer to check if those strings have been actually found and selected. It would not be very likely to occur but [1] if there is a selection before running the macro and [2] if nothing matching the find expression has been found, To lowercase and Display as Small Caps will be applied on the original selection. You can prevent it by checking the value returned by Find All command in the following way.

Code: Select all

$numFound = Find All '[A-Z]{2,}|[MFN](?=[-:.) ])', 'E-i'
if $numFound > 0  # Just 'if $numFound' will do the same
   Menu "To lowercase"
   Menu "Display as Small Caps"
end

Re: Macro for linguists: CAPS to Small Glosses

Posted: 2008-10-18 08:08:40
by thyx
Many thanks again!
As I'm not a linguist, I may misunderstand the purpose of your macro but you can combine the two Find All commands using | (OR operator).
Of course you're just right. I'm just starting to use RegEx etc. And I shouldn't spend too much time with technical stuff like that :-)
And if you want to apply To lowercase and Display as Small Caps on [MFN] but not on the following [-:.) ], you can use [MFN](?=[-:.) ]) instead of [MFN][-:.) ]. (?=expression) is Look-Ahead you can insert from the action menu (gear) of the Find panel.
Your solution is definitely better: if one wants to add something after the interpunction, it's back to standard = non-small caps. I think I saw that in the macro description of Find. I haven't been aware that I could add this in the Find panel. 8)

And good idea to check if anything's found at all. Well, better to stay on the safe side.
Anyway, one cannot use this as a macro for whole texts, because there are some acronyms in CAPS around in the normal text.

So, back to work, entering data on some languages literally around the world.

Thomas

PS It looks like that (from our database, with CAPS, but as nice tables)
‘Axrey ha-pgisha hem hitlonenu exad ‘al ha-sheni
after DEF-meeting 3PL:M complain:PAST:3PL one on DEF-two:ORD
After the meeting they complained about each other.

Re: Macro for linguists: CAPS to Small Glosses

Posted: 2008-10-19 08:38:46
by Kino
Hello again,
I haven't been aware that I could add this in the Find panel.
Since the version 1.0.1, Nisus Writer Pro began to use a new regex engine. Unfortunately, help.pdf is not very up-to-date. Features supported by it and its syntax is documented in
http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt

A while ago, I wrote an explanatory document, that you may find interesting if not useful.
http://www2.odn.ne.jp/alt-quinon/files/ ... ro_rtf.zip
Anyway, one cannot use this as a macro for whole texts, because there are some acronyms in CAPS around in the normal text.
Ah, I understand. Then, it would be better to add s to the find option so that the macro work in selection(s) only. Probably you have already done so, though.

Code: Select all

$numFound = Find All '[A-Z]{2,}|[MFN](?=[-:.) ])', 'E-is'
PS It looks like that
If M , F and N are always preceded by a colon, you can use (?<=:)[MFN](?=[-:.) ]) instead of [MFN](?=[-:.) ]) to reduce/avoid unexpected matchings.

Code: Select all

$numFound = Find All '[A-Z]{2,}|(?<=:)[MFN](?=[-:.) ])', 'E-is'
(?<=expression) is called look-behind which is available in the action menu of the Find panel too.