-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
140 lines (126 loc) · 3.69 KB
/
Copy pathapp.js
File metadata and controls
140 lines (126 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { analyzeText } from "./engine/analyzer.js";
import { evaluate } from "./engine/evaluator.js";
const Home = {
template: `
<div class="card">
<h2>感情分析エンジン</h2>
<textarea v-model="text" rows="4" placeholder="テキストを入力..."></textarea>
<button @click="analyze">分析</button>
<div v-if="matchedWords.length" class="stats">
<p>ヒット単語:</p>
<ul>
<li v-for="m in matchedWords" :key="m.word">
{{ m.word }}({{ m.category }} /
{{ m.base }}
<span v-if="m.negated">→ {{ -m.base }} 否定</span>
<span v-if="m.multiplier !== 1">×{{ m.multiplier }}</span>
= {{ m.polarity.toFixed(2) }})
</li>
</ul>
</div>
<div v-if="result" :class="['result', resultClass]">
{{ result }}
</div>
<div class="stats" v-if="result">
スコア: {{ score }} / ヒット: {{ hits }}
</div>
<div class="stats" v-if="debugLabel">
debug: {{ debugLabel }}
</div>
<div v-if="Object.keys(categoryScore).length" class="stats">
<p>カテゴリ別スコア:</p>
<ul>
<li v-for="(value, key) in categoryScore" :key="key">
{{ key }} : {{ value.toFixed(2) }}
</li>
</ul>
</div>
<button @click="runEvaluation">テスト評価</button>
<div v-if="evaluation" class="stats">
<p>📊 評価結果</p>
<ul>
<li>Accuracy: {{ (evaluation.accuracy * 100).toFixed(2) }}%</li>
<li>Precision: {{ (evaluation.precision * 100).toFixed(2) }}%</li>
<li>Recall: {{ (evaluation.recall * 100).toFixed(2) }}%</li>
</ul>
<p>Confusion Matrix</p>
<ul>
<li>TP: {{ evaluation.confusion.tp }}</li>
<li>TN: {{ evaluation.confusion.tn }}</li>
<li>FP: {{ evaluation.confusion.fp }}</li>
<li>FN: {{ evaluation.confusion.fn }}</li>
</ul>
</div>
<div v-if="evaluation" class="stats">
<p>❌ 誤判定({{ evaluation.errorCases.length }}件)</p>
<ul>
<li v-for="(r, i) in evaluation.errorCases.slice(0, 20)" :key="i">
<strong>{{ r.text }}</strong><br>
正解: {{ r.label }} / 予測: {{ r.predicted }}<br>
score: {{ r.normalizedScore.toFixed(2) }} / hits: {{ r.hits }}
</li>
</ul>
<p>⚠️ ヒットなし({{ evaluation.noHitCases.length }}件)</p>
<ul>
<li v-for="(r, i) in evaluation.noHitCases.slice(0, 20)" :key="i">
{{ r.text }}
</li>
</ul>
</div>
</div>
`,
data() {
return {
text: "",
result: "",
score: 0,
hits: 0,
matchedWords: [],
categoryScore: {},
config: null,
evaluation: null,
testset: {},
debugLabel: ""
};
},
computed: {
resultClass() {
if (this.result === "ポジティブ") return "positive";
if (this.result === "ネガティブ") return "negative";
return "neutral";
}
},
async mounted() {
let res = await fetch("./data/config.json");
this.config = await res.json();
res = await fetch("./data/testset.json");
this.testset = await res.json();
},
methods: {
analyze() {
if (!this.config) return;
const r = analyzeText(this.text, this.config);
this.result = r.result;
this.score = r.score;
this.hits = r.hits;
this.matchedWords = r.matchedWords;
this.categoryScore = r.categoryScore;
this.debugLabel = r.debugLabel;
},
runEvaluation() {
if (!this.config || !this.testset.length) return;
this.evaluation = evaluate(this.testset, this.config);
}
}
};
// Router
const routes = [
{ path: "/", component: Home }
];
const router = VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
routes
});
const app = Vue.createApp({});
app.use(router);
app.mount("#app");