The person who asked the question here .
Although it was possible to some extent by answering the question, there was a problem with the processing of the prompt sound. Please point out.



Expected output example

[kaltupa, caltupa, kaxtupa, caxtupa, kappa, cappa]
[saltusi, saxtusi, sassi, saltushi, saxtushi, sasshi, saltuci, saxtuci, sacci]

Example of actual output for input example

[kaltupa, caltupa, kaxtupa, caxtupa, kappa, cappa]
[saltusi, saxtusi, sassi, sacsi, saltushi, saxtushi, sasshi, sacshi, saltuci, saxtuci, sasci, sacci]

The problem is the same

Applicable source code

Because i am stuck with the character limit, please here .

Supplemental information

JDK 10.0.2
Eclipse 4.7 Oxygen

Please point out any missing information.

  • Answer # 1

    As long as you look at the linked source, it seems that it is already implemented, but "I do this".

    The romanization pattern of the sound "tsu" is



    The next hiragana consonant

    I think 3 patterns of

    (Oh, too, oo, etc. sound + vowel are excluded this time)
    The first and second can be converted straightforwardly, but the third is temporarily converted with the temporary symbol "#".

    // The pattern where the next consonant overlaps with the sound is set to #
    kanaMap.put ("っ", new String [] {"ltu", "xtu", "#"});

    Use this to convert "Kappa" as before. Then it will be like this.

    {"kaltupa", "kaxtupa", "ka # pa"}

    Then, after the list is completed, replace each result string with a regular expression that "# replaces with the following alphabet".

    "ka # pa" .replaceAll ("# (.)", "$1 $1") // ka # pa->kappa

    (To be precise, # and the next character are replaced with two "next character")

    I think you can respond to the sound without changing the program so far.

    For reference, link the source implemented for reference before making the previous answer.

    import java.util. *;
    import java.util.stream. *;
    public class HelloWorld {
         public static void main (String [] args) {
             // Kana and Romaji conversion map. Arrange in order of the number of characters.
             // key is the source string and value has an array for the pattern
             Map<String, String []>kanaMap = new LinkedHashMap<>();
             kanaMap.put ("sho", new String [] {"syo", "sho"});
             kanaMap.put ("sha", new String [] {"sya", "sha"});
             kanaMap.put ("Sh", new String [] {"si", "shi"});
             kanaMap.put ("U", new String [] {"u"});
             kanaMap.put ("bo", new String [] {"bo"});
             kanaMap.put ("or", new String [] {"ka", "ca"});
             kanaMap.put ("ぱ", new String [] {"pa"});
             // Set # once for the pattern where the next consonant overlaps with the sound
             kanaMap.put ("tsu", new String [] {"ltu", "xtu", "#"});
             // Hiragana to be converted
             String target = "Let's do it";
             // List that holds the Romaji pattern array for each hiragana
             List<String []>romaList = new ArrayList<>();
             // Result list
             List<String>result = new ArrayList<>();
             // Match one mora from the beginning and add one pattern array
             while (target.length ()>0) {
                 for (String key: kanaMap.keySet ()) {
                     if (target.startsWith (key)) {
                         romaList.add (kanaMap.get (key));
                         // If the match, delete the first charactertarget = target.replaceFirst (key, "");
             // List intermediate output check
             // Synthesize the pattern array from the beginning and create a pattern list
             for (String [] l: romaList) {
                 // Add all elements straight at the beginning
                 if (result.size () == 0) {
                     for (String s: l) {
                         result.add (s);
                 } else {
                     // Add all previous element x next element combinations
                     // Create a new list and put it there
                     List<String>newResult = new ArrayList<>();
                     for (String s1: result) {
                         for (String s2: l) {
                             newResult.add (s1 + s2);
                     // refresh list
                     result.clear ();
                     result = newResult;
             // replace "#" in sound promptly with stream
             result = result.stream (). map (s->s.replaceAll ("# (.)", "$1 $1")). collect (Collectors.toList ());
             // result output
             System.out.println ("Result->");
             System.out.println (Arrays.toString (result.toArray ()));

  • Answer # 2

    map.put ("Happa", new String [] {"ltupa", "xtupa", "ppa"}) ;
    I feel like I can go with

    , but registering one by one ...
    +somethingshould be generalized.

  • Answer # 3

    If there is a "tsu", look at the next hiragana and layer the same consonant

    Isn't it?

  • Answer # 4

    As far as the output example is concerned, it seems that "sounding sound" is not enough with the rule of overlapping the next consonant.

    I think that it is easier to get answers if you present the questioner's range as an example.
    I think that it will save time if you get information from the questioner who is investigating the current situation rather than the respondents examining the "definition" and "range" of "sounding sound".

    I can't think of an algorithmic one, so I could create it with all the dictionary output tools or Excel and register it with copy and paste.
    map.put ("っ ◯" ;, new String [] {"◯◯" ;,"◯◯" ;,"◯◯"});

    It may be possible to implement it by referring to the "sounding sound" in the following document.
    Recommended format for Japanese romaji

  • Answer # 5

    I want to process it all together.
    There is also a feeling now, but this is a feeling that processing with one-character look-ahead was better.

    I can't write a specific code, but look ahead to the next character and process the current character. If the second character is a roar, it looks like the first character is drawn using the roar as a key.
    And the same sound. Look at the next character and superimpose the next character's consonant. It seems that there is t before ch. (Opyon) Since ch is a line, there is no problem with t.

    I want to think about what to do specifically, but is it in time?