Hello π ΠΡΠΈΠ²Π΅Ρ π γγγ«γ‘γ―
kmoroz / wanakanashaapu Goto Github PK
View Code? Open in Web Editor NEWπ C# port of WanaKana JS π¦
π C# port of WanaKana JS π¦
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);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.