Jump to content

Change Case tp Proper with Mary/ann in the record


jpmiller

Recommended Posts

When I use the toTitleCase function I would like the letter after / to be capitalized.

 

The data source contains names with /

i.e.: MARY/ANN to Mary/ann is what I get now

i.e.: MARY/ANN to Mary/Ann is the result expected

 

Also: How do I retain suffix capitalization when the name is one field?

i.e.: John Doe, III instead of John Doe, Iii

 

Thank you,

Jeff

Link to comment
Share on other sites

First, I would ask to you to please refer to the many threads discussing the ToTitleCase function and its myriad limitations:

http://forums.pti.com/showthread.php?t=2731

http://forums.pti.com/showthread.php?t=2569

http://forums.pti.com/showthread.php?t=297

 

These are due to the fact that all the ways that humans might decide that names should be capitalized can't possibly be reduced to a computer algorithm, as capitalization itself is arbitrary, with more exceptions than hard-and-fast rules. No amount of code is going to be able to anticipate and "properly" capitalize names like these:

  • McDonald
  • d'Angelo
  • O'Neil
  • Mies van der Rohe
  • Leonardo di Caprio
  • Quincy Jones, MD
  • Director of Marketing
  • NE 1st Street
  • John Doe III
  • John Smith, CEO

Just to name a few of an uncountable number of examples. There's no complete list of exceptions to title casing. Like many "rules" about how text should be typeset and formatted, this is one of those things that's as much art as science.

 

You also have to be careful with non-ASCII (sometimes called "special") characters, with various umlauts and diacriticals and accents, such as "ñ" or "ü", in non-English names, especially with JavaScript Regular Expressions, which do not make distinctions about such characters when identifying things like word boundaries.

 

So hopefully I've tempered your expectations about exactly what can be accomplished with a "title case" function or rule. Your best bet is to have the original name, in the original, proper case, on hand in your data, before it's gone through some kind of transformation, such as CASS processing which "normalizes" names by converting them to all caps, because such a transformation is "lossy" and can't be reliably reversed.

 

That said, if you look at the ToTitleCase function in Builtins.js, you can see that it has been through a few revisions. Please DO NOT edit Builtins.js, but if you want slightly different ToTitleCase functionality, you can copy the function from there and paste it into your own rules, with a different name. If you were to do this, and in your own version of the function, uncomment the line below the comment "This doesn't properly handle accented characters," then it will do what you want, for a name like "MARY/ANN":

function CustomToTitleCase(string, leaveAllCapsWords)
{
   //if((typeof string != "number") && (typeof string != "string"))
   //    ThrowError("ToTitleCase", "The input string is invalid.");

   // This doesn't properly handle accented characters.
   return String(string).toLowerCase().replace(/\b\w/g, function(w){return w.toUpperCase()});
}

return CustomToTitleCase("MARY/ANN");
// returns "Mary/Ann"

Though obviously the problem mentioned in that comment will occur with a name such as "Niña", which is why that change was made to the rule in the first place. But that change obviously affected strings with things like slashes and other punctuation, or really anything other than spaces, delimiting different words in a name. Like I said, there isn't one master algorithm which can handle every possible way of doing capitalization, and every "fix" has its own trade-offs.

 

As for "suffix capitalization", such as "John Doe, III", that's also hard to reduce to an algorithm, but there was a lot of discussion about just that kind of thing in this thread:

http://forums.pti.com/showthread.php?t=2731

And I suggested this:

var result = ToTitleCase(Field("Full Name"));
var Exceptions = [ "I", "II", "III", "IV" ];
for (var i in Exceptions)
{
   var re = RegExp("\\b" + Exceptions[i] + "\\b", "gi");
   result = result.replace(re, Exceptions[i]);
}
return result;

Though again, there are many, many possible exceptions to title casing, including honorariums, abbreviations, and acronyms such as CEO, MD, POTUS, etc. Those could all be added to that Exceptions array, but it's a game you're never going to win.

 

I will add that, with FusionPro 10.1, you can specify as many instances of the "Preserve Case of Word or Phrase" callback XML rule as you want, which can be used to preserve the case of these kinds of abbreviations, even when ToTitleCase is called, as the FusionPro.Composition.AddTextReplacement function called in that rule works at a very low level in the typesetter. So you could have a series of rules like this:

http://forums.pti.com/attachment.php?attachmentid=1900&stc=1&d=1539030542

 

Or, you could have a series of these "whole word" exceptions defined in OnJobStart, like so:

var Exceptions = [ "I", "II", "III", "IV", "MD", "CEO" ];
for (var i in Exceptions)
   FusionPro.Composition.AddTextReplacement(Exceptions[i], Exceptions[i], false, true);

Though again, the task of constantly adding "new" exceptions to this list as you encounter them in your data will be a never-ending one.

PreserveCase.jpg.faedbe224a293ea4a95e34d4548fcb99.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...