Advertisement
antoine311200

Untitled

Jun 1st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global.hiragana =
  2. [
  3.   [["あ", "a"],  ["い", "i"],  ["う", "u"],  ["え", "e"],  ["お", "o"]],
  4.   [["か", "ka"],  ["き", "ki"],  ["く", "ku"],  ["け", "ke"],  ["こ", "ko"]],
  5.   [["さ", "sa"],  ["し", "shi"],  ["す", "su"],  ["せ", "se"],  ["そ", "so"]],
  6.   [["た", "ta"],  ["ち", "chi"],  ["つ", "tsu"],  ["て", "te"],  ["と", "to"]],
  7.   [["な", "na"],  ["に", "ni"],  ["ぬ", "nu"],  ["ね", "ne"],  ["の", "no"]],
  8.   [["は", "ha"],  ["ひ", "hi"],  ["ふ", "fu"],  ["へ", "he"],  ["ほ", "ho"]],
  9.   [["ま", "ma"],  ["み", "mi"],  ["む", "mu"],  ["め", "me"],  ["も", "mo"]],
  10.   [["ら", "ra"],  ["り", "ri"],  ["る", "ru"],  ["れ", "re"],  ["ろ", "ro"]],
  11.   [["わ", "wa"],  ["を", "wo"],  ["ん", "n"]],
  12.   [["や", "ya"],  ["ゆ", "yu"],  ["よ", "yo"]],
  13.  
  14.   [["が", "ga"],  ["ぎ", "gi"],  ["ぐ", "gu"],  ["げ", "ge"],  ["ご", "go"]],
  15.   [["ざ", "za"],  ["じ", "ji"],  ["ず", "zu"],  ["ぜ", "ze"],  ["ぞ", "zo"]],
  16.   [["だ", "da"],  ["ぢ", "ji"],  ["づ", "zu"],  ["で", "de"],  ["ど", "do"]],
  17.   [["ば", "ba"],  ["び", "bi"],  ["ぶ", "bu"],  ["べ", "be"],  ["ぼ", "bo"]],
  18.   [["ぱ", "pa"],  ["ぴ", "pi"],  ["ぷ", "pu"],  ["ぺ", "pe"],  ["ぽ", "po"]]
  19. ];
  20.  
  21. global.exeption = [
  22.   "嘲る", "焦る", "脂ぎ", "熱る", "弄る", "いび", "煎る", "入る", "要る", "うね", "彫る", "選る", "陥る", "阿る", "還る", "帰る", "孵る", "返る",
  23.   "反る", "限る", "翔る", "陰る", "呪る", "齧る", "噛る", "軋る", "轢る", "切る", "剪る", "斬る", "霧る", "抉る", "愚痴る", "散る", "抓る", "照る",
  24.   "覆る", "くねる", "縊る", "蹴る", "抉る", "遮る", "雑じる", "見縊る", "漲る", "毟る", "滅入る", "減る", "捩る", "よぎる", "捩る", "蘇る・甦る",
  25.   "湿気る", "茂る", "湿る", "喋る", "知る", "捩る", "滑る", "せびる", "競る", "謗る", "譏る", "誹る", "そべる", "滾る", "猛る", "駄弁る", "魂消る", "契る",
  26.   "どじる", "とちる", "迸る", "詰る", "滑る", "握る", "躙る", "滑る", "捩じる", "捻じる", "練る", "錬る", "煉る", "粘る", "罵る", "野次る", "弥次る",
  27.   "のめる", "入る", "走る", "侍る", "捻る", "びびる", "翻る", "耽る", "臥せる", "減る", "謙る", "穿る", "火照る・熱る", "迸る", "参る", "交じる", "混じる",
  28. ];
  29.  
  30.  
  31. Array.prototype.searchDepth = function(searchElement, equality, getter) {
  32.   const O = Object(this);
  33.   var index = this.indexOf(searchElement);
  34.   if(~index) {
  35.     return (getter) ? [index] : index;
  36.   }
  37.   else {
  38.     if(equality) {
  39.       if(Array.isArray(O[i])) {
  40.         index = O[i].searchDepth(searchElement, equality, getter);
  41.         if(index) {
  42.           return getter ? O[i] : [i].concat(index);
  43.         }
  44.       }
  45.     }
  46.     for(var i = 0; i < O.length; i++) {
  47.       if(Array.isArray(O[i])) {
  48.         index = O[i].searchDepth(searchElement, equality, getter);
  49.         if(index != null) {
  50.           return getter ? O[i] : [i].concat(index);
  51.         }
  52.       }
  53.     }
  54.     return null;
  55.   }
  56. };
  57.  
  58. Array.prototype.path = function(path) {
  59.   let arr = this;
  60.   for(let i = 0; i < path.length; i++) {
  61.     arr = arr[parseInt(path[i])];
  62.   }
  63.   return arr;
  64. };
  65.  
  66.  
  67. class Verb {
  68.   constructor(verb, type) {
  69.     this.verb  = verb;
  70.     this.type = type ? type : this.findType();
  71.     this.rentaikei = this.verb;
  72.     this.shuushikei = this.verb;
  73.  
  74.     const base = this.verb.substring(0, this.verb.length-1);
  75.     console.log(this.__search(this.verb.substr(-1)));
  76.     this.renyoukei = base+(this.type == "godan" ? this.__search(this.verb.substr(-1))[1][0] : "");
  77.     this.mizenkei = base+(this.type == "godan" ? this.__search(this.verb.substr(-1))[0][0] : "");
  78.     this.kateikei = base+this.__search(this.verb.substr(-1))[3][0];
  79.     this.meireikei = base+(this.type == "ichidan" ? this.__search(this.verb.substr(-1))[4][0] : this.kateikei.substr(-1));
  80.  
  81.     const last = this.verb.substring(this.verb.length-1);
  82.     console.log(last);
  83.     const __conjExeptObj = {
  84.       "す": ["した", "して"],
  85.       "く": ["いた", "いて"], "ぐ": ["いた", "いて"],
  86.       "む": ["んだ", "んで"], "ぶ": ["んだ", "んで"], "ぬ": ["んだ", "んで"],
  87.       "る": ["った", "って"], "う": ["った", "って"], "つ": ["った", "って"]
  88.     }
  89.     const past = (this.type == "ichidan") ? this.renyoukei+"た" : base+__conjExeptObj[last][0];
  90.     const teform = (this.type == "ichidan") ? this.renyoukei+"た" : base+__conjExeptObj[last][1];
  91.  
  92.     this.conj = {
  93.       "type": this.type,
  94.       "rentaikei": this.rentaikei,
  95.       "shuushikei": this.shuushikei,
  96.       "renyoukei": this.renyoukei,
  97.       "mizenkei": this.mizenkei,
  98.       "meireikei": this.meireikei,
  99.       "kateikei": this.kateikei,
  100.       "renyoukei": this.renyoukei,
  101.  
  102.       "non-past":         { pos: this.rentaikei,             neg: this.mizenkei+"ない" },
  103.       "non-past-polite":  { pos: this.renyoukei+"ます",       neg: this.renyoukei+"ません" },
  104.       "past":             { pos: past,                       neg: this.mizenkei+"なかった" },
  105.       "past-polite":      { pos: this.renyoukei+"ました",     neg: this.renyoukei+"ませんでした" },
  106.       "te-form":          { pos: teform,                      neg: this.mizenkei+"なくて" },
  107.       "imperative":       { pos: this.meireikei,              neg: this.verb+"な" },
  108.  
  109.       "potential": {
  110.         pos: (this.type == "ichidan" ? this.renyoukei+"られる" : this.kateikei+"る"),
  111.         neg: (this.type == "ichidan" ? this.renyoukei+"られない" : this.kateikei+"ない")
  112.       },
  113.       "passive": {
  114.         pos: this.mizenkei+(this.type == "ichidan" ? "られる" : "れる"),
  115.         neg: this.mizenkei+(this.type == "ichidan" ? "られない" : "れない")
  116.       },
  117.       "causative": {
  118.         pos: this.mizenkei+(this.type == "ichidan" ? "させる" : "せる"),
  119.         neg: this.mizenkei+(this.type == "ichidan" ? "させない" : "せない")
  120.       },
  121.  
  122.       "naide-form": { pos: "-", neg: this.mizenkei+"ない"+"で" }
  123.     };
  124.   }
  125.  
  126.   __search(v) {
  127.     return hiragana.searchDepth(v, false, true);
  128.   }
  129.  
  130.   findType() {
  131.     const lastChar = this.verb.substr(-1);
  132.     if(lastChar != "る") return "godan";
  133.     else if(~exeption.indexOf(this.verb)) return "godan";
  134.     else {
  135.       const lastlastChar = this.verb.substr(-2, 1);console.log(lastlastChar);
  136.       const hiraganaPath = hiragana.searchDepth(lastlastChar, false, false);
  137.       hiraganaPath.pop();
  138.       const syll = hiragana.path(hiraganaPath);
  139.  
  140.       if(~syll[1].indexOf("e") || ~syll[1].indexOf("i")) return "ichidan";
  141.       else return "godan";
  142.     }
  143.   }
  144.  
  145.   getRentaikei() {
  146.     return this.rentaikei;
  147.   }
  148.  
  149.   getRenyoukei() {
  150.     return this.renyoukei;
  151.   }
  152.  
  153.   getMizenkei() {
  154.     return this.mizenkei;
  155.   }
  156.  
  157.   getKateikei() {
  158.     return this.kateikei;
  159.   }
  160.  
  161.   getMeireikei() {
  162.     return this.meireikei;
  163.   }
  164.  
  165.   get(tense, positive) {
  166.     this.conj["causative-passive"] = {
  167.       pos: new Verb(this.conj["causative"]["pos"], "godan").getMizenkei()+"れる",
  168.       neg: new Verb(this.conj["causative"]["pos"], "godan").getMizenkei()+"れない"
  169.     };
  170.  
  171.     console.log(tense);
  172.  
  173.     let constr = tense.split(" ");
  174.     if(constr.length > 1) {
  175.       let first = constr[0]; console.log(first);
  176.       constr.shift();
  177.       return new Verb(this.conj[first]["pos"], "ichidan").get(constr.join(" "), positive);
  178.     }
  179.     return this.conj[tense][(positive) ? "pos" : "neg"];
  180.   }
  181.  
  182.   getAll() {
  183.     return this.conj;
  184.   }
  185. }
  186.  
  187. module.exports = Verb;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement