Giter VIP home page Giter VIP logo

wanakanashaapu's Introduction

Hello πŸ“ ΠŸΡ€ΠΈΠ²Π΅Ρ‚ πŸ“ こんにけは

it's me

wanakanashaapu's People

Contributors

kmoroz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

wanakanashaapu's Issues

"chuu" is translated into "けゅ" instead of "けゅう"

Hi,

When trying to transcript "chuu" into hiragana, I get the result "けゅ" instead of the expected "けゅう".

This seems to happen when adding the "ya" parts after consonants by calling this method inTreeBuilder.cs during the call line 70:

private static void AddNode(Node node, string romaji, string kana)
{
    if (romaji.Length == 1 && !node.Children.ContainsKey(romaji))
        node.Children.Add(romaji, new Node(kana));
    else if (romaji.Length == 1 && node.Children.ContainsKey(romaji))
        node.Children[romaji].Data = kana;
    else
    {
        foreach (char c in romaji)
        {
            if (!node.Children.ContainsKey(c.ToString()))
                node.Children.Add(c.ToString(), new Node(string.Empty));
            node = node.Children[c.ToString()];
            AddNode(node, romaji[1..], kana);
        }
    }
}

When trying to add ya in the k node, we get to foreach loop:

Current node is `k`, romaji = "ya", kana = "きゃ", current character is "y"
`k -> y` does not exist
    we create `k -> y`
node = `k -> y`
    ->  Add node recursively (node: `k -> y`, romaji: "a", kana: "きゃ")
        romaji.Length is 1 and `k -> y` does not have any child yet
            `k -> y -> a` is created with value "きゃ"
    <-

// next loop, node `k -> y`, romaji = "ya", kana = "きゃ", current character is "a"
`k -> y -> a` exists
node = `k -> y -> a`
    -> Add node recursively (node: `k -> y -> a`, romaji: "a", kana: "きゃ")
        romaji.Length is 1 and `k -> y -> a` does not have any child yet
            `k -> y -> a -> a` is created with value "きゃ"

It seems that there is a mix of recursion and iteration here which mixes things up.

I can see two solutions to that problem.

By fixing the iterations:

private static void AddNode(Node node, string romaji, string kana)
{
    if (romaji.Length == 1 && !node.Children.ContainsKey(romaji))
        node.Children.Add(romaji, new Node(kana));
    else if (romaji.Length == 1 && node.Children.ContainsKey(romaji))
        node.Children[romaji].Data = kana;
    else
    {
        var remaining = romaji;
        foreach (char c in romaji)
        {
            if (!node.Children.ContainsKey(c.ToString()))
                node.Children.Add(c.ToString(), new Node(string.Empty));
            node = node.Children[c.ToString()];
            AddNode(node, remaining[1..], kana);
            remaining = remaining[1..];
        }
    }
}

By fixing the recursion: (this seems more elegant to me)

private static void AddNode(Node node, string romaji, string kana)
{
    if (romaji.Length == 0)
        return;
    else if (romaji.Length == 1 && !node.Children.ContainsKey(romaji))
        node.Children.Add(romaji, new Node(kana));
    else if (romaji.Length == 1 && node.Children.ContainsKey(romaji))
        node.Children[romaji].Data = kana;
    else
    {
        var firstChar = romaji.First().ToString();
        if (!node.Children.ContainsKey(firstChar))
            node.Children.Add(firstChar.First().ToString(), new Node(string.Empty));
        node = node.Children[firstChar.ToString()];
        AddNode(node, romaji[1..], kana);
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.