Separates string into camelCase

Asked

Viewed 151 times

-1

It is possible using Javascript to convert string to camelCase, eg: areaEspacoReservado in Área espaço reservado Obs: add the accents where necessary ?

  • 1

    "Add the accents where necessary" Then you pushed a little, right

  • 2

    Yes it is possible, as long as you create a dictionary with all the accented words to make the substitution..

  • What are the criteria? List them all.

  • formaDaForma - is it "formwork form" or "formwork shape"? In some cases the accent will be impossible to determine.

  • 3

    You also have to ensure that there will be no words that are written in the same way but only differentiated by the accent (as "knew", "wise" and "wise"). Maybe in your case you don’t, but anyway. The string variation is so great that you need such a general solution? Maybe it’s easier to map the entire string (areaEspacoReservado) to its respective text...

  • The criteria would be to use values in camelCase that comes in the keys of a json dynamically, I can manipulate this JSON if I can add the accents would have any problem? would help ?

  • @wDrik I believe accents are no problem.

  • 1

    In my opinion, putting the accents correctly makes the question very broad, and liable to be closed for that reason. To be done correctly is probably thing for master’s thesis.

  • In fact it doesn’t even need the dictionary, just an algorithm for the grammatical rules, ex: area is proparoxitone, so will accent...

  • 1

    @Magichat and how exactly the algorithm will know which syllable of each word to define what is oxytone, paroxitone or proparoxitone?

  • @Máttheusspoo look for algorítimo prosódico.

Show 6 more comments

1 answer

1

It is possible but laborious. You would need to create an accent "dictionary" to make the conversion (area for área, for example). The flow would be:

  1. Split the words with a regex
  2. Translate words with dictionary
  3. Manipulate text to keep only the first letter uppercase
  • 3

    And even then it would not solve all the problems, because in these phrases: "Today I went to the office" and "Today I talked to the secretary" which will delimit that secretaria should or should not carry accent?

  • Correct, it would be necessary a contextual analysis also in this case.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.