プログラムでTOEICの問題を解く

  • 93
    いいね
  • 0
    コメント
この記事は最終更新日から1年以上が経過しています。

 ご存じのようにTOEICは、定番の英語試験です。今回、TOEICの文法問題をプログラムでどこまで解けるか、チャレンジします。この記事の内容は、10月のNode-RED勉強会で発表した内容です。

TOEICの文法問題

 TOEIC専門の授業を受けたことがある方であれば、「本当に?」と思う様な解答テクニックが沢山あることをご存じと思います。その一つに、「文法問題は、問題文を全文読まなくとも、空欄の前後の2~3単語を見るだけで解答できる」というテクニックです。これはコロケーション問題と呼ばれており、単語間の並びの相性の良さの情報のみで解ける問題です。例えば、下記の様な問題です(本問題は、TOEIC Bridge問題集の問題を一部改変して作成しました)。

問題文: The ladder is leaning ---- the wall.
選択肢: (A) between  (B) after  (C) about  (D) against

 答えは、(D) againstです。TOEICを3回受験すると、1回は出てきそうな定番の文章を含んだ良問です。TOEICの語彙をよく知っている方であれば、leaning againstという単語の並びが頻出であるため、leaningのみ見ればagainstが解答と分かります。また、leaning againstの語彙を知らなくても、the wallの前にはagainstが適切な前置詞であるため、解答を導き出せます。このようなコロケーション問題は、自然な単語の並びを認識できるほどの量の英文を読んでいることを確認する手段として、とても優れています。

アルゴリズム

 プログラムは、GUI上で処理を繋ぐのみで簡単に一連の処理を開発できるIBM Bluemix上のNode-REDを用いて実装しました。アルゴリズムは、問題文の空欄前後1~3単語のみを見て、書籍のテキストでよく使われている単語の並びを解答するという処理を行います。書籍上での単語の出現頻度のデータは、Google Books N-gramを用いました。このデータを整形し、Bluemixの分析向けDBであるdashDBに入れて検索できるようにしました。

toeic_algorithm.png

 まずステップ(1)にて、空欄前後の1~3単語を切り出します。次に、ステップ(2)にて各切り出した文字列に、各選択肢を追加した文字列を作成します。最後に、各文字列が書籍上で使わてれいる頻度を検索し、スコアを積み上げグラフとして表示します。出力されるグラフは、クイズミリオネアのオーディエンスのようなイメージです。

Node-REDの実装

 まず、質問文と4つの選択肢を入力する入力フォームのUIと、結果としてスコアをグラフ表示するUIを作成しました。また、UIとは別に問題文と選択肢の文字列を投げると、スコアを返すREST APIを作成しました。UIとAPIは、UI & APIパターンを用いて接続しました。UIは下の様なノードです。

toeic_ui.png

 APIは、問題文から文字列を切り出し方毎にスコアを算出する「要素API」と、各要素APIの結果をまとめて問合せる「統合API」の2種類を作成しました。
 要素APIは選択肢4つ分、4回データベースを問合せ、4つのスコアを返します。繰り返し処理は、下の様に8の字型が目印のwhileパターンを用いています。

toeic_while.png

 統合APIは各要素APIを問合せた結果を正規化し、まとめたスコアをUIに送付します。各要素APIの問合せには、複数のノードから受け取った値を集計するSequenceパターンを用いました。

toeic_sequence.png

 Bluemix上のNode-REDは、すぐにデータベースと接続できるため、今回のようなアプリケーションを簡単に実装でき、便利です。本アルゴリズムのアイデア自体は、3年ほど前からあったのですが、データベースのセットアップが大変な点、得意の(?)Javaで実装するとウェブアプリケーション化するまでに工数がかかりすぎる点が障壁となってしました。一方、Node-REDを用いた本アプリケーションの開発時間は4時間程です。Bluemixでよく言われる「開発者がコーディングに専念できる開発環境」は、その通りだと思います。
 今回はデータの整形に他社IaaSを使いましたが、Bluemixが稼働しているIaaSであるSoftLayerを使えばよりアップロード等が効率的に行えそうです。dashDBはオブジェクトストレージからのデータロードに対応しているので、SoftLayerのオブジェクトストレージからのアップロードを試してみたいところです。

出力画面

 出力結果は、下の通りです。左は品詞問題、右は先ほど紹介したコロケーション問題です。

toeic_screen.png

 品詞問題の結果には、(A)に"I a"が少しだけ存在していますが、"give me"、"me a"、"give me a"の単語の並びが書籍中でよく見られるため、(D)が最もスコアが高くなっています。
 コロケーション問題は、空欄後1単語目の"the"だけで求めた青色のスコアは(A)(B)(C)が(D)より高くなっています。しかし、緑色の"leaning against"、紫色の"against the wall"のスコアが積算され、合計スコアで(D)が適切であると導き出しています。

評価

 本アルゴリズムをTOEIC公式問題集のVol4,5,6の120問を用いて評価したところ、下のとおり正答率65~88%と分かりました。日本人の平均点は60%ですので、本アルゴリズムは人間と同等の能力があると考えても良さそうです。

results.png

最後に

 この結果を見ると、TOEICの問題はプログラムで解けてしまうような文法問題であるため、簡単な試験と思う方がいると思います。確かにWordのスペルチェックの様な機能で人間をサポートできそうな文法問題です。この試験が簡単と思った方は、自身のチャンスと思います。TOEICは昇進や就職などでメリットがとても多い試験ですので、活用した方が良いです。ぜひ私と一緒に満点目指して頑張りましょう。
 試験運営側もコロケーション問題が多く、テクニックを知っているか否かでスコアに差がついてしまう問題は、認識していると思われます(個人的には、TOEICは英語能力を計る以外に、学習の戦略や毎日のタイムマネージメントの力を問う試験でもあると思うので、この問題はあってもいい気もします)。実際、最近の公式試験の問題はコロケーション問題が少なく、全文を読み考えて解く必要のある問題が多くなってきました。また、2016年5月からの新形式の試験では、より実践的な試験問題になると公表されています。そのため、解き甲斐のある問題が多くなり、面白くなりそうです。

応用編: 質問応答システムを実装

 本プログラムを公開したところ、質問応答システムとして使おうとした方がいらっしゃいました。文法問題ではなく、自然文の質問文を入力し、その答えを4択問題として解かせるというものです。空欄の部分をWhat等の疑問詞に変えるのみであるので、すぐに質問応答システムとして実装できました。ユーザの反応を見て素早く、アプリケーションを変更できるのはBluemixならではの開発スタイルと思います。

results2.png

 上の例では、Which is Japanese food?という疑問文の答えとして、Sushiが最も適切であると解答してします。また、Where is capital city in the United States?という問題に対しては、Washingtonが答えであると言っています。本アルゴリズムは、疑問詞の後ろ3単語までしか考慮していませんので、実はin the United Statesを見ずに解答している点はご愛敬です。

ソースコード

 ホスト名などハードコーディングしている部分もありますが、参考までにソースコードを貼り付けます。Google Books N-gramのデータは9TBもありダウンロードが大変ですので、簡単に試してみたい場合は代替手段として前の記事で紹介したMicrosoft Web N-gram ServicesのAPIを使うと便利です。

ユーザインターフェイス

