Skip to content

Instantly share code, notes, and snippets.

@PaperclipBadger
Created June 14, 2017 18:27
Show Gist options
  • Save PaperclipBadger/6108703d8ebed03592df5f70682bf634 to your computer and use it in GitHub Desktop.
Save PaperclipBadger/6108703d8ebed03592df5f70682bf634 to your computer and use it in GitHub Desktop.
(some of the) conjugations for Japanese verbs
var conjugations = (function() {
var godan_map =
{ "う": ["わ", "い","う","え","お"]
, "く": ["か", "き","く","け","こ"]
, "ぐ": ["が", "ぎ","ぐ","げ","ご"]
, "す": ["さ", "し","す","せ","そ"]
, "つ": ["た", "ち","つ","て","と"]
, "ぬ": ["な", "に","ぬ","ね","の"]
, "ぶ": ["ば", "び","ぶ","べ","ぼ"]
, "む": ["ま", "み","む","め","も"]
, "る": ["ら", "り","る","れ","ろ"]
};
var romaji_vowels = {"a": 0, "i": 1, "u": 2, "e": 3, "o": 4};
var hiragana_vowels = {"あ": 0, "い": 1, "う": 2, "え": 3, "お": 4};
function changeVowel(u_char, vowel) {
if (vowel in romaji_vowels) {
return godan_map[u_char][romaji_vowels[vowel]];
} else if (vowel in hiragana_vowels) {
return godan_map[u_char][hiragana_vowels[vowel]];
}
}
var API = {
negative: function(dict, type, ruby) {
switch (dict) {
case "来る": return ruby ? "<ruby><rb>来</rb><rt>こ</rt></ruby>ない"
: "来(こ)ない";
case "ある": return "ない";
default:
root = dict.slice(0, -1);
switch (type) {
case "する": return dict.slice(0, -2) + "しない";
case "る": return root + "ない";
case "う":
c = changeVowel(dict.slice(-1), "あ");
return root + c + "ない";
}
}
},
past: function(dict, type, ruby) {
switch (dict) {
case "来る": return ruby ? "<ruby><rb>来</rb><rt>き</rt></ruby>た"
: "来(き)た";
case "行く": return "行った";
default:
var root = dict.slice(0, -1);
switch (type) {
case "する": return dict.slice(0, -2) + "した";
case "る": return dict.slice(0, -1) + "た";
case "う": switch (dict.slice(-1)) {
case "す": return root + "した";
case "く": return root + "いた";
case "ぐ": return root + "いだ";
case "む":
case "ぶ":
case "ぬ": return root + "んだ";
case "る":
case "う":
case "つ": return root + "った";
}
}
}
},
past_negative: function() {
return API.negative.apply(this, arguments).slice(0, -1) + "かった";
},
stem: function(dict, type, ruby) {
switch (dict) {
case "来る": return ruby ? "<ruby><rb>来</rb><rt>き</rt></ruby>"
: "来(き)";
default:
root = dict.slice(0, -1);
switch (type) {
case "する": return dict.slice(0, -2) + "し";
case "る": return root;
case "う": return root + changeVowel(dict.slice(-1), "い");
}
}
},
masu: function() {
return API.stem.apply(this, arguments) + "ます";
},
masu_negative: function() {
return API.stem.apply(this, arguments) + "ません";
},
masu_past: function() {
return API.stem.apply(this, arguments) + "ました";
},
masu_past_negative: function() {
return API.stem.apply(this, arguments) + "ませんでした";
},
te: function() {
var past = API.past.apply(this, arguments);
switch (past.slice(-1)) {
case "た": return past.slice(0, -1) + "て";
case "だ": return past.slice(0, -1) + "で";
}
},
te_negative: function() {
return API.negative.apply(this, arguments).slice(0, -1) + "くて";
},
potential: function(dict, type, ruby) {
switch (dict) {
case "来る": return ruby ? "<ruby><rb>来</rb><rt>こ</rt></ruby>られる"
: "来(こ)られる";
default:
root = dict.slice(0, -1);
switch (type) {
case "する":
var suffix = ruby ? "<ruby>"
+ "<rb>出</rb><rt>で</rt>"
+ "<rb>来</rb><rt>き</rt>"
+ "</ruby>る"
: "出来る(できる)";
return dict.slice(0, -2) + suffix;
case "る": return root + "られる";
case "う": return root + changeVowel(dict.slice(-1), "え") + "る";
}
}
}
}
return API;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment