■今回作成したソースコード
[
{
"wires": [
[
"a007a948.20f6a"
]
],
"y": 38.00000762939453,
"id": "9de62461.aaae7",
"type": "http in",
"z": "1ff7c60f.1abbc2",
"name": "",
"url": "/",
"method": "get",
"swaggerDoc": "",
"x": 69.99998474121094
},
{
"wires": [
[
"6ca6caca.39f39c"
]
],
"y": 39.00000762939453,
"id": "a007a948.20f6a",
"type": "template",
"z": "1ff7c60f.1abbc2",
"name": "入力フォームの作成",
"field": "payload",
"format": "handlebars",
"template": "<!DOCTYPE html>\n<html>\n<head>\n <title>Personality Insights</title>\n <style type=text/css>\n textarea.c { width: 80em; height: 20ex; }\n </style>\n</head>\n<body>\n <h1>Personality Insights</h1>\n パーソナリティを分析する対象テキストを入力してください(100ワード以上)。\n <form action=/q method=POST>\n <textarea name=f class=c autofocus=true></textarea>\n <input type=submit value=分析 />\n </form>\n</body>\n</html>\n",
"x": 266
},
{
"wires": [],
"y": 41.00000762939453,
"x": 821,
"name": "",
"z": "1ff7c60f.1abbc2",
"type": "http response",
"id": "6ca6caca.39f39c"
},
{
"wires": [],
"y": 376.0000305175781,
"x": 822,
"name": "",
"z": "1ff7c60f.1abbc2",
"type": "http response",
"id": "6b01b71b.82e888"
},
{
"wires": [
[
"6b01b71b.82e888"
]
],
"y": 286,
"id": "41bb76fe.034f8",
"type": "template",
"z": "1ff7c60f.1abbc2",
"name": "回答HTML生成",
"field": "payload",
"format": "handlebars",
"template": "<html>\n<head>\n <title>Personality Insights</title>\n <style>\n li.high { color: magenta; }\n li.mid { color: black; }\n li.low { color: darkgreen; }\n </style>\n</head>\n<body>\n <h1>Personality Insights</h1>\n <h2>ビッグファイブ(Personality)</h2>\n {{{personality}}}\n <hr>\n <h2>欲求(needs)</h2>\n {{{needs}}}\n <hr>\n <h2>価値(values)</h2>\n {{{values}}}\n</body>\n</html>\n",
"x": 731
},
{
"wires": [
[
"41bb76fe.034f8"
]
],
"y": 286,
"id": "de401047.363f7",
"type": "function",
"z": "1ff7c60f.1abbc2",
"name": "回答の整形",
"func": "var categoryNameTable = {\n personality: ビッグファイブ,\n needs: 欲求,\n values: 価値\n};\nvar nameTable = {\n openness: 開放性,\n adventurousness: 大胆性,\n artistic interests: 芸術的関心度,\n emotionality: 情動性,\n imagination: 想像力,\n intellect: 思考力,\n liberalism: 現状打破,\n authority-challenging: 現状打破,\n achievement striving: 達成努力,\n conscientiousness: 誠実性,\n orderliness: 秩序性,\n cautiousness: 注意深さ,\n dutifulness: 秩序性,\n self-discipline: 自制力,\n self-efficacy: 自己効力感,\n activity level: 活発度,\n assertiveness: 自己主張,\n cheerfulness: 明朗性,\n excitement-seeking: 刺激希求性,\n friendliness: 外向性,\n gregariousness: 社交性,\n extraversion: 外向性,\n outgoing: 外向性,\n agreeableness: 協調性,\n altruism: 利他主義,\n cooperation: 協調性,\n modesty: 謙虚さ,\n morality: 道徳観,\n uncompromising: 強硬さ,\n sympathy: 共感度,\n trust: 信用度,\n emotional range: 情緒不安定性,\n fiery: 激情的,\n anger: 激情的,\n anxiety: 心配性,\n prone to worry: 心配性,\n depression: 悲観的,\n melancholy: 悲観的,\n immoderation: 利己的,\n self-consciousness: 自意識過剰,\n vulnerability: 低ストレス耐性,\n susceptible to stress: 低ストレス耐性,\n neuroticism: 情緒不安定性,\n openness_parent: 開放性,\n\n challenge: 挑戦,\n closeness: 親密,\n curiosity: 好奇心,\n excitement: 興奮,\n harmony: 調和,\n ideal: 理想,\n liberty: 自由主義,\n love: 社会性,\n practicality: 実用主義,\n self-expression: 自己表現,\n stability: 安定性,\n structure: 仕組,\n challenge_parent: 挑戦,\n\n conservation: 現状維持,\n openness to change: 変化許容性,\n hedonism: 快楽主義,\n self-enhancement: 自己増進,\n self-transcendence: 自己超越,\n self-transcendence_parent: 自己超越,\n values: 価値\n}\n\nfunction getInsights(insights, border_high, border_low) {\n var result = {\n personality: ,\n needs: ,\n values: \n };\n for (var i = 0; i < insights.length; i++) {\n var insight = insights[i];\n var name = nameTable[insight.name.toLowerCase()];\n if (name == null) name = insight.name.toLowerCase();\n if (insight.percentage != null && insight.percentage !== ) {\n var item_class = mid;\n if (insight.percentage > border_high && insight.percentage <= 1.0) {\n item_class = high;\n } else if (insight.percentage >= 0.0 && insight.percentage < border_low) {\n item_class = low;\n }\n result[insight.category] += <li class=\\ + item_class + \\> + name + : + Math.round(insight.percentage * 100, 0) + % + </li>;\n }\n if (insight.children != null) {\n var result_children = getInsights(insight.children, border_high, border_low); \n if (result_children.personality !== ) {\n result.personality += <ul> + result_children.personality + </ul>;\n }\n if (result_children.needs !== ) {\n result.needs += <ul> + result_children.needs + </ul>;\n }\n if (result_children.values !== ) {\n result.values += <ul> + result_children.values + </ul>;\n }\n }\n }\n return result;\n}\n\nvar result = getInsights(msg.insights.children, 0.8, 0.2);\n\nmsg.personality = <ul> + result.personality +</ul>;\nmsg.needs = <ul> + result.needs +</ul>;\nmsg.values = <ul> + result.values +</ul>;\n\nmsg.headers = {\n Content-type: text/html\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 561
},
{
"wires": [
[
"de401047.363f7"
]
],
"y": 209,
"x": 457,
"name": "Personality Insights呼び出し",
"z": "1ff7c60f.1abbc2",
"type": "watson-personality-insights",
"id": "1497d3db.2e241c"
},
{
"wires": [
[
"9e6a073a.c38478"
]
],
"y": 185,
"id": "f16c47c5.12cee8",
"type": "function",
"z": "1ff7c60f.1abbc2",
"name": "入力内容をpayloadへ",
"func": "msg.payload = msg.payload.f;\nmsg.payload_length = msg.payload.split(' ').length;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 164.00001525878906
},
{
"wires": [
[
"f16c47c5.12cee8"
]
],
"y": 94.99999237060547,
"id": "38e21bae.c02ca4",
"type": "http in",
"z": "1ff7c60f.1abbc2",
"name": "",
"url": "/q",
"method": "post",
"swaggerDoc": "",
"x": 68.99998474121094
},
{
"wires": [
[
"1497d3db.2e241c"
],
[
"7786a01b.3d2f9"
]
],
"y": 286.08331298828125,
"x": 221.0833282470703,
"id": "9e6a073a.c38478",
"type": "switch",
"z": "1ff7c60f.1abbc2",
"name": "100語以上?",
"property": "payload_length",
"rules": [
{
"v": "100",
"t": "gte"
},
{
"t": "else"
}
],
"checkall": "true",
"outputs": 2
},
{
"wires": [
[
"6b01b71b.82e888"
]
],
"y": 378.0833435058594,
"id": "7786a01b.3d2f9",
"type": "template",
"z": "1ff7c60f.1abbc2",
"name": "100文字未満エラー",
"field": "payload",
"format": "handlebars",
"template": "<html>\n<head>\n <title>Error: Personality Insights</title>\n\n</head>\n<body>\nPersonality insights requires a minimum of one hundres words.\n</body>\n</html>\n",
"x": 422.08331298828125
}
]