You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
privatestaticvoidAddNode(Nodenode,stringromaji,stringkana){if(romaji.Length ==1&&!node.Children.ContainsKey(romaji))
node.Children.Add(romaji,new Node(kana));elseif(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:
privatestaticvoidAddNode(Nodenode,stringromaji,stringkana){if(romaji.Length ==1&&!node.Children.ContainsKey(romaji))
node.Children.Add(romaji,new Node(kana));elseif(romaji.Length ==1&& node.Children.ContainsKey(romaji))
node.Children[romaji].Data =kana;else{varremaining= 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)
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 in
TreeBuilder.cs
during the call line 70:When trying to add
ya
in thek
node, we get to foreach loop: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:
By fixing the recursion: (this seems more elegant to me)
The text was updated successfully, but these errors were encountered: