Home>

Hello, I am indebted.

I'd like to create a program that converts hiragana to romaji this time.
It takes an input value and returns the one converted to romaji by arraylist.

Example

Shoubosha
Waingurasu


Sample output

[shoubousha, shoubousya, syoubousha, syoubousya]
[wainngurasu, waingurasu]
I want to hear

"sho" for "sho", "nn" for "n", etc.

shoubousha
wainngurasu


Can be created if the program is output (in the case of the above input example), but I do not know what code to write to output as above.
I wanted to tell you what kind of code you would like to write, so I asked a question.

Supplemental information

JDK 10.0.2
Eclipse 4.7 Oxygen

Please indicate any missing information.

  • Answer # 1

    I mean you want to cover all patterns, such as Hebon or Japanese.
    Let's prepare a map for conversion of all patterns.
    If you do not have a one-to-one map, you can just make it an array.
    ''→ ['si&apos ;,'shi'].
    All you need to do is combine all the patterns for the characters you got from the array.

    Before you ask a question, try to make something you think will be.
    Isn't it fine to have super redundant code?
    You can do almost anything with aifand a loop.

  • Answer # 2

    Shobosha is difficult, so why don't you start with a simple string such as "shika" or "mochi"?

    First, let's create a conversion table with a Map object.
    The key is an open letter and the value is an array of possible Roman patterns.
    Even if there is only one pattern of Roman characters, it will be arranged.

    Map<String, String []>= new HashMap<String, String []>
    map.put ("し", new String [] {"si", "shi"});
    map.put ("or", new String [] {"ka"});


    With this kind of feeling, let's make it because only the character string used for the problem is needed.

    Next, convert the character in question into an array character by character.
    This time it is "only", so it can be divided into "shi" and "ka". Think about how to split it yourself.
    "java String If you search with "quote by character""

    "and"correspond to {"si","shi"} and"or"to {"ka"}.
    Possible patterns are 2x1 = 2 patterns.
    Answer all the possible combinations by string concatenation.

    To do this programmatically, loop one hiragana character at a time.

    List<String>result = new ArrayList<>();// List to put the answer
    for (int i = 0;i<hiragana.length;i ++) {//<-hiragana contains only one character
      String [] romajiArray = map.get (hiragana [i]);// Get pre-registered Roman pattern array
      if (result.size () == 0) {// Because the answer list is empty at first, add the contents of the array to result as it is
    /// Omitted. Think for yourself
      } else {// Go to else because the second and subsequent characters already contain Roman characters
        // Register the combination of the existing character string and the next character pattern
        // Think about it yourself
      }
    }

    The part I wrote about thinking for myself is the core part of this task. Please try and error.

    When you look at the question text, you will have one hiragana → one romaji pattern. On the other hand, the Romaji side becomes an array, and the for only repeats. If you do it in order, you can solve it properly.

    Write your own source and if it gets stuck, clarify where it got stuck and ask again.
    If you write a code, you will be answered in code.

    ※ I think it may be a little difficult for beginners.
    * In any case, stuttering becomes difficult as soon as the sound comes in, but for now it can be ignored.

  • Answer # 3

    java Hiragana Romaji conversion
    I did a google search on.

    String conversion from hiragana to romaji
    http://syunpon-java.com/programing/java/sample/hiragana2roma.shtml

    Java library for converting Kanji/Katakana/Hiragana to Romaji
    https://askjapan.me/q/Java-36080758093

    I think you can find other information.

  • Answer # 4

    The difficulty level of this problem is different between "Shobosha" and "Waigurasu" in the example.

    There is no problem in processing "Waigurasu" in the order of words, but if "Shobosha" is processed from the beginning of words in the same way, the decision logic becomes complicated.

    Look at the first character "shi", prepare two patterns [shi] and [si], then look at the next character "yo" and connect "lyo" and "xyo",

    [shilyo, shixyo, silyo, sixyo] and the desired [sho, syo] will not be born.
    (In the first place, it is necessary to think separately whether lyo or xyo, which is a method of computer input of "yo", can be defined as romaji.)

    A possible solution in this case is to determine the character from the back.
    Hiragana is limited to 2 characters, even if you consider "Kya, Kyu, Kyo" and "Fua, Gua" etc.
    Judge from the back one character at a time, and in the case of `` Ah, i, ぅ, ee, ぉ, nya, yu, yo '', convert to romaji with 2 characters combined with the previous character, and judge from the front I think it's easier to write than doing it.

    Also, as for the conversion of hiragana and romaji, as others have advised, it is easy to create a conversion table in the Map type, but it is also possible to use witch sentences. (Only Java7 or later)

    For your reference, we have heard that it is faster than Map.
    (In the case of this example, there is almost no effect. I don't think you can feel the difference.)

    switch (str) {
        case "Kya":
            // TODO: String generation processing;
            break;
        case "kyu":
            // TODO: String generation processing;
            break;
    

  • Answer # 5

    Sorry for not being java, but python
    Convert hiragana/katakana and romaji to each other in Python
    There is. I am allowed to use it with python. It works with python but it's pretty good.
    There is a source so you can change it to your liking
    It is python source, but the code is on it, so why not change it to java?