0

I have a requirement where in i have a dropdown for some String texts which have accent characters as well as english characters. Now when i search with English characters i should be able to search for its equivalent accent characters as well. Convert english characters to its equivalent accent characters. Now when i provide input as DAG i should have the below output :

ÐÁĞ
DAG

I had thought of a solution to have HashMap where i can map all the English alphabets with the accent characters. But thought if there could be a library already doing this job. I tried all ways but didnt find any. Please advise.

sTg
  • 4,313
  • 16
  • 68
  • 115
  • 1
    Does [this](https://stackoverflow.com/questions/2373213/java-ignore-accents-when-comparing-strings) answer your question? – Sweeper Aug 17 '20 at 08:22
  • @Sweeper - IT should work for all accents and symbols and i want conversion of english characters to accent. – sTg Aug 17 '20 at 08:25
  • 1
    Does this answer your question? [Is there a way to get rid of accents and convert a whole string to regular letters?](https://stackoverflow.com/questions/3322152/is-there-a-way-to-get-rid-of-accents-and-convert-a-whole-string-to-regular-lette) – River Aug 17 '20 at 08:27
  • @River - this is not what i am looking for. I want to convert English characters which is my input to accent characters which would be my output. – sTg Aug 17 '20 at 08:32
  • Seems like you have to implement a search-function, I suggest you to use a index, like *Lucene* which already does this with the [ASCIIFoldingFilter](https://lucene.apache.org/core/4_9_0/analyzers-common/org/apache/lucene/analysis/miscellaneous/ASCIIFoldingFilter.html) – Lino Aug 17 '20 at 08:33
  • How can my question be marked as duplicate when my requirement altogether is different. I want to convert english characters. Kindy reopen my question – sTg Aug 17 '20 at 08:33
  • 1
    @sTg how should the program know which accents it should use? Are you targeting a specific language? – Lino Aug 17 '20 at 08:36
  • 2
    @sTg using a hashMap would be the best approach in my opinion. Assuming it's a one time setup and a one-one mapping, you would need to define ~26 (maybe 26*2 if you want caps as well) mappings which seems very easy to do. The only thing I would say is that I don't understand is how you are having a one to one mapping at all. It seems incorrect that you are mapping english characters to accented characters. – Soccergods Aug 17 '20 at 08:59
  • For most letters, there are multiple accented forms (á, à, â, ä etc) - do you want to pick one of the forms? Based on which set of rules? Or do you ant a list containing all permutations of possible forms (would get huge pretty fast)? – Hulk Aug 17 '20 at 09:30
  • I want all permutation and combinations @Hulk – sTg Aug 17 '20 at 09:32
  • See [The table for the Latin Script](https://en.wikipedia.org/wiki/Latin_script_in_Unicode) - So you want to map `Basic Latin` letters to all of their correspinding `Latin-1 Supplement` forms. Do you also want `Latin Extended-A` forms? – Hulk Aug 17 '20 at 09:42
  • 2
    Either way, this is a rather unusual requirement, and I fear you'll have to build those lists yourself. – Hulk Aug 17 '20 at 09:48
  • I wanted both Latin-1 Supplement and Latin Extended-A... Oh so i should iterate the list for each character and generate a combination of letters?. Aint there any library @Hulk – sTg Aug 17 '20 at 09:50
  • Well, most libraries are focussed on providing the other direction - i.e. Normalization to the Basic Latin forms, ignoring them during search, sorting them based on locale specific rules, etc. See for example [Collator](https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/text/Collator.html) and [CollationElementIterator](https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/text/CollationElementIterator.html) – Hulk Aug 17 '20 at 10:07
  • As the permutations you are looking for mostly won't make sense in any natural language, there is rarely a need to generate something like that. – Hulk Aug 17 '20 at 10:09
  • *"I want all permutation and combinations"* - but there are infinitely many, you have to put some limit to it – Joni Aug 17 '20 at 11:32
  • @Joni - It will depend on the name the user specifies. For eg :- Joni is the input.. so for that i will need the permutation and combination. Max will be 25 characters for entering name in the field. – sTg Aug 18 '20 at 06:23
  • 1
    so in addition to adding all the accents which by the way you can add as many as you want and even duplicate them e.g.J̷̨͖̳͚̣̱̙̼̖̞̜͕̊͑͋͋͒o̷̧̫̝̫̟̞̫̣̘̝̳̜̯̭͈̓n̸͙͎̦̼̪̲̑͑͊͛͗͝ͅi̶͈͚̺̥̹̞̫͍͚͖̪͇͍̱̫͂̂̈́́̇̍͂͌̽̌ you want to reorder the letters so the output looks like ỉ̷̱̘̖͍̑͆͆̾͜͜J̸̢͉͕̦̞̜̻̦͎̕͜n̸̨̟͈̼̬̣̮̝̽̈́͋͆̽̕ͅò̴͇͈͕͈͇̅́̆̒̾̅͂ ? – Joni Aug 18 '20 at 11:15

0 Answers0