[{"id":"41b48979.be4b78","type":"http in","z":"6ddf533a.9220ac","name":"","url":"/result","method":"get","swaggerDoc":"","x":371.42858505249023,"y":865.6112108230591,"wires":[["b3197426.4ce688"]]},{"id":"b3197426.4ce688","type":"function","z":"6ddf533a.9220ac","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":511.57143783569336,"y":866.7540159225464,"wires":[["68f99e9a.97066"]]},{"id":"dcd15122.232eb","type":"function","z":"6ddf533a.9220ac","name":"統合API向けURL作成","func":"msg.url = \"http://toeic.mybluemix.net/p5api\"\n          + \"?q=\" + encodeURI(msg.tmp_q)\n          + \"&c0=\" + encodeURI(msg.c[0])\n          + \"&c1=\" + encodeURI(msg.c[1])\n          + \"&c2=\" + encodeURI(msg.c[2])\n          + \"&c3=\" + encodeURI(msg.c[3]);\n\nreturn msg;","outputs":1,"noerr":0,"x":858.9999961853027,"y":866.0397081375122,"wires":[["3913a877.c6ec58"]]},{"id":"3913a877.c6ec58","type":"http request","z":"6ddf533a.9220ac","name":"統合API問合せ","method":"GET","ret":"obj","url":"","x":1048.285701751709,"y":866.0397081375122,"wires":[["887349d4.778cb8"]]},{"id":"483f7153.b7c09","type":"http response","z":"6ddf533a.9220ac","name":"","x":1380.1904373168945,"y":917.134922504425,"wires":[]},{"id":"887349d4.778cb8","type":"change","z":"6ddf533a.9220ac","name":"headers削除","rules":[{"t":"delete","p":"headers"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210.7134971618652,"y":865.1825304031372,"wires":[["fe4360ba.01bca","4f57e4cb.b0a81c"]]},{"id":"68f99e9a.97066","type":"function","z":"6ddf533a.9220ac","name":"q文末句点削除","func":"msg.tmp_q = msg.q.replace( /\\.$/, \"\")\n                 .replace( /__+/, \"----\")\n                 .replace( / ?\\-\\-+ ?/, \" ---- \")\n                 .replace(/ ?& ?/, \" and \");\n\nreturn msg;","outputs":1,"noerr":0,"x":669.4285850524902,"y":866.6111192703247,"wires":[["dcd15122.232eb"]]},{"id":"4f57e4cb.b0a81c","type":"template","z":"6ddf533a.9220ac","name":"解答出力","field":"payload","format":"html","template":"<HTML>\n<HEAD>\n<TITLE>Whatson</TITLE>\n<META name='viewport' content='initial-scale=1, width=device-width'/>\n</HEAD>    \n<BODY bgcolor='silver'>\n<TABLE bgcolor='gray' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<FONT size='+2' color='white'><A href='whatson' style='text-decoration:none; color:white;'>Whatson</A></FONT>\n</TD></TR></TABLE><BR>\n<TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>問題文 (Question)</B><BR>\n{{q}}<BR>\n</TD></TR></TABLE><BR>\n<TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>選択肢 (Choices)</B><BR>\n(A) {{c.0}}<BR>\n(B) {{c.1}}<BR>\n(C) {{c.2}}<BR>\n(D) {{c.3}}<BR>\n</TD></TR></TABLE><BR>\n<!-- <TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>ユーザが入力した解答 (Your answer)</B><BR>\n{{a}}<BR>\n</TD></TR></TABLE><BR> -->\n<TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>人工知能の解答 (Computational results)<B><BR>\n<IMG src='http://chart.apis.google.com/chart?chs=280x140&chd=t:{{payload.s.0.0}},{{payload.s.1.0}},{{payload.s.2.0}},{{payload.s.3.0}}|{{payload.s.0.1}},{{payload.s.1.1}},{{payload.s.2.1}},{{payload.s.3.1}}|{{payload.s.0.2}},{{payload.s.1.2}},{{payload.s.2.2}},{{payload.s.3.2}}|{{payload.s.0.3}},{{payload.s.1.3}},{{payload.s.2.3}},{{payload.s.3.3}}|{{payload.s.0.4}},{{payload.s.1.4}},{{payload.s.2.4}},{{payload.s.3.4}}|{{payload.s.0.5}},{{payload.s.1.5}},{{payload.s.2.5}},{{payload.s.3.5}}|{{payload.s.0.6}},{{payload.s.1.6}},{{payload.s.2.6}},{{payload.s.3.6}}&cht=bhs&chco=800000,2b0080,80006a,008015,550080,805500,006a80&chxt=x,y&chxl=0:|0|1|2|3|1:|D|C|B|A&chds=0,3'>\n</TD></TR></TABLE><BR>\n\n<!-- <TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>人工知能の解答2 (Computational results)<B><BR>\n<IMG src='http://chart.apis.google.com/chart?chs=280x140&chd=t:{{payload.s.0.0}},{{payload.s.1.0}},{{payload.s.2.0}},{{payload.s.3.0}}|{{payload.s.0.1}},{{payload.s.1.1}},{{payload.s.2.1}},{{payload.s.3.1}}|{{payload.s.0.3}},{{payload.s.1.3}},{{payload.s.2.3}},{{payload.s.3.3}}&cht=bhs&chco=800000,2b0080,008015&chxt=x,y&chxl=0:|0|1|2|3|1:|D|C|B|A&chds=0,3'>\n</TD></TR></TABLE><BR>\n\n<TABLE width='300' bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>ログ</B><BR>\n2gram<BR>\n{{payload.s.0.0}}, {{payload.s.1.0}}, {{payload.s.2.0}}, {{payload.s.3.0}}<BR>\n{{payload.s.0.1}}, {{payload.s.1.1}}, {{payload.s.2.1}}, {{payload.s.3.1}}<BR>\n3gram<BR>\n{{payload.s.0.2}}, {{payload.s.1.2}}, {{payload.s.2.2}}, {{payload.s.3.2}}<BR>\n{{payload.s.0.3}}, {{payload.s.1.3}}, {{payload.s.2.3}}, {{payload.s.3.3}}<BR>\n{{payload.s.0.4}}, {{payload.s.1.4}}, {{payload.s.2.4}}, {{payload.s.3.4}}<BR>\n4gram<BR>\n{{payload.s.0.5}}, {{payload.s.1.5}}, {{payload.s.2.5}}, {{payload.s.3.5}}<BR>\n{{payload.s.0.6}}, {{payload.s.1.6}}, {{payload.s.2.6}}, {{payload.s.3.6}}<BR>\n</TD></TR></TABLE><BR> -->\n<A href='whatson'>トップページへ戻る</A>\n</BODY>\n</HTML>","x":1247.4285888671875,"y":916.6111450195312,"wires":[["483f7153.b7c09"]]},{"id":"fe4360ba.01bca","type":"debug","z":"6ddf533a.9220ac","name":"スコア出力","active":true,"console":"false","complete":"payload","x":1370.0953102111816,"y":864.9444751739502,"wires":[]},{"id":"a89dcd5a.57623","type":"comment","z":"6ddf533a.9220ac","name":"出力UI","info":"","x":358.6577453613281,"y":827,"wires":[]},{"id":"760079b7.89ff88","type":"http in","z":"6ddf533a.9220ac","name":"","url":"/sample1","method":"get","swaggerDoc":"","x":411.33331298828125,"y":650.6666870117188,"wires":[["4776cbc6.b88934"]]},{"id":"4776cbc6.b88934","type":"function","z":"6ddf533a.9220ac","name":"チョコレート問題","func":"msg.q = \"Give ---- a chocolate.\";\nmsg.c = [\"I\", \"my\", \"mine\", \"me\"];\nmsg.a = \"me\";\n\nreturn msg;","outputs":1,"noerr":0,"x":599.3333129882812,"y":650.3333435058594,"wires":[["48687508.b7978c"]]},{"id":"765d25d4.89a2dc","type":"function","z":"6ddf533a.9220ac","name":"はしご問題","func":"msg.q = \"The ladder is leaning ---- the wall.\";\nmsg.c = [\"between\", \"after\", \"about\", \"against\"];\nmsg.a = \"against\";\n\nreturn msg;","outputs":1,"noerr":0,"x":612,"y":686.0000305175781,"wires":[["48687508.b7978c"]]},{"id":"5da805f4.a257fc","type":"http response","z":"6ddf533a.9220ac","name":"","x":985,"y":689,"wires":[]},{"id":"4074cda2.bf8b34","type":"http in","z":"6ddf533a.9220ac","name":"","url":"/whatson","method":"get","swaggerDoc":"","x":410.3332862854004,"y":612.6666259765625,"wires":[["ed02e17d.12fd2"]]},{"id":"85319225.7ace7","type":"comment","z":"6ddf533a.9220ac","name":"入力UI","info":"","x":390.23727798461914,"y":566.5713806152344,"wires":[]},{"id":"ed02e17d.12fd2","type":"function","z":"6ddf533a.9220ac","name":"問題なし","func":"msg.q = \"\";\nmsg.c = [\"\", \"\", \"\", \"\"];\nmsg.a = \"\";\n\nreturn msg;","outputs":1,"noerr":0,"x":619.3333129882812,"y":612.333251953125,"wires":[["48687508.b7978c"]]},{"id":"93296fce.6cd69","type":"http in","z":"6ddf533a.9220ac","name":"","url":"/sample2","method":"get","swaggerDoc":"","x":411,"y":687.0000305175781,"wires":[["765d25d4.89a2dc"]]},{"id":"3cceb596.c3314a","type":"http in","z":"6ddf533a.9220ac","name":"","url":"/about","method":"get","swaggerDoc":"","x":402,"y":724,"wires":[["4d038814.b2fc78"]]},{"id":"4d038814.b2fc78","type":"template","z":"6ddf533a.9220ac","name":"説明","field":"payload","format":"html","template":"<HTML>\n<HEAD>\n<TITLE>Whatson</TITLE>\n<META name='viewport' content='initial-scale=1, width=device-width'/>\n</HEAD>    \n<BODY bgcolor='silver'>\n<TABLE bgcolor='gray' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<FONT size='+2' color='white'><A href='whatson' style='text-decoration:none; color:white;'>Whatson</A></FONT>\n</TD></TR></TABLE><BR>\n<TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>Whatsonとは</B><BR>\n TOEIC文法問題Part5を解く人工知能です。\n膨大な書籍の英文を瞬時に調べ、統計的に適切な解答を導き出します。<BR>\n Whatsonは品詞問題、コロケーション問題が得意です。\n時制問題など、その他の問題はまだまだ勉強中です。<BR>\n※Whatson(ワッツオン)はWatsonサービスではありません。\n<BR>\n</TD></TR></TABLE><BR>\n<TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>使い方</B><BR>\n(1) 問題文と各選択肢を入力し、送信をクリックします。\n選択肢が入る空欄には、----を入力してください。<BR>\n(2) 計算結果としてスコアの積み上げグラフを出力します。\n最も積算スコアが高い選択肢が、Whatsonが導き出した解答です。\n</TD></TR></TABLE><BR>\n<TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>解答の精度</B><BR>\n 正答率は60~80%です。\n特に<A href='http://square.toeic.or.jp/kyouzai/store/syoseki/lr/tools_07.html'>TOEIC公式問題集Vol4 TEST1</A>の問題は、高い正答率を出しています。<BR>\nもしWhatsonが賢い解答をしていたら、私(開発者)も英語の勉強をしたいので教えてください。\n</TD></TR></TABLE><BR>\n<TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>使用データ</B><BR>\n Whatsonは、800万冊以上の書籍の英文から作られたコーパス<A href='http://storage.googleapis.com/books/ngrams/books/datasetsv2.html'>Google Books N-gram</A>を使用しています。\n</TD></TR></TABLE><BR>\n<A href='whatson'>トップページへ戻る</A>\n</BODY>\n</HTML>","x":821.0000038146973,"y":724.000020980835,"wires":[["5da805f4.a257fc"]]},{"id":"48687508.b7978c","type":"template","z":"6ddf533a.9220ac","name":"入力フォーム","field":"payload","format":"html","template":"<HTML>\n<HEAD>\n<TITLE>Whatson</TITLE>\n<META name='viewport' content='initial-scale=1.5, width=device-width'/>\n</HEAD>    \n<BODY bgcolor='silver'>\n<TABLE bgcolor='gray' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<FONT size='+2' color='white'><A href='whatson' style='text-decoration:none; color:white;'>Whatson</A></FONT>\n</TD></TR></TABLE><BR>\n<FORM method='GET' action='result'>\n<FONT size='-1'>TOEIC文法問題Part5の問題文と<BR>各選択肢を入力してください。<BR>人工知能Whatsonが解答します。<BR><BR></FONT>\n<TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>問題文 (Question)</B><BR><TEXTAREA name='q' rows='8'>{{q}}</TEXTAREA><BR>\n※ 空欄は----を入力<BR>\n</TD></TR></TABLE><BR>\n<TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>選択肢 (Choices)</B><BR>\n(A) <INPUT type='text' name='c0' value='{{c.0}}'><BR>\n(B) <INPUT type='text' name='c1' value='{{c.1}}'><BR>\n(C) <INPUT type='text' name='c2' value='{{c.2}}'><BR>\n(D) <INPUT type='text' name='c3' value='{{c.3}}'><BR>\n</TD></TR></TABLE><BR>\n<!-- <TABLE bgcolor='white' style='border:2px solid gray;border-radius: 10px;' cellspacing='0' cellpadding='10'>\n<TR><TD>\n<B>解答 (Your answer)</B><BR>\n<INPUT type='text' name='a' value='{{a}}'><BR>\n※ 任意<BR>\n</TD></TR></TABLE><BR> -->\n<INPUT type='submit'>\n</FORM>\n<A href='about'>Whatsonについて</A><BR>\n<A href='sample1'>サンプル問題1</A><BR>\n<A href='sample2'>サンプル問題2</A><BR>\n<BR>\n<A href='whatson'>トップページへ戻る</A><BR>\n</BODY>\n</HTML>","x":806,"y":650,"wires":[["5da805f4.a257fc"]]}]

統合API

[{"id":"eacbaccd.15345","type":"http in","z":"2afdf263.d5020e","name":"","url":"/p5api","method":"get","swaggerDoc":"","x":468.6666717529297,"y":557.1667937387974,"wires":[["ba3db1b4.45c25"]]},{"id":"6a758689.958a78","type":"function","z":"2afdf263.d5020e","name":"2gram1向けURL作成","func":"msg.url = \"http://toeic.mybluemix.net/2gram1\"\n          + \"?q=\" + encodeURI(msg.q)\n          + \"&c0=\" + encodeURI(msg.c[0])\n          + \"&c1=\" + encodeURI(msg.c[1])\n          + \"&c2=\" + encodeURI(msg.c[2])\n          + \"&c3=\" + encodeURI(msg.c[3]);\n\nreturn msg;","outputs":1,"noerr":0,"x":658.6666717529297,"y":626.1667937387974,"wires":[["fcde9fab.03216"]]},{"id":"fcde9fab.03216","type":"http request","z":"2afdf263.d5020e","name":"","method":"GET","ret":"obj","url":"","x":834.6666717529297,"y":624.1667632212193,"wires":[["7c4d7ca5.83b284"]]},{"id":"6de76df0.921894","type":"function","z":"2afdf263.d5020e","name":"スコア0-1正規化","func":"var start = 0;\nvar end = 1;\n\nvar total = [0, 0, 0, 0];\n\nfor (var i = 0; i < 4; i++)\n{\n    for (var j = start; j < end+1; j++)\n    {\n        total[i] += msg.s[i][j];\n    }\n}\n\nvar max = Math.max.apply(null, total);\nif (max == 0)\n{\n    max = 1;\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    for (var j = start; j < end+1; j++)\n    {\n        msg.s[i][j] = 1.0 * msg.s[i][j] / max;\n    }\n}\n\nreturn msg;","outputs":"1","noerr":0,"x":642.5624542236328,"y":752.9446257700474,"wires":[["ed1a10d4.12e5f"]]},{"id":"8475a3ea.7b8a6","type":"function","z":"2afdf263.d5020e","name":"2gram2向けURL作成","func":"msg.url = \"http://toeic.mybluemix.net/2gram2\"\n          + \"?q=\" + encodeURI(msg.q)\n          + \"&c0=\" + encodeURI(msg.c[0])\n          + \"&c1=\" + encodeURI(msg.c[1])\n          + \"&c2=\" + encodeURI(msg.c[2])\n          + \"&c3=\" + encodeURI(msg.c[3]);\n\nreturn msg;","outputs":1,"noerr":0,"x":654.5624847412109,"y":685.5001372446568,"wires":[["68218fe.f97de7"]]},{"id":"68218fe.f97de7","type":"http request","z":"2afdf263.d5020e","name":"","method":"GET","ret":"obj","url":"","x":830.5624847412109,"y":683.5001067270787,"wires":[["cae48d2c.351b7"]]},{"id":"7c4d7ca5.83b284","type":"function","z":"2afdf263.d5020e","name":"スコア0格納","func":"var index = 0;\n\nmsg.s[0][index] = msg.payload.s[0];\nmsg.s[1][index] = msg.payload.s[1];\nmsg.s[2][index] = msg.payload.s[2];\nmsg.s[3][index] = msg.payload.s[3];\n\nreturn msg;","outputs":1,"noerr":0,"x":985.5625457763672,"y":622.722366248563,"wires":[["8475a3ea.7b8a6","78e0fdc6.871f04"]]},{"id":"78e0fdc6.871f04","type":"debug","z":"2afdf263.d5020e","name":"スコア出力","active":true,"console":"false","complete":"payload","x":1162.5625457763672,"y":622.7223967661412,"wires":[]},{"id":"5272bc85.ad8d44","type":"debug","z":"2afdf263.d5020e","name":"スコア出力","active":true,"console":"false","complete":"payload","x":1161.5625457763672,"y":682.722366248563,"wires":[]},{"id":"ba3db1b4.45c25","type":"function","z":"2afdf263.d5020e","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":626.6666717529297,"y":558.1667937387974,"wires":[["b9340b4a.46cbf8"]]},{"id":"cae48d2c.351b7","type":"function","z":"2afdf263.d5020e","name":"スコア1格納","func":"var index = 1;\n\nmsg.s[0][index] = msg.payload.s[0];\nmsg.s[1][index] = msg.payload.s[1];\nmsg.s[2][index] = msg.payload.s[2];\nmsg.s[3][index] = msg.payload.s[3];\n\nreturn msg;","outputs":1,"noerr":0,"x":984.6666717529297,"y":683.1666716684849,"wires":[["5272bc85.ad8d44","6de76df0.921894"]]},{"id":"b9340b4a.46cbf8","type":"function","z":"2afdf263.d5020e","name":"スコア初期化","func":"msg.s = new Array(4);\nmsg.s[0] = {};\nmsg.s[1] = {};\nmsg.s[2] = {};\nmsg.s[3] = {};\n\nreturn msg;","outputs":1,"noerr":0,"x":780.6666717529297,"y":558.1667937387974,"wires":[["6a758689.958a78"]]},{"id":"ed1a10d4.12e5f","type":"function","z":"2afdf263.d5020e","name":"3gram1向けURL作成","func":"msg.url = \"http://toeic.mybluemix.net/3gram1\"\n          + \"?q=\" + encodeURI(msg.q)\n          + \"&c0=\" + encodeURI(msg.c[0])\n          + \"&c1=\" + encodeURI(msg.c[1])\n          + \"&c2=\" + encodeURI(msg.c[2])\n          + \"&c3=\" + encodeURI(msg.c[3]);\n\nreturn msg;","outputs":1,"noerr":0,"x":660.7708892822266,"y":816.1667937387974,"wires":[["23b75aa9.dc48a6"]]},{"id":"23b75aa9.dc48a6","type":"http request","z":"2afdf263.d5020e","name":"","method":"GET","ret":"obj","url":"","x":836.7708892822266,"y":814.1667632212193,"wires":[["18d3fa57.e72c06"]]},{"id":"a3dd48cf.5c22b8","type":"function","z":"2afdf263.d5020e","name":"スコア2-4正規化","func":"var start = 2;\nvar end = 4;\n\nvar total = [0, 0, 0, 0];\n\nfor (var i = 0; i < 4; i++)\n{\n    for (var j = start; j < end+1; j++)\n    {\n        total[i] += msg.s[i][j];\n    }\n}\n\nvar max = Math.max.apply(null, total);\nif (max == 0)\n{\n    max = 1;\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    for (var j = start; j < end+1; j++)\n    {\n        msg.s[i][j] = 1.0 * msg.s[i][j] / max;\n    }\n}\n\nreturn msg;","outputs":"1","noerr":0,"x":642.6666717529297,"y":996.9446257700474,"wires":[["b9f22a3f.460dd8"]]},{"id":"e0c9800b.1f368","type":"function","z":"2afdf263.d5020e","name":"3gram2向けURL作成","func":"msg.url = \"http://toeic.mybluemix.net/3gram2\"\n          + \"?q=\" + encodeURI(msg.q)\n          + \"&c0=\" + encodeURI(msg.c[0])\n          + \"&c1=\" + encodeURI(msg.c[1])\n          + \"&c2=\" + encodeURI(msg.c[2])\n          + \"&c3=\" + encodeURI(msg.c[3]);\n\nreturn msg;","outputs":1,"noerr":0,"x":656.6667022705078,"y":875.5001372446568,"wires":[["b972dd95.468d2"]]},{"id":"b972dd95.468d2","type":"http request","z":"2afdf263.d5020e","name":"","method":"GET","ret":"obj","url":"","x":832.6667022705078,"y":873.5001067270787,"wires":[["b21bef81.4de41"]]},{"id":"18d3fa57.e72c06","type":"function","z":"2afdf263.d5020e","name":"スコア2格納","func":"var index = 2;\n\nmsg.s[0][index] = msg.payload.s[0];\nmsg.s[1][index] = msg.payload.s[1];\nmsg.s[2][index] = msg.payload.s[2];\nmsg.s[3][index] = msg.payload.s[3];\n\nreturn msg;","outputs":1,"noerr":0,"x":987.6667633056641,"y":812.722366248563,"wires":[["e0c9800b.1f368","8faf1aad.7050e8"]]},{"id":"8faf1aad.7050e8","type":"debug","z":"2afdf263.d5020e","name":"スコア出力","active":true,"console":"false","complete":"payload","x":1164.666763305664,"y":812.7223967661412,"wires":[]},{"id":"9e06ce2d.61f93","type":"debug","z":"2afdf263.d5020e","name":"スコア出力","active":true,"console":"false","complete":"payload","x":1163.666763305664,"y":872.722366248563,"wires":[]},{"id":"b21bef81.4de41","type":"function","z":"2afdf263.d5020e","name":"スコア3格納","func":"var index = 3;\n\nmsg.s[0][index] = msg.payload.s[0];\nmsg.s[1][index] = msg.payload.s[1];\nmsg.s[2][index] = msg.payload.s[2];\nmsg.s[3][index] = msg.payload.s[3];\n\nreturn msg;","outputs":1,"noerr":0,"x":985.7708892822266,"y":875.1666716684849,"wires":[["9e06ce2d.61f93","5a4b6802.a5b498"]]},{"id":"15134036.eaecc","type":"debug","z":"2afdf263.d5020e","name":"スコア出力","active":true,"console":"false","complete":"payload","x":1019.6666717529297,"y":1231.1667937387974,"wires":[]},{"id":"712a3d41.8ed5c4","type":"http response","z":"2afdf263.d5020e","name":"","x":1003.6666717529297,"y":1185.1667937387974,"wires":[]},{"id":"21d8d3e2.de272c","type":"function","z":"2afdf263.d5020e","name":"スコア0-6格納","func":"var start = 0;\nvar end = 6;\n\nfor (var i = 0; i < 4; i++)\n{\n    for (var j = start; j < end+1; j++)\n    {\n        msg.s[i][j] = 1.0 * parseInt(msg.s[i][j]*100) / 100;\n    }\n}\n\nmsg.payload = new Object();\nmsg.payload.s = msg.s;\n\nreturn msg;","outputs":1,"noerr":0,"x":823.6666717529297,"y":1182.1665495981724,"wires":[["712a3d41.8ed5c4","15134036.eaecc"]]},{"id":"b9f22a3f.460dd8","type":"function","z":"2afdf263.d5020e","name":"4gram1向けURL作成","func":"msg.url = \"http://toeic.mybluemix.net/4gram1\"\n          + \"?q=\" + encodeURI(msg.q)\n          + \"&c0=\" + encodeURI(msg.c[0])\n          + \"&c1=\" + encodeURI(msg.c[1])\n          + \"&c2=\" + encodeURI(msg.c[2])\n          + \"&c3=\" + encodeURI(msg.c[3]);\n\nreturn msg;","outputs":1,"noerr":0,"x":653.6666717529297,"y":1058.1667937387974,"wires":[["1b4b3b5d.e4b4c5"]]},{"id":"1b4b3b5d.e4b4c5","type":"http request","z":"2afdf263.d5020e","name":"","method":"GET","ret":"obj","url":"","x":829.6666717529297,"y":1056.1667632212193,"wires":[["8ac0831b.753f8"]]},{"id":"6f62c0fa.909d4","type":"function","z":"2afdf263.d5020e","name":"スコア5-6正規化","func":"var start = 5;\nvar end = 6;\n\nvar total = [0, 0, 0, 0];\n\nfor (var i = 0; i < 4; i++)\n{\n    for (var j = start; j < end+1; j++)\n    {\n        total[i] += msg.s[i][j];\n    }\n}\n\nvar max = Math.max.apply(null, total);\nif (max == 0)\n{\n    max = 1;\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    for (var j = start; j < end+1; j++)\n    {\n        msg.s[i][j] = 1.0 * msg.s[i][j] / max;\n    }\n}\n\nreturn msg;","outputs":"1","noerr":0,"x":637.5624542236328,"y":1184.9446257700474,"wires":[["21d8d3e2.de272c"]]},{"id":"af9ee806.506118","type":"function","z":"2afdf263.d5020e","name":"4gram2向けURL作成","func":"msg.url = \"http://toeic.mybluemix.net/4gram2\"\n          + \"?q=\" + encodeURI(msg.q)\n          + \"&c0=\" + encodeURI(msg.c[0])\n          + \"&c1=\" + encodeURI(msg.c[1])\n          + \"&c2=\" + encodeURI(msg.c[2])\n          + \"&c3=\" + encodeURI(msg.c[3]);\n\nreturn msg;","outputs":1,"noerr":0,"x":649.5624847412109,"y":1117.5001372446568,"wires":[["c888f751.377708"]]},{"id":"c888f751.377708","type":"http request","z":"2afdf263.d5020e","name":"","method":"GET","ret":"obj","url":"","x":825.5624847412109,"y":1115.5001067270787,"wires":[["64e5fb8c.9b1a04"]]},{"id":"8ac0831b.753f8","type":"function","z":"2afdf263.d5020e","name":"スコア5格納","func":"var index = 5;\n\nmsg.s[0][index] = msg.payload.s[0];\nmsg.s[1][index] = msg.payload.s[1];\nmsg.s[2][index] = msg.payload.s[2];\nmsg.s[3][index] = msg.payload.s[3];\n\nreturn msg;","outputs":1,"noerr":0,"x":980.5625457763672,"y":1054.722366248563,"wires":[["af9ee806.506118","55ab8196.aa548"]]},{"id":"55ab8196.aa548","type":"debug","z":"2afdf263.d5020e","name":"スコア出力","active":true,"console":"false","complete":"payload","x":1157.5625457763672,"y":1054.7223967661412,"wires":[]},{"id":"b7a6d07b.48593","type":"debug","z":"2afdf263.d5020e","name":"スコア出力","active":true,"console":"false","complete":"payload","x":1156.5625457763672,"y":1114.722366248563,"wires":[]},{"id":"64e5fb8c.9b1a04","type":"function","z":"2afdf263.d5020e","name":"スコア6格納","func":"var index = 6;\n\nmsg.s[0][index] = msg.payload.s[0];\nmsg.s[1][index] = msg.payload.s[1];\nmsg.s[2][index] = msg.payload.s[2];\nmsg.s[3][index] = msg.payload.s[3];\n\nreturn msg;","outputs":1,"noerr":0,"x":978.6666717529297,"y":1117.166671668485,"wires":[["b7a6d07b.48593","6f62c0fa.909d4"]]},{"id":"92bd1094.6d42f","type":"comment","z":"2afdf263.d5020e","name":"統合API","info":"","x":462.3333511352539,"y":506.00004959106445,"wires":[]},{"id":"5a4b6802.a5b498","type":"function","z":"2afdf263.d5020e","name":"3gram3向けURL作成","func":"msg.url = \"http://toeic.mybluemix.net/3gram3\"\n          + \"?q=\" + encodeURI(msg.q)\n          + \"&c0=\" + encodeURI(msg.c[0])\n          + \"&c1=\" + encodeURI(msg.c[1])\n          + \"&c2=\" + encodeURI(msg.c[2])\n          + \"&c3=\" + encodeURI(msg.c[3]);\n\nreturn msg;","outputs":1,"noerr":0,"x":656.6666717529297,"y":936.1667937387974,"wires":[["7c0333e3.83fccc"]]},{"id":"7c0333e3.83fccc","type":"http request","z":"2afdf263.d5020e","name":"","method":"GET","ret":"obj","url":"","x":832.6666717529297,"y":934.1667632212193,"wires":[["8e4ce0e4.71b32"]]},{"id":"342132c7.cbdece","type":"debug","z":"2afdf263.d5020e","name":"スコア出力","active":true,"console":"false","complete":"payload","x":1163.666732788086,"y":933.3890227427037,"wires":[]},{"id":"8e4ce0e4.71b32","type":"function","z":"2afdf263.d5020e","name":"スコア4格納","func":"var index = 4;\n\nmsg.s[0][index] = msg.payload.s[0];\nmsg.s[1][index] = msg.payload.s[1];\nmsg.s[2][index] = msg.payload.s[2];\nmsg.s[3][index] = msg.payload.s[3];\n\nreturn msg;","outputs":1,"noerr":0,"x":985.7708587646484,"y":935.8333281626255,"wires":[["342132c7.cbdece","a3dd48cf.5c22b8"]]}]

要素API

[{"id":"265976b9.d9a68a","type":"function","z":"2afdf263.d5020e","name":"文字列を配列化","func":"msg.payload = msg.payload.split(/ |, /);\n\nreturn msg;","outputs":1,"noerr":0,"x":852.6666793823242,"y":1871.6666084875615,"wires":[["a95d705c.56a29"]]},{"id":"a95d705c.56a29","type":"function","z":"2afdf263.d5020e","name":"空欄前1単語抽出","func":"var input = msg.payload;\nvar i = 0;\n\nwhile (i<input.length && !input[i].match(/^-+$/))\n{\n    i++;\n}\n\nvar tmp = \"\";\nvar len = 1;\nif (0 <= i-len)\n{\n    for (var j = i-len; j < input.length && j < i; j++)\n    {\n        tmp += input[j];\n        if (j != input.length-1 && j != i-1)\n        {\n            tmp += \" \";\n        }\n    }\n}\nmsg.payload = tmp;\n\nreturn msg;","outputs":1,"noerr":0,"x":1044.6666793823242,"y":1869.6666084875615,"wires":[["9361e4e4.6c9e18"]]},{"id":"8448bb5e.7bb748","type":"dashDB in","z":"2afdf263.d5020e","service":"dashDB-f6","query":"SELECT * FROM NGRM WHERE WORD = ?;","params":"msg.payload","name":"","x":1340.6666793823242,"y":1870.6666084875615,"wires":[["344250ef.cbbdb"]]},{"id":"617402d4.9e8bfc","type":"http in","z":"2afdf263.d5020e","name":"","url":"/2gram1","method":"get","swaggerDoc":"","x":373.6666793823242,"y":1790.6666390051396,"wires":[["21151673.deeaea","9496009c.6b6a"]]},{"id":"c58f874a.3a7078","type":"http response","z":"2afdf263.d5020e","name":"","x":895.6666641235352,"y":1934.6666084875615,"wires":[]},{"id":"2db8116e.d247ee","type":"function","z":"2afdf263.d5020e","name":"payload = q","func":"msg.payload = msg.q;\n\nreturn msg;","outputs":1,"noerr":0,"x":687.6666793823242,"y":1874.6666084875615,"wires":[["265976b9.d9a68a"]]},{"id":"344250ef.cbbdb","type":"function","z":"2afdf263.d5020e","name":"スコア格納","func":"if (msg.payload.FREQ != null)\n    msg.s[msg.i] = msg.payload.FREQ;\nelse\n    msg.s[msg.i] = 0;\n\nreturn msg;","outputs":1,"noerr":0,"x":1474.6666793823242,"y":1870.6666084875615,"wires":[["56f674b0.a9098c"]]},{"id":"bc12c030.43ed4","type":"function","z":"2afdf263.d5020e","name":"payloadへスコア格納","func":"msg.payload = new Object();\nmsg.payload.s = msg.s;\n\nreturn msg;","outputs":1,"noerr":0,"x":717.6666793823242,"y":1934.6666084875615,"wires":[["c58f874a.3a7078","9035588.f6fcaa8"]]},{"id":"d01a951b.2fe568","type":"http in","z":"2afdf263.d5020e","name":"","url":"/2gram2","method":"get","swaggerDoc":"","x":367.56250762939453,"y":2107.5554787268193,"wires":[["6a557ea0.95aa8","705f0eac.8fa0f"]]},{"id":"21151673.deeaea","type":"function","z":"2afdf263.d5020e","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":532.6666793823242,"y":1788.6666084875615,"wires":[["d7e2cfd8.281d3"]]},{"id":"56f674b0.a9098c","type":"function","z":"2afdf263.d5020e","name":"i++","func":"msg.i++;\n\nreturn msg;","outputs":1,"noerr":0,"x":1041.6666793823242,"y":1762.6666084875615,"wires":[["d7386937.28c798"]]},{"id":"d7386937.28c798","type":"switch","z":"2afdf263.d5020e","name":"i<4","property":"i","rules":[{"t":"lt","v":"4"},{"t":"else"}],"checkall":"true","outputs":2,"x":539.6666793823242,"y":1881.6666084875615,"wires":[["2db8116e.d247ee"],["bc12c030.43ed4"]]},{"id":"e1fc5962.1e03a8","type":"template","z":"2afdf263.d5020e","name":"i=0","field":"i","format":"handlebars","template":"0","x":385.6666793823242,"y":1882.6666084875615,"wires":[["d7386937.28c798"]]},{"id":"d7e2cfd8.281d3","type":"function","z":"2afdf263.d5020e","name":"スコア初期化","func":"msg.s = new Array(4);\n\nreturn msg;","outputs":1,"noerr":0,"x":695.6666793823242,"y":1788.6666084875615,"wires":[["e1fc5962.1e03a8"]]},{"id":"9496009c.6b6a","type":"debug","z":"2afdf263.d5020e","name":"アクセス確認","active":false,"console":"false","complete":"payload","x":543.6666793823242,"y":1740.6666084875615,"wires":[]},{"id":"9035588.f6fcaa8","type":"debug","z":"2afdf263.d5020e","name":"スコア出力","active":true,"console":"false","complete":"payload","x":908.6666793823242,"y":1973.6666084875615,"wires":[]},{"id":"771122ae.88eedc","type":"function","z":"2afdf263.d5020e","name":"空欄後1単語抽出","func":"var input = msg.payload;\nvar i = 0;\n\nwhile (i<input.length && !input[i].match(/^-+$/))\n{\n    i++;\n}\n\nvar tmp = \"\";\nvar len = 1;\nif (i+len < input.length)\n{\n    for (var j = i+1; j < input.length && j-(i+1) < len; j++)\n    {\n        tmp += input[j];\n        if (j != input.length-1 && j-(i+1) != len-1)\n        {\n            tmp += \" \";\n        }\n    }\n}\nmsg.payload = tmp;\n\nreturn msg;","outputs":1,"noerr":0,"x":1035.6666793823242,"y":2185.6665627111943,"wires":[["7c300f32.83cff"]]},{"id":"c5bff075.3a401","type":"function","z":"2afdf263.d5020e","name":"文字列を配列化","func":"msg.payload = msg.payload.split(/ |, /);\n\nreturn msg;","outputs":1,"noerr":0,"x":847.6666793823242,"y":2188.6665627111943,"wires":[["771122ae.88eedc"]]},{"id":"4af00f1c.b50ff","type":"dashDB in","z":"2afdf263.d5020e","service":"dashDB-f6","query":"SELECT * FROM NGRM WHERE WORD = ?;","params":"msg.payload","name":"","x":1335.6666793823242,"y":2185.6665627111943,"wires":[["d62afb90.29d508"]]},{"id":"7e52b129.81ad5","type":"http response","z":"2afdf263.d5020e","name":"","x":890.6666641235352,"y":2251.6665627111943,"wires":[]},{"id":"b873e679.478c18","type":"function","z":"2afdf263.d5020e","name":"payload = q","func":"msg.payload = msg.q;\n\nreturn msg;","outputs":1,"noerr":0,"x":682.6666793823242,"y":2191.6665627111943,"wires":[["c5bff075.3a401"]]},{"id":"d62afb90.29d508","type":"function","z":"2afdf263.d5020e","name":"スコア格納","func":"if (msg.payload.FREQ != null)\n    msg.s[msg.i] = msg.payload.FREQ;\nelse\n    msg.s[msg.i] = 0;\n\nreturn msg;","outputs":1,"noerr":0,"x":1479.6666793823242,"y":2185.6665627111943,"wires":[["4d3245e4.b2cdbc"]]},{"id":"b4cab012.4b355","type":"function","z":"2afdf263.d5020e","name":"payloadへスコア格納","func":"msg.payload = new Object();\nmsg.payload.s = msg.s;\n\nreturn msg;","outputs":1,"noerr":0,"x":712.6666793823242,"y":2251.6665627111943,"wires":[["7e52b129.81ad5","2e88f6cf.d1770a"]]},{"id":"705f0eac.8fa0f","type":"function","z":"2afdf263.d5020e","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":527.6666793823242,"y":2105.6665627111943,"wires":[["e8a90cbc.1756f"]]},{"id":"4d3245e4.b2cdbc","type":"function","z":"2afdf263.d5020e","name":"i++","func":"msg.i++;\n\nreturn msg;","outputs":1,"noerr":0,"x":1036.6666793823242,"y":2079.6665627111943,"wires":[["f666f2cb.09991"]]},{"id":"f666f2cb.09991","type":"switch","z":"2afdf263.d5020e","name":"i<4","property":"i","rules":[{"t":"lt","v":"4"},{"t":"else"}],"checkall":"true","outputs":2,"x":534.6666793823242,"y":2198.6665627111943,"wires":[["b873e679.478c18"],["b4cab012.4b355"]]},{"id":"d910ecaf.26ef1","type":"template","z":"2afdf263.d5020e","name":"i=0","field":"i","format":"handlebars","template":"0","x":380.6666793823242,"y":2199.6665627111943,"wires":[["f666f2cb.09991"]]},{"id":"e8a90cbc.1756f","type":"function","z":"2afdf263.d5020e","name":"スコア初期化","func":"msg.s = new Array(4);\n\nreturn msg;","outputs":1,"noerr":0,"x":690.6666793823242,"y":2105.6665627111943,"wires":[["d910ecaf.26ef1"]]},{"id":"6a557ea0.95aa8","type":"debug","z":"2afdf263.d5020e","name":"","active":false,"console":"false","complete":"false","x":538.6666793823242,"y":2053.6665627111943,"wires":[]},{"id":"2e88f6cf.d1770a","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":908.6666793823242,"y":2290.6665627111943,"wires":[]},{"id":"7c300f32.83cff","type":"function","z":"2afdf263.d5020e","name":"c+q","func":"for (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to /, \"to_\");\n}\n\nvar min = Math.min(msg.c[0].split(\" \").length,\nmsg.c[1].split(\" \").length,\nmsg.c[2].split(\" \").length,\nmsg.c[3].split(\" \").length);\n\nvar strs = msg.c[msg.i].split(\" \");\nvar tmp = \"\";\nfor (var i = strs.length - min; i < strs.length; i++)\n{\n    tmp += strs[i];\n    if (i != strs.length-1)\n    {\n        tmp += \" \";\n    }\n}\n\nif (msg.payload != \"\")\n{\n    msg.payload = tmp.replace(/^to_/, \"to \") + \" \" + msg.payload;\n}\nelse\n{\n    msg.payload = \"\";\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to_/, \"to \");\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1203.6666793823242,"y":2184.6666084875615,"wires":[["4af00f1c.b50ff","bf41865f.40be78"]]},{"id":"9361e4e4.6c9e18","type":"function","z":"2afdf263.d5020e","name":"qとcを連結","func":"for (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to /, \"to_\");\n}\n\nvar min = Math.min(msg.c[0].split(\" \").length,\nmsg.c[1].split(\" \").length,\nmsg.c[2].split(\" \").length,\nmsg.c[3].split(\" \").length);\n\nvar strs = msg.c[msg.i].split(\" \");\nvar tmp = \"\";\nfor (var i = 0; i < min; i++)\n{\n    tmp += strs[i];\n    if (i != min-1)\n    {\n        tmp += \" \";\n    }\n}\n\nif (msg.payload != \"\")\n{\n    msg.payload = msg.payload + \" \" + tmp.replace(/^to_/, \"to \");\n}\nelse\n{\n    msg.payload = \"\";\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to_/, \"to \");\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1201.6666793823242,"y":1871.6666084875615,"wires":[["8448bb5e.7bb748","2d51a92b.d2ae56"]]},{"id":"3f107c0.fc0ef84","type":"debug","z":"2afdf263.d5020e","name":"連結文字列出力","active":true,"console":"false","complete":"payload","x":1472.6666793823242,"y":1958.6666084875615,"wires":[]},{"id":"bf41865f.40be78","type":"function","z":"2afdf263.d5020e","name":"文頭文末識別文字追加","func":"msg.payload = \"2gram2:_\" + msg.payload + \"_\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1277.6666793823242,"y":2259.6666084875615,"wires":[["d36cde6f.2c932"]]},{"id":"2d51a92b.d2ae56","type":"function","z":"2afdf263.d5020e","name":"文頭文末識別文字追加","func":"msg.payload = \"2gram1:_\" + msg.payload + \"_\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1276.6666793823242,"y":1960.6666084875615,"wires":[["3f107c0.fc0ef84"]]},{"id":"d36cde6f.2c932","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":1473.6666793823242,"y":2259.6666084875615,"wires":[]},{"id":"25e6f6ae.da190a","type":"function","z":"2afdf263.d5020e","name":"文字列を配列化","func":"msg.payload = msg.payload.split(/ |, /);\n\nreturn msg;","outputs":1,"noerr":0,"x":861.7708511352539,"y":2487.6666084875615,"wires":[["54900eef.ab6ff"]]},{"id":"54900eef.ab6ff","type":"function","z":"2afdf263.d5020e","name":"空欄前2単語抽出","func":"var input = msg.payload;\nvar i = 0;\n\nwhile (i<input.length && !input[i].match(/^-+$/))\n{\n    i++;\n}\n\nvar tmp = \"\";\nvar len = 2;\nif (0 <= i-len)\n{\n    for (var j = i-len; j < input.length && j < i; j++)\n    {\n        tmp += input[j];\n        if (j != input.length-1 && j != i-1)\n        {\n            tmp += \" \";\n        }\n    }\n}\nmsg.payload = tmp;\n\nreturn msg;","outputs":1,"noerr":0,"x":1053.770851135254,"y":2485.6666084875615,"wires":[["fe75b6f4.018a48"]]},{"id":"c04d1b2e.3fb2e8","type":"dashDB in","z":"2afdf263.d5020e","service":"dashDB-f6","query":"SELECT * FROM NGRM WHERE WORD = ?;","params":"msg.payload","name":"","x":1349.770851135254,"y":2484.6666084875615,"wires":[["3f5f4401.c0a0bc"]]},{"id":"c6590e4b.39a6f","type":"http in","z":"2afdf263.d5020e","name":"","url":"/3gram1","method":"get","swaggerDoc":"","x":382.7708511352539,"y":2406.6666390051396,"wires":[["e28c055e.1d73f8","23373e03.dcc8c2"]]},{"id":"c5251c18.3adae","type":"http response","z":"2afdf263.d5020e","name":"","x":904.7708358764648,"y":2550.6666084875615,"wires":[]},{"id":"a770de8.f588f2","type":"function","z":"2afdf263.d5020e","name":"payload = q","func":"msg.payload = msg.q;\n\nreturn msg;","outputs":1,"noerr":0,"x":696.7708511352539,"y":2490.6666084875615,"wires":[["25e6f6ae.da190a"]]},{"id":"3f5f4401.c0a0bc","type":"function","z":"2afdf263.d5020e","name":"スコア格納","func":"if (msg.payload.FREQ != null)\n    msg.s[msg.i] = msg.payload.FREQ;\nelse\n    msg.s[msg.i] = 0;\n\nreturn msg;","outputs":1,"noerr":0,"x":1493.770851135254,"y":2484.6666084875615,"wires":[["c5731af8.3a8ce8"]]},{"id":"37b37c41.c84c84","type":"function","z":"2afdf263.d5020e","name":"payloadへスコア格納","func":"msg.payload = new Object();\nmsg.payload.s = msg.s;\n\nreturn msg;","outputs":1,"noerr":0,"x":726.7708511352539,"y":2550.6666084875615,"wires":[["c5251c18.3adae","39547b86.c6ab84"]]},{"id":"87900d24.786ff","type":"http in","z":"2afdf263.d5020e","name":"","url":"/3gram2","method":"get","swaggerDoc":"","x":379.66667556762695,"y":2691.5555702795536,"wires":[["e6008557.19ff78","899a18ff.7665e8"]]},{"id":"e28c055e.1d73f8","type":"function","z":"2afdf263.d5020e","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":541.7708511352539,"y":2404.6666084875615,"wires":[["31c8a39c.ce375c"]]},{"id":"c5731af8.3a8ce8","type":"function","z":"2afdf263.d5020e","name":"i++","func":"msg.i++;\n\nreturn msg;","outputs":1,"noerr":0,"x":1050.770851135254,"y":2378.6666084875615,"wires":[["87bd92bf.78427"]]},{"id":"87bd92bf.78427","type":"switch","z":"2afdf263.d5020e","name":"i<4","property":"i","rules":[{"t":"lt","v":"4"},{"t":"else"}],"checkall":"true","outputs":2,"x":548.7708511352539,"y":2497.6666084875615,"wires":[["a770de8.f588f2"],["37b37c41.c84c84"]]},{"id":"3788af8d.c8775","type":"template","z":"2afdf263.d5020e","name":"i=0","field":"i","format":"handlebars","template":"0","x":394.7708511352539,"y":2498.6666084875615,"wires":[["87bd92bf.78427"]]},{"id":"31c8a39c.ce375c","type":"function","z":"2afdf263.d5020e","name":"スコア初期化","func":"msg.s = new Array(4);\n\nreturn msg;","outputs":1,"noerr":0,"x":704.7708511352539,"y":2404.6666084875615,"wires":[["3788af8d.c8775"]]},{"id":"23373e03.dcc8c2","type":"debug","z":"2afdf263.d5020e","name":"","active":false,"console":"false","complete":"false","x":552.7708511352539,"y":2352.6666084875615,"wires":[]},{"id":"39547b86.c6ab84","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":922.7708511352539,"y":2589.6666084875615,"wires":[]},{"id":"a3c82cf1.5c37d","type":"function","z":"2afdf263.d5020e","name":"空欄後1単語抽出","func":"var input = msg.payload;\nvar i = 0;\n\nwhile (i<input.length && !input[i].match(/^-+$/))\n{\n    i++;\n}\n\nvar tmp = \"\";\nvar len =1;\nif (i+len < input.length)\n{\n    for (var j = i+1; j < input.length && j-(i+1) < len; j++)\n    {\n        tmp += input[j];\n        if (j != input.length-1 && j-(i+1) != len-1)\n        {\n            tmp += \" \";\n        }\n    }\n}\nmsg.payload = tmp;\n\nreturn msg;","outputs":1,"noerr":0,"x":1107.7708473205566,"y":2832.6666542639286,"wires":[["9c57a741.63a858"]]},{"id":"1fb54487.e04abb","type":"function","z":"2afdf263.d5020e","name":"文字列を配列化","func":"msg.payload = msg.payload.split(/ |, /);\n\nreturn msg;","outputs":1,"noerr":0,"x":919.7708587646484,"y":2774.666745816663,"wires":[["22626f8e.dd9d9"]]},{"id":"4ad524b9.b52adc","type":"dashDB in","z":"2afdf263.d5020e","service":"dashDB-f6","query":"SELECT * FROM NGRM WHERE WORD = ?;","params":"msg.payload","name":"","x":1485.7708473205566,"y":2772.6666542639286,"wires":[["ac8468f2.537b98"]]},{"id":"6e3f4689.91c0b8","type":"http response","z":"2afdf263.d5020e","name":"","x":973.7708320617676,"y":2881.6666542639286,"wires":[]},{"id":"ada812e8.5257f","type":"function","z":"2afdf263.d5020e","name":"payload = q","func":"msg.payload = msg.q;\n\nreturn msg;","outputs":1,"noerr":0,"x":764.7708473205566,"y":2775.6666542639286,"wires":[["1fb54487.e04abb"]]},{"id":"ac8468f2.537b98","type":"function","z":"2afdf263.d5020e","name":"スコア格納","func":"if (msg.payload.FREQ != null)\n    msg.s[msg.i] = msg.payload.FREQ;\nelse\n    msg.s[msg.i] = 0;\n\nreturn msg;","outputs":1,"noerr":0,"x":1615.770896911621,"y":2773.6665627111943,"wires":[["58ebcf02.a7143"]]},{"id":"687e35ec.9781cc","type":"function","z":"2afdf263.d5020e","name":"payloadへスコア格納","func":"msg.payload = new Object();\nmsg.payload.s = msg.s;\n\nreturn msg;","outputs":1,"noerr":0,"x":795.7708473205566,"y":2881.6666542639286,"wires":[["6e3f4689.91c0b8","19b8fa7a.e64706"]]},{"id":"899a18ff.7665e8","type":"function","z":"2afdf263.d5020e","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":539.7708473205566,"y":2689.6666542639286,"wires":[["fd6d9f2e.02926"]]},{"id":"58ebcf02.a7143","type":"function","z":"2afdf263.d5020e","name":"i++","func":"msg.i++;\n\nreturn msg;","outputs":1,"noerr":0,"x":1048.7708473205566,"y":2663.6666542639286,"wires":[["9cd515eb.632ae8"]]},{"id":"9cd515eb.632ae8","type":"switch","z":"2afdf263.d5020e","name":"i<4","property":"i","rules":[{"t":"lt","v":"4"},{"t":"else"}],"checkall":"true","outputs":2,"x":546.7708473205566,"y":2782.6666542639286,"wires":[["ada812e8.5257f"],["687e35ec.9781cc"]]},{"id":"b9fca229.46036","type":"template","z":"2afdf263.d5020e","name":"i=0","field":"i","format":"handlebars","template":"0","x":392.77084732055664,"y":2783.6666542639286,"wires":[["9cd515eb.632ae8"]]},{"id":"fd6d9f2e.02926","type":"function","z":"2afdf263.d5020e","name":"スコア初期化","func":"msg.s = new Array(4);\n\nreturn msg;","outputs":1,"noerr":0,"x":702.7708473205566,"y":2689.6666542639286,"wires":[["b9fca229.46036"]]},{"id":"e6008557.19ff78","type":"debug","z":"2afdf263.d5020e","name":"","active":false,"console":"false","complete":"false","x":550.7708473205566,"y":2637.6666542639286,"wires":[]},{"id":"19b8fa7a.e64706","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":991.7708473205566,"y":2920.6666542639286,"wires":[]},{"id":"9c57a741.63a858","type":"function","z":"2afdf263.d5020e","name":"tmp+c+q条件付","func":"for (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to /, \"to_\");\n}\n\nvar min = Math.min(msg.c[0].split(\" \").length,\nmsg.c[1].split(\" \").length,\nmsg.c[2].split(\" \").length,\nmsg.c[3].split(\" \").length);\n\nvar max = Math.max(msg.c[0].split(\" \").length,\nmsg.c[1].split(\" \").length,\nmsg.c[2].split(\" \").length,\nmsg.c[3].split(\" \").length);\n\nif (min == max && msg.tmp != \"\" && msg.payload != \"\")\n{\n    msg.payload = msg.tmp + \" \" + msg.c[msg.i].replace(/^to_/, \"to \") + \" \" + msg.payload;\n}\nelse\n{\n    msg.payload = \"\";\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to_/, \"to \");\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1282.7708435058594,"y":2832.666745816663,"wires":[["4ad524b9.b52adc","a6f1cbe9.590e38"]]},{"id":"fe75b6f4.018a48","type":"function","z":"2afdf263.d5020e","name":"q+c","func":"for (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to /, \"to_\");\n}\n\nvar min = Math.min(msg.c[0].split(\" \").length,\nmsg.c[1].split(\" \").length,\nmsg.c[2].split(\" \").length,\nmsg.c[3].split(\" \").length);\n\nvar strs = msg.c[msg.i].split(\" \");\nvar tmp = \"\";\nfor (var i = 0; i < min; i++)\n{\n    tmp += strs[i];\n    if (i != min-1)\n    {\n        tmp += \" \";\n    }\n}\n\nif (msg.payload != \"\")\n{\n    msg.payload = msg.payload + \" \" + tmp.replace(/^to_/, \"to \");\n}\nelse\n{\n    msg.payload = \"\";\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to_/, \"to \");\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1210.770851135254,"y":2487.6666084875615,"wires":[["c04d1b2e.3fb2e8","c4921193.3b6df"]]},{"id":"7f48a86d.80b758","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":1503.770851135254,"y":2574.6666084875615,"wires":[]},{"id":"a6f1cbe9.590e38","type":"function","z":"2afdf263.d5020e","name":"文頭文末識別文字追加","func":"msg.payload = \"3gram2:_\" + msg.payload + \"_\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1402.7708473205566,"y":2886.6666542639286,"wires":[["90a95852.6f56a8"]]},{"id":"c4921193.3b6df","type":"function","z":"2afdf263.d5020e","name":"文頭文末識別文字追加","func":"msg.payload = \"3gram1:_\" + msg.payload + \"_\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1307.770851135254,"y":2576.6666084875615,"wires":[["7f48a86d.80b758"]]},{"id":"90a95852.6f56a8","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":1598.7708473205566,"y":2886.6666542639286,"wires":[]},{"id":"94b2638c.6b4da","type":"function","z":"2afdf263.d5020e","name":"文字列を配列化","func":"msg.payload = msg.payload.split(/ |, /);\n\nreturn msg;","outputs":1,"noerr":0,"x":848.7708625793457,"y":3531.6666542639286,"wires":[["b848c63e.47b738"]]},{"id":"b848c63e.47b738","type":"function","z":"2afdf263.d5020e","name":"空欄前3単語抽出","func":"var input = msg.payload;\nvar i = 0;\n\nwhile (i<input.length && !input[i].match(/^-+$/))\n{\n    i++;\n}\n\nvar tmp = \"\";\nvar len = 3;\nif (0 <= i-len)\n{\n    for (var j = i-len; j < input.length && j < i; j++)\n    {\n        tmp += input[j];\n        if (j != input.length-1 && j != i-1)\n        {\n            tmp += \" \";\n        }\n    }\n}\nmsg.payload = tmp;\n\nreturn msg;","outputs":1,"noerr":0,"x":1040.7708625793457,"y":3529.6666542639286,"wires":[["fef4dcaa.010b2"]]},{"id":"7d86795.f827988","type":"dashDB in","z":"2afdf263.d5020e","service":"dashDB-f6","query":"SELECT * FROM NGRM WHERE WORD = ?;","params":"msg.payload","name":"","x":1336.7708625793457,"y":3528.6666542639286,"wires":[["c60eebdf.39f118"]]},{"id":"a183bbf1.5e7c48","type":"http in","z":"2afdf263.d5020e","name":"","url":"/4gram1","method":"get","swaggerDoc":"","x":369.7708625793457,"y":3450.666684781507,"wires":[["d22a5688.2dd5a8","7605430a.89fabc"]]},{"id":"3a72e047.c58d2","type":"http response","z":"2afdf263.d5020e","name":"","x":891.7708473205566,"y":3594.6666542639286,"wires":[]},{"id":"756b5723.8a94a8","type":"function","z":"2afdf263.d5020e","name":"payload = q","func":"msg.payload = msg.q;\n\nreturn msg;","outputs":1,"noerr":0,"x":683.7708625793457,"y":3534.6666542639286,"wires":[["94b2638c.6b4da"]]},{"id":"c60eebdf.39f118","type":"function","z":"2afdf263.d5020e","name":"スコア格納","func":"if (msg.payload.FREQ != null)\n    msg.s[msg.i] = msg.payload.FREQ;\nelse\n    msg.s[msg.i] = 0;\n\nreturn msg;","outputs":1,"noerr":0,"x":1480.7708625793457,"y":3528.6666542639286,"wires":[["c1e28c0.f3e1d7"]]},{"id":"e515f9e.f1aea08","type":"function","z":"2afdf263.d5020e","name":"payloadへスコア格納","func":"msg.payload = new Object();\nmsg.payload.s = msg.s;\n\nreturn msg;","outputs":1,"noerr":0,"x":713.7708625793457,"y":3594.6666542639286,"wires":[["3a72e047.c58d2","54f94383.ab06bc"]]},{"id":"f02a4c2c.0fd5b","type":"http in","z":"2afdf263.d5020e","name":"","url":"/4gram2","method":"get","swaggerDoc":"","x":363.666690826416,"y":3767.5555245031865,"wires":[["6f6e8547.90917c","14404e1a.ebbfb2"]]},{"id":"d22a5688.2dd5a8","type":"function","z":"2afdf263.d5020e","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":528.7708625793457,"y":3448.6666542639286,"wires":[["eba1408c.145ec"]]},{"id":"c1e28c0.f3e1d7","type":"function","z":"2afdf263.d5020e","name":"i++","func":"msg.i++;\n\nreturn msg;","outputs":1,"noerr":0,"x":1037.7708625793457,"y":3422.6666542639286,"wires":[["a2b6e790.5d4918"]]},{"id":"a2b6e790.5d4918","type":"switch","z":"2afdf263.d5020e","name":"i<4","property":"i","rules":[{"t":"lt","v":"4"},{"t":"else"}],"checkall":"true","outputs":2,"x":535.7708625793457,"y":3541.6666542639286,"wires":[["756b5723.8a94a8"],["e515f9e.f1aea08"]]},{"id":"b189110c.4e76f","type":"template","z":"2afdf263.d5020e","name":"i=0","field":"i","format":"handlebars","template":"0","x":381.7708625793457,"y":3542.6666542639286,"wires":[["a2b6e790.5d4918"]]},{"id":"eba1408c.145ec","type":"function","z":"2afdf263.d5020e","name":"スコア初期化","func":"msg.s = new Array(4);\n\nreturn msg;","outputs":1,"noerr":0,"x":691.7708625793457,"y":3448.6666542639286,"wires":[["b189110c.4e76f"]]},{"id":"7605430a.89fabc","type":"debug","z":"2afdf263.d5020e","name":"","active":false,"console":"false","complete":"false","x":539.7708625793457,"y":3396.6666542639286,"wires":[]},{"id":"54f94383.ab06bc","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":909.7708625793457,"y":3633.6666542639286,"wires":[]},{"id":"b976868c.468978","type":"function","z":"2afdf263.d5020e","name":"空欄後3単語抽出","func":"var input = msg.payload;\nvar i = 0;\n\nwhile (i<input.length && !input[i].match(/^-+$/))\n{\n    i++;\n}\n\nvar tmp = \"\";\nvar len = 3;\nif (i+len < input.length)\n{\n    for (var j = i+1; j < input.length && j-(i+1) < len; j++)\n    {\n        tmp += input[j];\n        if (j != input.length-1 && j-(i+1) != len-1)\n        {\n            tmp += \" \";\n        }\n    }\n}\nmsg.payload = tmp;\n\nreturn msg;","outputs":1,"noerr":0,"x":1031.7708625793457,"y":3845.6666084875615,"wires":[["f5e3791b.0a1c88"]]},{"id":"c141581.f3ebea8","type":"function","z":"2afdf263.d5020e","name":"文字列を配列化","func":"msg.payload = msg.payload.split(/ |, /);\n\nreturn msg;","outputs":1,"noerr":0,"x":843.7708625793457,"y":3848.6666084875615,"wires":[["b976868c.468978"]]},{"id":"db9eadcf.24615","type":"dashDB in","z":"2afdf263.d5020e","service":"dashDB-f6","query":"SELECT * FROM NGRM WHERE WORD = ?;","params":"msg.payload","name":"","x":1331.7708625793457,"y":3845.6666084875615,"wires":[["5d5f54c1.a2a0ac"]]},{"id":"9536c608.6ac938","type":"http response","z":"2afdf263.d5020e","name":"","x":886.7708473205566,"y":3911.6666084875615,"wires":[]},{"id":"1d9f1b53.e260e5","type":"function","z":"2afdf263.d5020e","name":"payload = q","func":"msg.payload = msg.q;\n\nreturn msg;","outputs":1,"noerr":0,"x":678.7708625793457,"y":3851.6666084875615,"wires":[["c141581.f3ebea8"]]},{"id":"5d5f54c1.a2a0ac","type":"function","z":"2afdf263.d5020e","name":"スコア格納","func":"if (msg.payload.FREQ != null)\n    msg.s[msg.i] = msg.payload.FREQ;\nelse\n    msg.s[msg.i] = 0;\n\nreturn msg;","outputs":1,"noerr":0,"x":1475.7708625793457,"y":3845.6666084875615,"wires":[["3c92e045.c36d2"]]},{"id":"20f86293.df079e","type":"function","z":"2afdf263.d5020e","name":"payloadへスコア格納","func":"msg.payload = new Object();\nmsg.payload.s = msg.s;\n\nreturn msg;","outputs":1,"noerr":0,"x":708.7708625793457,"y":3911.6666084875615,"wires":[["9536c608.6ac938","fc52010c.03ae"]]},{"id":"14404e1a.ebbfb2","type":"function","z":"2afdf263.d5020e","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":523.7708625793457,"y":3765.6666084875615,"wires":[["19a6b676.e6594a"]]},{"id":"3c92e045.c36d2","type":"function","z":"2afdf263.d5020e","name":"i++","func":"msg.i++;\n\nreturn msg;","outputs":1,"noerr":0,"x":1032.7708625793457,"y":3739.6666084875615,"wires":[["f84ef85b.07b108"]]},{"id":"f84ef85b.07b108","type":"switch","z":"2afdf263.d5020e","name":"i<4","property":"i","rules":[{"t":"lt","v":"4"},{"t":"else"}],"checkall":"true","outputs":2,"x":530.7708625793457,"y":3858.6666084875615,"wires":[["1d9f1b53.e260e5"],["20f86293.df079e"]]},{"id":"162d8bd5.e9d274","type":"template","z":"2afdf263.d5020e","name":"i=0","field":"i","format":"handlebars","template":"0","x":376.7708625793457,"y":3859.6666084875615,"wires":[["f84ef85b.07b108"]]},{"id":"19a6b676.e6594a","type":"function","z":"2afdf263.d5020e","name":"スコア初期化","func":"msg.s = new Array(4);\n\nreturn msg;","outputs":1,"noerr":0,"x":686.7708625793457,"y":3765.6666084875615,"wires":[["162d8bd5.e9d274"]]},{"id":"6f6e8547.90917c","type":"debug","z":"2afdf263.d5020e","name":"","active":false,"console":"false","complete":"false","x":534.7708625793457,"y":3713.6666084875615,"wires":[]},{"id":"fc52010c.03ae","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":904.7708625793457,"y":3950.6666084875615,"wires":[]},{"id":"f5e3791b.0a1c88","type":"function","z":"2afdf263.d5020e","name":"c+q","func":"for (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to /, \"to_\");\n}\n\nvar min = Math.min(msg.c[0].split(\" \").length,\nmsg.c[1].split(\" \").length,\nmsg.c[2].split(\" \").length,\nmsg.c[3].split(\" \").length);\n\nvar strs = msg.c[msg.i].split(\" \");\nvar tmp = \"\";\nfor (var i = strs.length - min; i < strs.length; i++)\n{\n    tmp += strs[i];\n    if (i != strs.length-1)\n    {\n        tmp += \" \";\n    }\n}\n\nif (msg.payload != \"\")\n{\n    msg.payload = tmp.replace(/^to_/, \"to \") + \" \" + msg.payload;\n}\nelse\n{\n    msg.payload = \"\";\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to_/, \"to \");\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1199.7708625793457,"y":3844.6666542639286,"wires":[["db9eadcf.24615","19daf694.e62509"]]},{"id":"fef4dcaa.010b2","type":"function","z":"2afdf263.d5020e","name":"q+c","func":"for (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to /, \"to_\");\n}\n\nvar min = Math.min(msg.c[0].split(\" \").length,\nmsg.c[1].split(\" \").length,\nmsg.c[2].split(\" \").length,\nmsg.c[3].split(\" \").length);\n\nvar strs = msg.c[msg.i].split(\" \");\nvar tmp = \"\";\nfor (var i = 0; i < min; i++)\n{\n    tmp += strs[i];\n    if (i != min-1)\n    {\n        tmp += \" \";\n    }\n}\n\nif (msg.payload != \"\")\n{\n    msg.payload = msg.payload + \" \" + tmp.replace(/^to_/, \"to \");\n}\nelse\n{\n    msg.payload = \"\";\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to_/, \"to \");\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1197.7708625793457,"y":3531.6666542639286,"wires":[["7d86795.f827988","dd399c43.22c66"]]},{"id":"887d660a.778298","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":1490.7708625793457,"y":3618.6666542639286,"wires":[]},{"id":"19daf694.e62509","type":"function","z":"2afdf263.d5020e","name":"文頭文末識別文字追加","func":"msg.payload = \"4gram2:_\" + msg.payload + \"_\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1273.7708625793457,"y":3919.6666542639286,"wires":[["ab9a5293.5465b"]]},{"id":"dd399c43.22c66","type":"function","z":"2afdf263.d5020e","name":"文頭文末識別文字追加","func":"msg.payload = \"4gram1:_\" + msg.payload + \"_\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1294.7708625793457,"y":3620.6666542639286,"wires":[["887d660a.778298"]]},{"id":"ab9a5293.5465b","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":1469.7708625793457,"y":3919.6666542639286,"wires":[]},{"id":"627bbd13.9d8444","type":"http in","z":"2afdf263.d5020e","name":"","url":"/3gram3","method":"get","swaggerDoc":"","x":380.66667556762695,"y":3058.6666542639286,"wires":[["5a326c60.a5cd94","a148bc7f.5eb74"]]},{"id":"b736cb2.f48c938","type":"function","z":"2afdf263.d5020e","name":"空欄後2単語抽出","func":"var input = msg.payload;\nvar i = 0;\n\nwhile (i<input.length && !input[i].match(/^-+$/))\n{\n    i++;\n}\n\nvar tmp = \"\";\nvar len = 2;\nif (i+len < input.length)\n{\n    for (var j = i+1; j < input.length && j-(i+1) < len; j++)\n    {\n        tmp += input[j];\n        if (j != input.length-1 && j-(i+1) != len-1)\n        {\n            tmp += \" \";\n        }\n    }\n}\nmsg.payload = tmp;\n\nreturn msg;","outputs":1,"noerr":0,"x":1048.7708473205566,"y":3136.7777382483036,"wires":[["afae390f.5051c8"]]},{"id":"78821faa.877de","type":"function","z":"2afdf263.d5020e","name":"文字列を配列化","func":"msg.payload = msg.payload.split(/ |, /);\n\nreturn msg;","outputs":1,"noerr":0,"x":860.7708473205566,"y":3139.7777382483036,"wires":[["b736cb2.f48c938"]]},{"id":"5702da0b.a8fd24","type":"dashDB in","z":"2afdf263.d5020e","service":"dashDB-f6","query":"SELECT * FROM NGRM WHERE WORD = ?;","params":"msg.payload","name":"","x":1348.7708473205566,"y":3136.7777382483036,"wires":[["3353d164.ccac2e"]]},{"id":"1003b05f.effc5","type":"http response","z":"2afdf263.d5020e","name":"","x":903.7708320617676,"y":3202.7777382483036,"wires":[]},{"id":"cb3a41f6.34c5c","type":"function","z":"2afdf263.d5020e","name":"payload = q","func":"msg.payload = msg.q;\n\nreturn msg;","outputs":1,"noerr":0,"x":695.7708473205566,"y":3142.7777382483036,"wires":[["78821faa.877de"]]},{"id":"3353d164.ccac2e","type":"function","z":"2afdf263.d5020e","name":"スコア格納","func":"if (msg.payload.FREQ != null)\n    msg.s[msg.i] = msg.payload.FREQ;\nelse\n    msg.s[msg.i] = 0;\n\nreturn msg;","outputs":1,"noerr":0,"x":1492.7708473205566,"y":3136.7777382483036,"wires":[["410ce844.bef318"]]},{"id":"f7934739.086cb8","type":"function","z":"2afdf263.d5020e","name":"payloadへスコア格納","func":"msg.payload = new Object();\nmsg.payload.s = msg.s;\n\nreturn msg;","outputs":1,"noerr":0,"x":725.7708473205566,"y":3202.7777382483036,"wires":[["1003b05f.effc5","a5899ee5.5a766"]]},{"id":"a148bc7f.5eb74","type":"function","z":"2afdf263.d5020e","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":540.7708473205566,"y":3056.7777382483036,"wires":[["cbbd4d26.3442b"]]},{"id":"410ce844.bef318","type":"function","z":"2afdf263.d5020e","name":"i++","func":"msg.i++;\n\nreturn msg;","outputs":1,"noerr":0,"x":1049.7708473205566,"y":3030.7777382483036,"wires":[["6787ee38.98781"]]},{"id":"6787ee38.98781","type":"switch","z":"2afdf263.d5020e","name":"i<4","property":"i","rules":[{"t":"lt","v":"4"},{"t":"else"}],"checkall":"true","outputs":2,"x":547.7708473205566,"y":3149.7777382483036,"wires":[["cb3a41f6.34c5c"],["f7934739.086cb8"]]},{"id":"77e7b7fd.881848","type":"template","z":"2afdf263.d5020e","name":"i=0","field":"i","format":"handlebars","template":"0","x":393.77084732055664,"y":3150.7777382483036,"wires":[["6787ee38.98781"]]},{"id":"cbbd4d26.3442b","type":"function","z":"2afdf263.d5020e","name":"スコア初期化","func":"msg.s = new Array(4);\n\nreturn msg;","outputs":1,"noerr":0,"x":703.7708473205566,"y":3056.7777382483036,"wires":[["77e7b7fd.881848"]]},{"id":"5a326c60.a5cd94","type":"debug","z":"2afdf263.d5020e","name":"","active":false,"console":"false","complete":"false","x":551.7708473205566,"y":3004.7777382483036,"wires":[]},{"id":"a5899ee5.5a766","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":921.7708473205566,"y":3241.7777382483036,"wires":[]},{"id":"afae390f.5051c8","type":"function","z":"2afdf263.d5020e","name":"c+q","func":"for (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to /, \"to_\");\n}\n\nvar min = Math.min(msg.c[0].split(\" \").length,\nmsg.c[1].split(\" \").length,\nmsg.c[2].split(\" \").length,\nmsg.c[3].split(\" \").length);\n\nvar strs = msg.c[msg.i].split(\" \");\nvar tmp = \"\";\nfor (var i = strs.length - min; i < strs.length; i++)\n{\n    tmp += strs[i];\n    if (i != strs.length-1)\n    {\n        tmp += \" \";\n    }\n}\n\nif (msg.payload != \"\")\n{\n    msg.payload = tmp.replace(/^to_/, \"to \") + \" \" + msg.payload;\n}\nelse\n{\n    msg.payload = \"\";\n}\n\nfor (var i = 0; i < 4; i++)\n{\n    msg.c[i] = msg.c[i].replace(/^to_/, \"to \");\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1216.7708473205566,"y":3135.777784024671,"wires":[["5702da0b.a8fd24","3e4e30c9.c1b1d"]]},{"id":"3e4e30c9.c1b1d","type":"function","z":"2afdf263.d5020e","name":"文頭文末識別文字追加","func":"msg.payload = \"3gram3:_\" + msg.payload + \"_\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1290.7708473205566,"y":3210.777784024671,"wires":[["49d932a1.b626cc"]]},{"id":"49d932a1.b626cc","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":1486.7708473205566,"y":3210.777784024671,"wires":[]},{"id":"22626f8e.dd9d9","type":"function","z":"2afdf263.d5020e","name":"空欄前1単語抽出","func":"var input = msg.payload;\nvar i = 0;\n\nwhile (i<input.length && !input[i].match(/^-+$/))\n{\n    i++;\n}\n\nvar tmp = \"\";\nvar len = 1;\nif (0 <= i-len)\n{\n    for (var j = i-len; j < input.length && j < i; j++)\n    {\n        tmp += input[j];\n        if (j != input.length-1 && j != i-1)\n        {\n            tmp += \" \";\n        }\n    }\n}\nmsg.payload = tmp;\n\nreturn msg;","outputs":1,"noerr":0,"x":1106.666660308838,"y":2774.6666542639286,"wires":[["a66dbdcd.59924"]]},{"id":"a66dbdcd.59924","type":"function","z":"2afdf263.d5020e","name":"tmp = payload","func":"msg.tmp = msg.payload;\n\nreturn msg;","outputs":1,"noerr":0,"x":1276.666660308838,"y":2774.6666542639286,"wires":[["8d210b0d.72def8"]]},{"id":"8d210b0d.72def8","type":"function","z":"2afdf263.d5020e","name":"payload = q","func":"msg.payload = msg.q;\n\nreturn msg;","outputs":1,"noerr":0,"x":761.5624885559082,"y":2833.5555702795536,"wires":[["e4e32755.1b1cd8"]]},{"id":"e4e32755.1b1cd8","type":"function","z":"2afdf263.d5020e","name":"文字列を配列化","func":"msg.payload = msg.payload.split(/ |, /);\n\nreturn msg;","outputs":1,"noerr":0,"x":916.5625,"y":2832.555661832288,"wires":[["a3c82cf1.5c37d"]]},{"id":"d4062974.2bf9d8","type":"dashDB in","z":"2afdf263.d5020e","service":"dashDB-f6","query":"SELECT * FROM NGRM WHERE WORD = ?;","params":"msg.payload","name":"","x":1351.000804901123,"y":1558.6666533102543,"wires":[["20e4dd96.df1b22"]]},{"id":"c0e377a1.3f1c88","type":"http in","z":"2afdf263.d5020e","name":"","url":"/1gram1","method":"get","swaggerDoc":"","x":384.00080490112305,"y":1480.6666838278325,"wires":[["42f4e881.bd0b18","48524725.b7adb8"]]},{"id":"2ddeb86b.d22148","type":"http response","z":"2afdf263.d5020e","name":"","x":906.000789642334,"y":1624.6666533102543,"wires":[]},{"id":"9e75175e.618ae8","type":"function","z":"2afdf263.d5020e","name":"payload = c","func":"msg.payload = msg.c[msg.i];\n\nreturn msg;","outputs":1,"noerr":0,"x":698.000804901123,"y":1564.6666533102543,"wires":[["d4062974.2bf9d8","db58448f.24a7b8"]]},{"id":"20e4dd96.df1b22","type":"function","z":"2afdf263.d5020e","name":"スコア格納","func":"if (msg.payload.FREQ != null)\n    msg.s[msg.i] = msg.payload.FREQ;\nelse\n    msg.s[msg.i] = 0;\n\nreturn msg;","outputs":1,"noerr":0,"x":1495.000804901123,"y":1558.6666533102543,"wires":[["a39d2adc.5c62d8"]]},{"id":"a5904fb4.5a6fb","type":"function","z":"2afdf263.d5020e","name":"payloadへスコア格納","func":"msg.payload = new Object();\nmsg.payload.s = msg.s;\n\nreturn msg;","outputs":1,"noerr":0,"x":728.000804901123,"y":1624.6666533102543,"wires":[["2ddeb86b.d22148","9b2729f3.64d8d8"]]},{"id":"8cec6dd3.73139","type":"comment","z":"2afdf263.d5020e","name":"要素API","info":"","x":356.00001525878906,"y":1743.1212844848633,"wires":[]},{"id":"42f4e881.bd0b18","type":"function","z":"2afdf263.d5020e","name":"q,c,a退避","func":"msg.q = msg.payload.q;\nmsg.c = [msg.payload.c0, msg.payload.c1, msg.payload.c2, msg.payload.c3];\nmsg.a = msg.payload.a;\n\nreturn msg;","outputs":1,"noerr":0,"x":543.000804901123,"y":1478.6666533102543,"wires":[["657b4d99.9a84b4"]]},{"id":"a39d2adc.5c62d8","type":"function","z":"2afdf263.d5020e","name":"i++","func":"msg.i++;\n\nreturn msg;","outputs":1,"noerr":0,"x":1052.000804901123,"y":1452.6666533102543,"wires":[["4de1d764.b21e28"]]},{"id":"4de1d764.b21e28","type":"switch","z":"2afdf263.d5020e","name":"i<4","property":"i","rules":[{"t":"lt","v":"4"},{"t":"else"}],"checkall":"true","outputs":2,"x":550.000804901123,"y":1571.6666533102543,"wires":[["9e75175e.618ae8"],["a5904fb4.5a6fb"]]},{"id":"29b1b031.d64e5","type":"template","z":"2afdf263.d5020e","name":"i=0","field":"i","format":"handlebars","template":"0","x":396.00080490112305,"y":1572.6666533102543,"wires":[["4de1d764.b21e28"]]},{"id":"657b4d99.9a84b4","type":"function","z":"2afdf263.d5020e","name":"スコア初期化","func":"msg.s = new Array(4);\n\nreturn msg;","outputs":1,"noerr":0,"x":706.000804901123,"y":1478.6666533102543,"wires":[["29b1b031.d64e5"]]},{"id":"48524725.b7adb8","type":"debug","z":"2afdf263.d5020e","name":"","active":false,"console":"false","complete":"false","x":554.000804901123,"y":1426.6666533102543,"wires":[]},{"id":"9b2729f3.64d8d8","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":924.000804901123,"y":1663.6666533102543,"wires":[]},{"id":"cc71a7bf.338e58","type":"debug","z":"2afdf263.d5020e","name":"","active":true,"console":"false","complete":"false","x":1505.000804901123,"y":1648.6666533102543,"wires":[]},{"id":"db58448f.24a7b8","type":"function","z":"2afdf263.d5020e","name":"文頭文末識別文字追加","func":"msg.payload = \"1gram1:_\" + msg.payload + \"_\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1309.000804901123,"y":1650.6666533102543,"wires":[["cc71a7bf.338e58"]]}]