Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -71,7 +71,7 @@ async function render() {
|
|
| 71 |
return;
|
| 72 |
}
|
| 73 |
const question = state.byId[qid];
|
| 74 |
-
$("question-summary").innerHTML = `<h3>${esc(question.question)}</h3><p><strong>Gold answer:</strong> ${esc(question.answer || "No annotated answer")}</p><p>${esc(question.report_year)} annual report
|
| 75 |
$("comparison").innerHTML = Object.entries(METHODS).map(([key, method]) => {
|
| 76 |
const top = state.replay.results[qid][key].top_k;
|
| 77 |
const exact = top.filter(c => goldStatus(question, c).css === "gold");
|
|
@@ -96,7 +96,8 @@ async function renderRanking(question) {
|
|
| 96 |
if (trace.metrics?.length) cues.push(`Metrics: ${trace.metrics.join(", ")}`);
|
| 97 |
const allLabels = [...new Set(result.top_k.flatMap(c => provenance(c.reasons)))];
|
| 98 |
$("route-summary").style.setProperty("--accent", method.color);
|
| 99 |
-
$("route-summary").innerHTML = `<strong>${esc(method.label)}</strong><span>${esc(cues.join("
|
|
|
|
| 100 |
$("ranking").innerHTML = result.top_k.map(candidate => {
|
| 101 |
const obj = corpus[candidate.object_id] || {};
|
| 102 |
const status = goldStatus(question, candidate);
|
|
@@ -105,10 +106,58 @@ async function renderRanking(question) {
|
|
| 105 |
return `<article class="evidence ${status.css}"><div class="rank">#${candidate.rank}</div><div><div class="match">${esc(status.label)}</div><div class="chips">${provenance(candidate.reasons).map(x => `<span class="chip">${esc(x)}</span>`).join("")}</div></div><div class="meta">Page ${esc(candidate.page)}<br>${esc(candidate.type || obj.object_type || "")}</div><div class="preview"><strong>${esc(candidate.object_id)}</strong><p>${esc((obj.text || "Evidence text unavailable").replace(/\s+/g, " ").slice(0, 520))}</p></div><a class="source" href="${esc(link)}" target="_blank" rel="noopener">PDF</a></article>`;
|
| 106 |
}).join("");
|
| 107 |
} catch (error) {
|
|
|
|
| 108 |
$("ranking").innerHTML = `<div class="error">${esc(error.message)}</div>`;
|
| 109 |
}
|
| 110 |
}
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
async function init() {
|
| 113 |
try {
|
| 114 |
const [benchmarkRes, replayRes, sourceRes] = await Promise.all([
|
|
|
|
| 71 |
return;
|
| 72 |
}
|
| 73 |
const question = state.byId[qid];
|
| 74 |
+
$("question-summary").innerHTML = `<h3>${esc(question.question)}</h3><p><strong>Gold answer:</strong> ${esc(question.answer || "No annotated answer")}</p><p>${esc(question.report_year)} annual report 路 ${esc(question.question_type.replaceAll("_", " "))}</p>`;
|
| 75 |
$("comparison").innerHTML = Object.entries(METHODS).map(([key, method]) => {
|
| 76 |
const top = state.replay.results[qid][key].top_k;
|
| 77 |
const exact = top.filter(c => goldStatus(question, c).css === "gold");
|
|
|
|
| 96 |
if (trace.metrics?.length) cues.push(`Metrics: ${trace.metrics.join(", ")}`);
|
| 97 |
const allLabels = [...new Set(result.top_k.flatMap(c => provenance(c.reasons)))];
|
| 98 |
$("route-summary").style.setProperty("--accent", method.color);
|
| 99 |
+
$("route-summary").innerHTML = `<strong>${esc(method.label)}</strong><span>${esc(cues.join(" 路 ") || "Saved ranking without path cues")}</span><div class="chips">${allLabels.map(x => `<span class="chip">${esc(x)}</span>`).join("")}</div>`;
|
| 100 |
+
renderGraph(question, key, result, corpus);
|
| 101 |
$("ranking").innerHTML = result.top_k.map(candidate => {
|
| 102 |
const obj = corpus[candidate.object_id] || {};
|
| 103 |
const status = goldStatus(question, candidate);
|
|
|
|
| 106 |
return `<article class="evidence ${status.css}"><div class="rank">#${candidate.rank}</div><div><div class="match">${esc(status.label)}</div><div class="chips">${provenance(candidate.reasons).map(x => `<span class="chip">${esc(x)}</span>`).join("")}</div></div><div class="meta">Page ${esc(candidate.page)}<br>${esc(candidate.type || obj.object_type || "")}</div><div class="preview"><strong>${esc(candidate.object_id)}</strong><p>${esc((obj.text || "Evidence text unavailable").replace(/\s+/g, " ").slice(0, 520))}</p></div><a class="source" href="${esc(link)}" target="_blank" rel="noopener">PDF</a></article>`;
|
| 107 |
}).join("");
|
| 108 |
} catch (error) {
|
| 109 |
+
$("graph-view").innerHTML = `<div class="error">${esc(error.message)}</div>`;
|
| 110 |
$("ranking").innerHTML = `<div class="error">${esc(error.message)}</div>`;
|
| 111 |
}
|
| 112 |
}
|
| 113 |
|
| 114 |
+
function renderGraph(question, key, result, corpus) {
|
| 115 |
+
const trace = result.trace || {};
|
| 116 |
+
const years = trace.years?.length ? trace.years : [question.report_year];
|
| 117 |
+
const entities = trace.entities || [];
|
| 118 |
+
const metrics = trace.metrics || [];
|
| 119 |
+
const cueNodes = [
|
| 120 |
+
...years.map(year => `<div class="graph-node cue year"><strong>Year</strong><span>${esc(year)}</span></div>`),
|
| 121 |
+
...entities.map(entity => `<div class="graph-node cue entity"><strong>Entity</strong><span>${esc(entity)}</span></div>`),
|
| 122 |
+
...metrics.map(metric => `<div class="graph-node cue metric"><strong>Metric</strong><span>${esc(metric)}</span></div>`)
|
| 123 |
+
].join("");
|
| 124 |
+
|
| 125 |
+
const graphRows = result.top_k.slice(0, 5).map(candidate => {
|
| 126 |
+
const obj = corpus[candidate.object_id] || {};
|
| 127 |
+
const status = goldStatus(question, candidate);
|
| 128 |
+
const reasons = candidate.reasons || [];
|
| 129 |
+
let source = "BM25 + E5";
|
| 130 |
+
let sourceClass = "hybrid";
|
| 131 |
+
let relation = "retrieves";
|
| 132 |
+
let edgeClass = "hybrid";
|
| 133 |
+
if (reasons.some(reason => reason.startsWith("path:same_metric:"))) {
|
| 134 |
+
source = `Metric: ${metrics[0] || "query metric"}`;
|
| 135 |
+
sourceClass = "metric";
|
| 136 |
+
relation = "same-metric";
|
| 137 |
+
edgeClass = "metric";
|
| 138 |
+
} else if (reasons.some(reason => reason.startsWith("path:same_entity:"))) {
|
| 139 |
+
source = `Entity: ${entities[0] || "query entity"}`;
|
| 140 |
+
sourceClass = "entity";
|
| 141 |
+
relation = "same-entity";
|
| 142 |
+
edgeClass = "entity";
|
| 143 |
+
} else if (reasons.some(reason => reason.startsWith("path:same_page:"))) {
|
| 144 |
+
source = "Page-linked object";
|
| 145 |
+
sourceClass = "page";
|
| 146 |
+
relation = "same-page";
|
| 147 |
+
edgeClass = "page";
|
| 148 |
+
} else if (reasons.some(reason => reason.startsWith("source:without_adjacent_page"))) {
|
| 149 |
+
source = "Hybrid seed object";
|
| 150 |
+
sourceClass = "graph";
|
| 151 |
+
relation = "selected-graph expansion";
|
| 152 |
+
edgeClass = "graph";
|
| 153 |
+
}
|
| 154 |
+
const text = (obj.text || candidate.object_id).replace(/\s+/g, " ").slice(0, 115);
|
| 155 |
+
return `<div class="graph-path-row"><div class="graph-source ${sourceClass}">${esc(source)}</div><div class="graph-edge ${edgeClass}"><span>${esc(relation)}</span></div><div class="graph-node evidence-node ${status.css}"><strong>#${candidate.rank} 路 Page ${esc(candidate.page)}</strong><span>${esc(text)}</span></div></div>`;
|
| 156 |
+
}).join("");
|
| 157 |
+
$("graph-view").style.setProperty("--accent", METHODS[key].color);
|
| 158 |
+
$("graph-view").innerHTML = `<div class="graph-root graph-node query"><strong>Question</strong><span>${esc(question.question)}</span></div><div class="graph-down" aria-hidden="true"></div><div class="graph-cues">${cueNodes || `<div class="graph-node cue year"><strong>Year</strong><span>${esc(question.report_year)}</span></div>`}</div><div class="graph-section-label">Active node-to-node routes</div><div class="graph-paths">${graphRows}</div><div class="graph-legend"><span class="legend-line hybrid">Hybrid edge</span><span class="legend-line graph">Graph expansion edge</span><span class="legend-line path">Typed graph edge</span><span>Green node = exact gold 路 Amber node = gold page</span></div>`;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
async function init() {
|
| 162 |
try {
|
| 163 |
const [benchmarkRes, replayRes, sourceRes] = await Promise.all([
|