Correct Title Case in English

Discuss and share scripts and script files...
Post Reply
Dustydog
Posts: 321
Joined: 13 Jun 2016 04:19

Correct Title Case in English

Post by Dustydog »

This is hardly brilliant, but I find it handy. All it does is change the case of things to be more correct after Applying Title Case To Something. You're certainly welcome to tell me if I ought perhaps to have done it in a different way.

It turns appropriate words into lowercase, has a section one can fill with things like Dvd >> DVD, has a short start on roman numerals. The roman numerals still retain spaces before and afterwards, though most of the more complex ones don't need it; they'd also be more useful if they took into account a following period.

If one simply starts out with a list of appropriate words in a text editor, this isn't hard to create, and the logic is very simple - there's simply a fair amount of data, and I didn't want to do something with a complicated loop. I felt this way was quite straightforward. It's got a relative base title for a multiscript at the beginning, obviously.

Things like this are simply a hassle to write, but I use it constantly when correcting titles, so here you go.

Code: Select all

"Correct Caps In Title Case|||"
//This is actually cleaner code than it looks, and it's reasonably fast; it's simply a list separated by >> for the same list with a cap change. Has surrounding spaces so it catches only interior, discrete words. The first part isn't actually case sensitive, but it's use is more obvious written this way.

 $DoTwice=2;
 While ($DoTwice--){
  rename s, " A | An | The | One | Some | Few >> a | an | the | one | some | few ";
  rename s, " For | And | Nor | But | Or | Yet | So | At | Around | By | After | Along | For | From | Of | On | To | With | Without >> for | and | nor | but | or | yet | so | at | around | by | after | along | for | from | of | on | to | with | without ";
  rename s, " Aboard | About | Above | Across | After | Against | Again | Along | Alongside | Amid | Amidst | Mid | Among | Around | As | Astride | At | Atop | Before | Behind >> aboard | about | above | across | after | against | again | along | alongside | amid | amidst | mid | among | around | as | astride | at | atop | before | behind ";
  rename s, " Below | Beneath | Beside | Besides | Between | Beyond | But | By | Circa | Come | Despite | Down | During | Except | For | From | In | Inside | Into | Less | Like >> below | beneath | beside | besides | between | beyond | but | by | circa | come | despite | down | during | except | for | from | in | inside | into | less | like ";
  rename s, " Minus | Near | Nearer | Nearest | Notwithstanding | Of | Off | On | Onto | Opposite | Out | Outside | Over | Past | Per | Save | Short | Since | Than | Through >> minus | near | nearer | nearest | notwithstanding | of | off | on | onto | opposite | out | outside | over | past | per | save | short | since | than | through ";
  rename s, " Throughout | To | Toward | Towards | Under | Underneath | Unlike | Until | Till | Up | Upon | Upside | Versus | Via | With | Within | Without >> throughout | to | toward | towards | under | underneath | unlike | until | till | up | upon | upside | versus | via | with | within | without ";
 };
 //Catches all if done twice. Could correct by not having things that follow one another in the same row - overlapping spaces aren't caught by this 'rename' construct. Separated in rows simply for length and logical order at the moment.
 //Doesn't include a very few outside cases that wouldn't be encountered.

//Correct by recapping after \s-\s; \.\s - the beginning is done already. This section probably could be done, at least more briefly for the code, with a loop, but at least it's consistent.

