Slightly OT: Convert words to proper case

C

Chris Dunaway

I used CodeSmith with a template to convert a Sql table to a class, i.
e., it took the column names from the table and create a concrete class
from it. It works fine, but one problem is caused by the fact that the
column names in the table are all UPPERCASE. So a resulting property
might be:

public string ORDERNUMBER
{
get { return _ordernumber; }
set { _ordernumber = value; }
}

and what I would LIKE it to be is:

public string OrderNumber //Note proper case
here
{
get { return _ordernumber; }
set { _ordernumber = value; }
}

I would like to find an algorithm that will convert the name correctly.
Does anyone know of such an algorithm?

I am presuming that since it must pick out the individual words Order
and Number that it must use some sort of dictionary of words. Perhaps
with a setting to indicate the minimum word size such as 5 letters.

It would not produce perfect output, but I think it could be fine tuned
to catch most words. The remaining ones would have to be edited by
hand. Of if there were multiple optons, pop up a dialog to give the
user a choice.

Anyone know of any code that can accomplish this?

Thanks
 
C

cody

Chris said:
I used CodeSmith with a template to convert a Sql table to a class, i.
e., it took the column names from the table and create a concrete class
from it. It works fine, but one problem is caused by the fact that the
column names in the table are all UPPERCASE. So a resulting property
might be:

public string ORDERNUMBER
{
get { return _ordernumber; }
set { _ordernumber = value; }
}

and what I would LIKE it to be is:

public string OrderNumber //Note proper case
here
{
get { return _ordernumber; }
set { _ordernumber = value; }
}

I would like to find an algorithm that will convert the name correctly.
Does anyone know of such an algorithm?

I am presuming that since it must pick out the individual words Order
and Number that it must use some sort of dictionary of words. Perhaps
with a setting to indicate the minimum word size such as 5 letters.

It would not produce perfect output, but I think it could be fine tuned
to catch most words. The remaining ones would have to be edited by
hand. Of if there were multiple optons, pop up a dialog to give the
user a choice.

Anyone know of any code that can accomplish this?

Thanks

maybe you change case in your database in the first place :)
 
C

Chris Dunaway

maybe you change case in your database in the first place :)

I agree, but that is out of my control. I was just wondering if
someone had made a function to convert words, even compound words, to
proper case so that CONTACTNAME or contactname would become
ContactName.

Thanks,

Chris
 
B

Bruce Wood

Chris said:
I used CodeSmith with a template to convert a Sql table to a class, i.
e., it took the column names from the table and create a concrete class
from it. It works fine, but one problem is caused by the fact that the
column names in the table are all UPPERCASE. So a resulting property
might be:

public string ORDERNUMBER
{
get { return _ordernumber; }
set { _ordernumber = value; }
}

and what I would LIKE it to be is:

public string OrderNumber //Note proper case
here
{
get { return _ordernumber; }
set { _ordernumber = value; }
}

I would like to find an algorithm that will convert the name correctly.
Does anyone know of such an algorithm?

I am presuming that since it must pick out the individual words Order
and Number that it must use some sort of dictionary of words. Perhaps
with a setting to indicate the minimum word size such as 5 letters.

It would not produce perfect output, but I think it could be fine tuned
to catch most words. The remaining ones would have to be edited by
hand. Of if there were multiple optons, pop up a dialog to give the
user a choice.

Anyone know of any code that can accomplish this?

I've never heard of any, and it would be tricky to build your own. For
example, is BOATHOUSE to be rendered as Boathouse or BoatHouse? I was
trying to think of a truly ambiguous example, one that could be
capitalized two ways. I haven't come up with one yet, but I'm sure that
they exist.

So, no... never heard of one, but if you manage to get something
working, do post it to GotDotNet or one of the other code sharing
sites. :)
 
L

Larry Lard

Bruce said:
I've never heard of any, and it would be tricky to build your own. For
example, is BOATHOUSE to be rendered as Boathouse or BoatHouse? I was
trying to think of a truly ambiguous example, one that could be
capitalized two ways. I haven't come up with one yet, but I'm sure that
they exist.

Overall. Knightsbridge. Soup.
 
J

John B

Bruce said:
I've never heard of any, and it would be tricky to build your own. For
example, is BOATHOUSE to be rendered as Boathouse or BoatHouse? I was
trying to think of a truly ambiguous example, one that could be
capitalized two ways. I haven't come up with one yet, but I'm sure that
they exist.

So, no... never heard of one, but if you manage to get something
working, do post it to GotDotNet or one of the other code sharing
sites. :)

You could do the following:
Start at the end of the string and move backwards, comparing your
remaining string for matches in your dictionary each time.

ie.
ordernumber X
ordernumbe X
ordernumb X
ordernum X
ordernu X
ordern X
order Y
then the rest of the string and repeat:
number Y

Of course this would require manual cleaning up afterwards and wouldnt
be perfect by any means but it would take care of a fair bit of the work
for you.

JB

Sorry to be replying to this post but I cant find the original thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top