Talk:革命
Add topicAppearance
Latest comment: 6 years ago by Erutuon in topic Ruby failure
Ruby failure
[edit]Ruby fails in one of the usage examples. It seems the kana for the word 力 is missing. Strangely, the ruby works if the example is shortened:
- failure:
{{ja-usex|強%大な力に立ち向かう誓いを交わすために集%結した人%々。革%命の日は近い。|きょう%だい な に たちむかう ちかい を かわす ため に しゅう%けつ した ひと%びと。かく%めい の ひ は ちかい。|People are gathering to swear an oath to revolt against their oppressors. The revolution is drawing nigh.}}
- ↓
- 強大な力に立ち向かう誓い
- kyōdai na ni tachimukau chikai
- People are gathering to swear an oath to revolt against their oppressors. The revolution is drawing nigh.
Not sure what's going on there, but thought I'd note it for future reference. — Eru·tuon 08:54, 28 November 2017 (UTC)
- Test:
- 強大な力に立ち向かう誓いを交わすために集結した人々。革命の日は近い。
- Kyōdai na randomukana ni tachimukau chikai o kawasu tame ni shūketsu shita hitobito. Kakumei no hi wa chikai.
- People are gathering to swear an oath to revolt against their oppressors. The revolution is drawing nigh.
- 強大な力に立ち向かう誓いを交わすために集結した人々。革命の日は近い。
- Wyang (talk) 09:06, 28 November 2017 (UTC)
- @Wyang: The example just needs the pronunciation of 力 to be added. If I add random kana between な and に, the error disappears. — Eru·tuon 09:51, 28 November 2017 (UTC)
- Test:
- (A)
{{ja-usex|強%大な力に立ち向かう誓いを交わすために集%結した人%々。革%命の日は近い。|きょう%だい な に たちむかう ちかい を かわす ため に しゅう%けつ した ひと%びと。かく%めい の ひ は ちかい。|blah}}
- 強大な力に立ち向かう誓いを交わすために集結した人々。革命の日は近い。
- Kyōdai na ni tachimukau chikai o kawasu tame ni shūketsu shita hitobito. Kakumei no hi wa chikai.
- blah
- 強大な力に立ち向かう誓いを交わすために集結した人々。革命の日は近い。
- (B)
{{ja-usex|強%大な力に立ち向かう誓い|きょう%だい な に たちむかう ちかい|blah}}
- 強大な力に立ち向かう誓い
- kyōdai na ni tachimukau chikai
- blah
- 強大な力に立ち向かう誓い
- @Erutuon The code on line 654 of Module:ja uses two steps to extract the ruby for kanjis. (1) compare pattern and spaced kana; (2) compare pattern and unspaced kana. Only when both steps fail will it report an error. Applied to the two examples:
- (A)
- pattern: ^(..-)%%(..-)な(..-)に(..-)ち(..-)かう(..-)いを(..-)わすために(..-)%%(..-)した(..-)%%(..-)。(..-)%%(..-)の(..-)は(..-)い。$
- spaced kana: きょう%だい な に たちむかう ちかい を かわす ため に しゅう%けつ した ひと%びと。かく%めい の ひは ちかい。
- Thus step (1) fails (for a different reason - the different spacing patterns in parameters 1 and 2, not the lack of kana for 力).
- unspaced kana: きょう%だいなにたちむかうちかいをかわすためにしゅう%けつしたひと%びと。かく%めいのひはちかい。
- And step (2) fails because of the lack of kana for 力.
- (B)
- pattern: ^(..-)%%(..-)な(..-)に(..-)ち(..-)かう(..-)い$
- spaced kana: きょう%だい な に たちむかう ちかい
- Thus step (1) passes despite the lack of kana, since parameter 1 is unspaced and the spacing in parameter 2 is counted as kana. And indeed, giving parameter 1 the same spaces makes this case fail:
- unspaced kana: きょう%だいなにたちむかうちかい
- Step (2) fails as expected since there is no kana for 力.
- It seems there are many ways of fixing this:
- Return an error if any of the captured 'rubies' contains only spaces after the check;
- Capture only
Kanjikana-containing strings in the error check on line 654 (not sure if this could lead to side effects); - Make parameter 1 of the template compulsorily spaced (this is the basis of the first step of this match-check function anyway).
- (A)
- Wyang (talk) 10:02, 28 November 2017 (UTC)
- Thanks for this analysis. It's very helpful. It is easy to determine if a capture contains only spaces; I've added code that checks for that, and the log entry can be changed to an error message. First the tracking category should be given a few days to fill up, and the existing cases be corrected, so that there aren't a bunch of module errors to be corrected all at once. Or maybe the function should be made to return
nil
, and Module:ja-usex and Module:ja-link should have fallback behavior in case ruby generation fails. - It would be possible to capture only kana (I corrected your message because the pattern operates on kana, not kanji). At the moment, the pattern-matching can even be done with the basic string functions. We would just have to replace
"..-"
with a kana pattern. It might have to contain characters besides kana, though. - Making the kana argument compulsively spaced would work, but it would require a lot of template input to be modified. — Eru·tuon 21:39, 28 November 2017 (UTC)
- Thanks for this analysis. It's very helpful. It is easy to determine if a capture contains only spaces; I've added code that checks for that, and the log entry can be changed to an error message. First the tracking category should be given a few days to fill up, and the existing cases be corrected, so that there aren't a bunch of module errors to be corrected all at once. Or maybe the function should be made to return