//After \s-\s
 rename s, " - a| - an| - the| - one| - some| - few >> - A| - An| - The| - One| - Some| - Few";
 rename s, " - for| - and| - nor| - but| - or| - yet| - so| - at| - around| - by| - after| - along| - for| - from| - of| - on| - to| - with| - without >> - For| - And| - Nor| - But| - Or| - Yet| - So| - At| - Around| - By| - After| - Along| - For| - From| - Of| - On| - To| - With| - Without";
 rename s, " - aboard| - about| - above| - across| - after| - against| - again| - along| - alongside| - amid| - amidst| - mid| - among| - around| - as| - astride| - at| - atop| - before| - behind >> - Aboard| - About| - Above| - Across| - After| - Against| - Again| - Along| - Alongside| - Amid| - Amidst| - Mid| - Among| - Around| - As| - Astride| - At| - Atop| - Before| - Behind";
 rename s, " - below| - beneath| - beside| - besides| - between| - beyond| - but| - by| - circa| - come| - despite| - down| - during| - except| - for| - from| - in| - inside| - into| - less| - like >> - Below| - Beneath| - Beside| - Besides| - Between| - Beyond| - But| - By| - Circa| - Come| - Despite| - Down| - During| - Except| - For| - From| - In| - Inside| - Into| - Less| - Like";
 rename s, " - minus| - near| - nearer| - nearest| - notwithstanding| - of| - off| - on| - onto| - opposite| - out| - outside| - over| - past| - per| - save| - short| - since| - than| - through >> - Minus| - Near| - Nearer| - Nearest| - Notwithstanding| - Of| - Off| - On| - Onto| - Opposite| - Out| - Outside| - Over| - Past| - Per| - Save| - Short| - Since| - Than| - Through";
 rename s, " - throughout| - to| - toward| - towards| - under| - underneath| - unlike| - until| - till| - up| - upon| - upside| - versus| - via| - with| - within| - without >> - Throughout| - To| - Toward| - Towards| - Under| - Underneath| - Unlike| - Until| - Till| - Up| - Upon| - Upside| - Versus| - Via| - With| - Within| - Without";

//After \.\s
 rename s, ". a|. an|. the|. one|. some|. few >> . A|. An|. The|. One|. Some|. Few";
 rename s, ". for|. and|. nor|. but|. or|. yet|. so|. at|. around|. by|. after|. along|. for|. from|. of|. on|. to|. with|. without >> . For|. And|. Nor|. But|. Or|. Yet|. So|. At|. Around|. By|. After|. Along|. For|. From|. Of|. On|. To|. With|. Without";
 rename s, ". aboard|. about|. above|. across|. after|. against|. again|. along|. alongside|. amid|. amidst|. mid|. among|. around|. as|. astride|. at|. atop|. before|. behind >> . Aboard|. About|. Above|. Across|. After|. Against|. Again|. Along|. Alongside|. Amid|. Amidst|. Mid|. Among|. Around|. As|. Astride|. At|. Atop|. Before|. Behind";
 rename s, ". below|. beneath|. beside|. besides|. between|. beyond|. but|. by|. circa|. come|. despite|. down|. during|. except|. for|. from|. in|. inside|. into|. less|. like >> . Below|. Beneath|. Beside|. Besides|. Between|. Beyond|. But|. By|. Circa|. Come|. Despite|. Down|. During|. Except|. For|. From|. In|. Inside|. Into|. Less|. Like";
 rename s, ". minus|. near|. nearer|. nearest|. notwithstanding|. of|. off|. on|. onto|. opposite|. out|. outside|. over|. past|. per|. save|. short|. since|. than|. through >> . Minus|. Near|. Nearer|. Nearest|. Notwithstanding|. Of|. Off|. On|. Onto|. Opposite|. Out|. Outside|. Over|. Past|. Per|. Save|. Short|. Since|. Than|. Through";
 rename s, ". throughout|. to|. toward|. towards|. under|. underneath|. unlike|. until|. till|. up|. upon|. upside|. versus|. via|. with|. within|. without >> . Throughout|. To|. Toward|. Towards|. Under|. Underneath|. Unlike|. Until|. Till|. Up|. Upon|. Upside|. Versus|. Via|. With|. Within|. Without";
 
//A few special cases for CamelBack, ACRONYMN, initials, roman numerals, or whatever personal quirks you wish:
 rename s, "Dvd|Cd|Flac>>DVD|CD|FLAC";
 rename s, " i | ii | iii | iv | v | vi | vii | viii | ix | x >> I | II | III | IV | V | VI | VII | VIII | IX | X "; 
 rename s, " xi | xii | xiii | xiv | xv | xvi | xvii | xviii | xix | xx >> XI | XII | XIII | XIV | XV | XVI | XVII | XVIII | XIX | XX ";

Post Reply