(function () {
"use strict";
var $ = function (id) { return document.getElementById(id); };
var MODES = ["corpus", "eval", "structures", "runs", "compare"];
var MODE_KEY = "phantomWiki100q.mode";
var RECORD_CACHE_LIMIT = 18;
var state = {
manifest: null,
mode: "corpus",
qid: null,
corpus: [],
corpusView: [],
corpusIndex: 0,
docByTitle: {},
eval: [],
evalView: [],
evalIndex: 0,
structuresIndex: null,
structuresView: [],
structuresIndexPosition: 0,
structureCache: new Map(),
runSlot: null,
runViewMode: "result",
runIndexes: {},
runViews: {},
runPositions: {},
runCache: new Map(),
compareIndex: null,
compareView: [],
comparePosition: 0,
compareCache: new Map(),
};
function esc(value) {
return String(value === null || value === undefined ? "" : value)
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """);
}
function short(value, limit) {
value = String(value || "").replace(/\s+/g, " ").trim();
return value.length > limit ? value.slice(0, limit - 1) + "…" : value;
}
function pct(value, digits) {
return (Number(value || 0) * 100).toFixed(digits === undefined ? 2 : digits) + "%";
}
function number(value) {
return typeof value === "number" ? value.toLocaleString() : "—";
}
function money(value) {
return typeof value === "number" ? "$" + value.toFixed(4) : "—";
}
async function fetchJson(path) {
var response = await fetch(path);
if (!response.ok) throw new Error(path + " returned HTTP " + response.status);
return response.json();
}
function cacheGet(cache, key) {
if (!cache.has(key)) return null;
var value = cache.get(key);
cache.delete(key);
cache.set(key, value);
return value;
}
function cacheSet(cache, key, value) {
if (cache.has(key)) cache.delete(key);
cache.set(key, value);
while (cache.size > RECORD_CACHE_LIMIT) {
cache.delete(cache.keys().next().value);
}
}
function field(label, value) {
return '
' + esc(label) +
'
' + value + "
";
}
function statusBadge(status) {
var labels = {
correct: "exact",
partial: "partial",
incorrect: "incorrect",
missing: "missing",
};
return '' +
esc(labels[status] || status) + "";
}
function goldHtml(values, label) {
values = Array.isArray(values) ? values : [values];
values = values.filter(function (value) {
return value !== null && value !== undefined && String(value).trim();
});
var items = values.length ? values.map(function (value) {
value = String(value);
if (Object.prototype.hasOwnProperty.call(state.docByTitle, value)) {
return '' + esc(value) + " ↗";
}
return '' + esc(value) + "";
}).join("") : 'none';
return '' +
esc(label || "Gold") + (values.length > 1 ? " · " + values.length : "") +
'
' + items + "
";
}
function wirePersonLinks(container) {
container.querySelectorAll(".person-link").forEach(function (link) {
link.addEventListener("click", function () {
openPerson(link.dataset.person);
});
});
}
function setSharedQid(qid) {
if (qid) state.qid = String(qid);
}
function sharedIndex(rows) {
if (!state.qid) return -1;
return rows.findIndex(function (row) {
return String(row.id || row.qid) === state.qid;
});
}
function manifestRun(slot) {
return (state.manifest.runs || []).find(function (run) {
return run.slot === slot;
});
}
function runStyle(run) {
return ' style="--run-accent:' + esc(run.accent || "#a78bfa") + '"';
}
function controlsFor(mode) {
return {
corpus: "corpusControls",
eval: "evalControls",
structures: "structureControls",
runs: "runControls",
compare: "compareControls",
}[mode];
}
function viewFor(mode) {
return {
corpus: "corpusView",
eval: "evalView",
structures: "structuresView",
runs: "runsView",
compare: "compareView",
}[mode];
}
async function setMode(mode) {
if (MODES.indexOf(mode) === -1) mode = "corpus";
state.mode = mode;
localStorage.setItem(MODE_KEY, mode);
document.querySelectorAll("#mainTabs button").forEach(function (button) {
button.classList.toggle("active", button.dataset.mode === mode);
});
MODES.forEach(function (candidate) {
$(controlsFor(candidate)).hidden = candidate !== mode;
$(viewFor(candidate)).hidden = candidate !== mode;
});
$("loading").hidden = true;
if (mode === "corpus") renderCorpus();
if (mode === "eval") filterEval();
if (mode === "structures") await loadStructures();
if (mode === "runs") await loadCurrentRun();
if (mode === "compare") await loadCompare();
}
function rebuildSelect(select, rows, position, labeler) {
select.innerHTML = "";
rows.forEach(function (row, index) {
var option = document.createElement("option");
option.value = String(index);
option.textContent = labeler(row);
select.appendChild(option);
});
select.value = String(position || 0);
}
function move(position, delta, length) {
if (!length) return 0;
return Math.max(0, Math.min(length - 1, position + delta));
}
function openPerson(title) {
$("corpusSearch").value = "";
state.corpusView = state.corpus.slice();
state.corpusIndex = state.docByTitle[title] || 0;
rebuildCorpusSelect();
setMode("corpus");
}
function filterCorpus() {
var query = $("corpusSearch").value.trim().toLowerCase();
state.corpusView = state.corpus.filter(function (row) {
return !query || String(row.title).toLowerCase().indexOf(query) >= 0;
});
if (state.corpusIndex >= state.corpusView.length) state.corpusIndex = 0;
rebuildCorpusSelect();
renderCorpus();
}
function rebuildCorpusSelect() {
rebuildSelect(
$("corpusSelect"),
state.corpusView,
state.corpusIndex,
function (row) { return short(row.title, 52); }
);
}
function renderCorpus() {
var host = $("corpusView");
if (!state.corpusView.length) {
host.innerHTML = 'No people match this filter.
';
$("corpusCounter").textContent = "0 / 0";
return;
}
var row = state.corpusView[state.corpusIndex];
$("corpusSelect").value = String(state.corpusIndex);
$("corpusCounter").textContent =
(state.corpusIndex + 1) + " / " + state.corpusView.length;
var article = row.article || "";
var rendered;
try {
rendered = window.marked ? marked.parse(article) : "" + esc(article) + "
";
} catch (error) {
rendered = "" + esc(article) + "
";
}
host.innerHTML = '' +
'
Corpus document
' + esc(row.title) +
'
' + rendered + "
";
host.scrollTop = 0;
}
function evalFacetValues(key) {
return Array.from(new Set(state.eval.map(function (row) {
return String((row.meta || {})[key] || "");
}).filter(Boolean))).sort(function (left, right) {
return Number(left) - Number(right);
});
}
function populateFacet(select, values) {
values.forEach(function (value) {
var option = document.createElement("option");
option.value = value;
option.textContent = value;
select.appendChild(option);
});
}
function filterEval() {
var query = $("evalSearch").value.trim().toLowerCase();
var difficulty = $("evalDifficulty").value;
var type = $("evalType").value;
state.evalView = state.eval.filter(function (row) {
var meta = row.meta || {};
if (difficulty && String(meta.Difficulty) !== difficulty) return false;
if (type && String(meta.Type) !== type) return false;
if (!query) return true;
return [
row.id,
row.question,
(row.answer || []).join(" "),
].join(" ").toLowerCase().indexOf(query) >= 0;
});
var shared = sharedIndex(state.evalView);
if (shared >= 0) state.evalIndex = shared;
else if (state.evalIndex >= state.evalView.length) state.evalIndex = 0;
rebuildSelect(
$("evalSelect"),
state.evalView,
state.evalIndex,
function (row) { return short(row.question, 55); }
);
renderEval();
}
function renderEval() {
var host = $("evalView");
if (!state.evalView.length) {
host.innerHTML = 'No questions match these filters.
';
$("evalCounter").textContent = "0 / 0";
return;
}
var row = state.evalView[state.evalIndex];
var meta = row.meta || {};
setSharedQid(row.id);
$("evalSelect").value = String(state.evalIndex);
$("evalCounter").textContent = (state.evalIndex + 1) + " / " + state.evalView.length;
var support = (row.supporting_titles || []).length
? goldHtml(row.supporting_titles, "Supporting people")
: 'The answer is an attribute value rather than a person document.
';
host.innerHTML = '' +
'
' + esc(row.id) + "" +
'difficulty ' + esc(meta.Difficulty) + "" +
'type ' + esc(meta.Type) + "
" +
"
" + esc(row.question) + "
" +
goldHtml(row.answer || [], "Gold answer") +
field("Question template", '
' + esc(row.template || "—") + "") +
field(
"Ground-truth Prolog chain",
row.prolog && row.prolog.length
? "
" + esc(row.prolog.join("\n")) + ""
: '
No Prolog chain retained.'
) +
field("Supporting documents", support) +
"
";
wirePersonLinks(host);
}
async function loadStructures() {
if (!state.structuresIndex) {
$("structuresView").innerHTML =
'Loading the structures index…
';
state.structuresIndex = await fetchJson(state.manifest.files.structures);
}
filterStructures();
}
function filterStructures() {
var rows = state.structuresIndex.rows || [];
var query = $("structureSearch").value.trim().toLowerCase();
state.structuresView = rows.filter(function (row) {
if (!query) return true;
return [
row.qid,
row.question,
(row.doc_ids || []).join(" "),
(row.source_doc_ids || []).join(" "),
].join(" ").toLowerCase().indexOf(query) >= 0;
});
var shared = sharedIndex(state.structuresView);
if (shared >= 0) state.structuresIndexPosition = shared;
else if (state.structuresIndexPosition >= state.structuresView.length) {
state.structuresIndexPosition = 0;
}
rebuildSelect(
$("structureSelect"),
state.structuresView,
state.structuresIndexPosition,
function (row) { return row.qid.slice(0, 8) + " · " + short(row.question, 48); }
);
renderStructureRecord();
}
async function decodeStructureRecord(item) {
var cached = cacheGet(state.structureCache, item.qid);
if (cached) return cached;
var response = await fetch("data/structures/" + item.path);
if (!response.ok) throw new Error(item.path + " returned HTTP " + response.status);
var encoded = (await response.text()).trim();
var binary = atob(encoded);
var bytes = new Uint8Array(binary.length);
for (var i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
if (typeof DecompressionStream === "undefined") {
throw new Error("This browser does not support gzip structure shards.");
}
var stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream("gzip"));
var record = JSON.parse(await new Response(stream).text());
cacheSet(state.structureCache, item.qid, record);
return record;
}
function structureShapeHtml(shape) {
return '' +
esc(shape.unit_name || shape.shape_id) + '' +
esc(shape.shape_id) + " · " + esc(shape.format || "text") +
'
' +
(shape.unit_description
? '' + esc(shape.unit_description) + "
"
: "") +
"" + esc(shape.content || "(empty artifact)") + "
";
}
function structureDocHtml(doc, position) {
var sourceIds = (doc.source_doc_ids || []).map(function (value) {
return "" + esc(value) + "";
}).join(" ");
return '' + esc(doc.doc_id) + "" +
number(doc.n_structures) + ' structures
' +
'
Source documents: ' + sourceIds + "
" +
'
Supporting text
' +
esc(doc.contents || "") + "" +
((doc.structures || []).map(structureShapeHtml).join("") ||
'
No structures for this document.
') +
"
";
}
async function renderStructureRecord() {
var host = $("structuresView");
if (!state.structuresView.length) {
host.innerHTML = 'No structures match this filter.
';
$("structureCounter").textContent = "0 / 0";
return;
}
var item = state.structuresView[state.structuresIndexPosition];
setSharedQid(item.qid);
$("structureSelect").value = String(state.structuresIndexPosition);
$("structureCounter").textContent =
(state.structuresIndexPosition + 1) + " / " + state.structuresView.length;
host.innerHTML = 'Loading ' + esc(item.qid) + "…
";
try {
var record = await decodeStructureRecord(item);
if (state.mode !== "structures" || state.qid !== record.qid) return;
var meta = state.structuresIndex.meta || {};
host.innerHTML = '' +
'
Structures v3
' +
"
" + esc(record.question) + '
' +
number(record.n_structures) + ' structures' +
'
' + esc(record.qid) + "" +
'' + number(record.n_source_docs) + " source docs" +
'' + number(meta.n_qids) + " matched questions
" +
goldHtml(record.gold_answers || [], "Gold answer") +
"
" +
(record.docs || []).map(structureDocHtml).join("");
wirePersonLinks(host);
} catch (error) {
host.innerHTML = 'Failed to load structures: ' +
esc(error) + "
";
}
}
async function ensureRunIndex(slot) {
if (state.runIndexes[slot]) return state.runIndexes[slot];
var run = manifestRun(slot);
state.runIndexes[slot] = await fetchJson(run.index);
state.runPositions[slot] = state.runPositions[slot] || 0;
return state.runIndexes[slot];
}
async function loadCurrentRun() {
if (!state.runSlot) state.runSlot = state.manifest.runs[0].slot;
$("runSelect").value = state.runSlot;
$("runsView").innerHTML = 'Loading run index…
';
await ensureRunIndex(state.runSlot);
filterRun();
}
function filterRun() {
var slot = state.runSlot;
var index = state.runIndexes[slot];
if (!index) return;
var query = $("runSearch").value.trim().toLowerCase();
var status = $("runStatus").value;
var rows = (index.records || []).filter(function (row) {
if (status && row.status !== status) return false;
if (!query) return true;
return [
row.qid,
row.question,
(row.gold || []).join(" "),
].join(" ").toLowerCase().indexOf(query) >= 0;
});
state.runViews[slot] = rows;
var shared = sharedIndex(rows);
if (shared >= 0) state.runPositions[slot] = shared;
else if (state.runPositions[slot] >= rows.length) state.runPositions[slot] = 0;
rebuildSelect(
$("runQidSelect"),
rows,
state.runPositions[slot],
function (row) { return row.qid.slice(0, 8) + " · " + short(row.question, 46); }
);
renderRunRecord();
}
async function ensureRunRecord(slot, qid, kind) {
var key = slot + "/" + kind + "/" + qid;
var cached = cacheGet(state.runCache, key);
if (cached) return cached;
var run = manifestRun(slot);
var root = kind === "trajectory" ? run.trajectories : run.results;
var record = await fetchJson(root + "/" + qid + ".json");
cacheSet(state.runCache, key, record);
return record;
}
function metric(label, value, note) {
return '' + esc(label) +
'
' + value + '
' +
esc(note || "") + "
";
}
function operationHtml(execution) {
var tokens = execution.tokens || {};
var stop = execution.failure_reason || execution.stop_reason ||
((execution.finish_reasons || []).length
? execution.finish_reasons[execution.finish_reasons.length - 1]
: "—");
return '' +
'
Stop / failure' + esc(stop) + "
" +
'
Agent work' +
number(execution.turns) + " turns · " + number(execution.tool_calls) +
" tool calls
" +
'
Tokens' +
number(tokens.total_tokens) + " total · " + number(tokens.prompt_tokens) +
" prompt · " + number(tokens.completion_tokens) + " completion
" +
'
Latency' +
(typeof execution.latency_ms === "number"
? (execution.latency_ms / 3600000).toFixed(2) + " hours"
: "—") + "
";
}
function provenanceHtml(provenance) {
return field(
"Provenance",
'' +
'
AML job' + esc(provenance.job || "—") +
'
Prompt' +
esc(provenance.prompt || "—") + '
Prompt SHA' +
esc(provenance.rendered_prompt_sha256 || "—") +
'
Model / relation format' +
esc(provenance.model || "—") + " · " + esc(provenance.relation_format || "—") +
"
"
);
}
function runHeaderMetrics(run) {
return '' +
metric("Mean answer F1", pct(run.mean_f1), run.exact + " exact / " + run.total) +
metric("Coverage", pct(run.coverage), run.answered + " answered / " + run.total) +
metric("Cost / question", money(run.cost_per_question_usd), "prediction agent only") +
metric("Prompt", esc(run.prompt || "—"), run.variant || "") +
"
";
}
function resultHtml(run, record) {
var score = record.score || {};
var execution = record.execution || {};
return runHeaderMetrics(run) +
'' +
'
' + esc(record.qid) + "" +
statusBadge(execution.status) +
'F1 ' + pct(score.f1) + "
" +
"
" + esc(record.question) + "
" +
goldHtml(record.gold || [], "Gold answer") +
field(
"Prediction",
record.prediction
? '
' + esc(record.prediction) + "
"
: '
No answer returned · ' +
esc(execution.failure_reason || "unknown failure") + "
"
) +
field(
"Deterministic answer-set score",
'
Precision' +
pct(score.precision) + '
Recall' +
pct(score.recall) + '
F1' +
pct(score.f1) + '
Set overlap' +
number(score.n_hit) + " / " + number(score.n_gold) + " gold
"
) +
operationHtml(execution) +
provenanceHtml(record.provenance || {}) +
"
";
}
function trajectoryHtml(run, record) {
return runHeaderMetrics(run) +
'' +
'
' + esc(record.qid) + "" +
statusBadge((record.execution || {}).status) +
'F1 ' + pct((record.score || {}).f1) + "
" +
"
" + esc(record.question) + "
" +
goldHtml(record.gold || [], "Gold answer") +
field(
"Final prediction",
record.prediction
? '
' + esc(record.prediction) + "
"
: '
No answer returned.'
) +
operationHtml(record.execution || {}) +
provenanceHtml(record.provenance || {}) +
((record.attempt_log || []).length
? '
Attempt log
' +
esc(JSON.stringify(record.attempt_log, null, 2)) + ""
: "") +
window.TrajectoryUI.render(record.events || [], run.label + " trajectory") +
"
";
}
async function renderRunRecord() {
var slot = state.runSlot;
var rows = state.runViews[slot] || [];
var position = state.runPositions[slot] || 0;
var host = $("runsView");
if (!rows.length) {
host.innerHTML = 'No run records match these filters.
';
$("runCounter").textContent = "0 / 0";
return;
}
var summary = rows[position];
var run = manifestRun(slot);
setSharedQid(summary.qid);
$("runQidSelect").value = String(position);
$("runCounter").textContent = (position + 1) + " / " + rows.length;
host.innerHTML = 'Loading ' + esc(summary.qid) + "…
";
try {
var record = await ensureRunRecord(
slot,
summary.qid,
state.runViewMode
);
if (state.mode !== "runs" || state.runSlot !== slot || state.qid !== record.qid) {
return;
}
host.innerHTML = state.runViewMode === "trajectory"
? trajectoryHtml(run, record)
: resultHtml(run, record);
wirePersonLinks(host);
window.TrajectoryUI.bind(host);
} catch (error) {
host.innerHTML = 'Failed to load run record: ' +
esc(error) + "
";
}
}
async function loadCompare() {
if (!state.compareIndex) {
$("compareView").innerHTML =
'Loading comparison index…
';
state.compareIndex = await fetchJson(state.manifest.files.compare);
}
filterCompare();
}
function filterCompare() {
var query = $("compareSearch").value.trim().toLowerCase();
var filter = $("compareFilter").value;
state.compareView = (state.compareIndex.records || []).filter(function (row) {
if (filter === "disagreement" && !row.disagreement) return false;
if (filter === "missing" && !row.any_missing) return false;
if (filter === "perfect" && !Object.values(row.exact || {}).some(Boolean)) return false;
return !query || [row.qid, row.question].join(" ").toLowerCase().indexOf(query) >= 0;
});
var shared = sharedIndex(state.compareView);
if (shared >= 0) state.comparePosition = shared;
else if (state.comparePosition >= state.compareView.length) state.comparePosition = 0;
rebuildSelect(
$("compareSelect"),
state.compareView,
state.comparePosition,
function (row) { return row.qid.slice(0, 8) + " · " + short(row.question, 48); }
);
renderCompareRecord();
}
async function ensureCompareRecord(qid) {
var cached = cacheGet(state.compareCache, qid);
if (cached) return cached;
var record = await fetchJson("data/compare/records/" + qid + ".json");
cacheSet(state.compareCache, qid, record);
return record;
}
function compareScoreHtml(slot, record) {
var run = manifestRun(slot);
return '' +
esc(run.label) + '
' + pct((record.score || {}).f1) +
'' + esc((record.execution || {}).status) + " · " +
number((record.execution || {}).turns) + " turns";
}
function compareRunHtml(slot, record) {
var run = manifestRun(slot);
return '' +
'
' + esc(run.variant || run.family) + "
" +
esc(run.label) + '
' +
statusBadge((record.execution || {}).status) + "
" +
field(
"Prediction",
record.prediction
? '
' + esc(record.prediction) + "
"
: '
No answer returned · ' +
esc((record.execution || {}).failure_reason || "unknown failure") +
""
) +
field(
"Score",
"precision " + pct((record.score || {}).precision) +
" · recall " + pct((record.score || {}).recall) +
" · F1 " + pct((record.score || {}).f1)
) +
operationHtml(record.execution || {}) +
"
";
}
async function renderCompareRecord() {
var host = $("compareView");
if (!state.compareView.length) {
host.innerHTML = 'No comparison rows match this filter.
';
$("compareCounter").textContent = "0 / 0";
return;
}
var summary = state.compareView[state.comparePosition];
setSharedQid(summary.qid);
$("compareSelect").value = String(state.comparePosition);
$("compareCounter").textContent =
(state.comparePosition + 1) + " / " + state.compareView.length;
host.innerHTML = 'Loading comparison ' +
esc(summary.qid) + "…
";
try {
var record = await ensureCompareRecord(summary.qid);
if (state.mode !== "compare" || state.qid !== record.qid) return;
var slots = state.compareIndex.slots || [];
host.innerHTML = '' +
'
' + esc(record.qid) +
'' + slots.length + " runs
" +
"
" + esc(record.question) + "
" +
goldHtml(record.gold || [], "Gold answer") +
"
" +
'' + slots.map(function (slot) {
return compareScoreHtml(slot, record.runs[slot]);
}).join("") + "
" +
slots.map(function (slot) {
return compareRunHtml(slot, record.runs[slot]);
}).join("");
wirePersonLinks(host);
} catch (error) {
host.innerHTML = 'Failed to load comparison: ' +
esc(error) + "
";
}
}
function bindEvents() {
document.querySelectorAll("#mainTabs button").forEach(function (button) {
button.addEventListener("click", function () {
setMode(button.dataset.mode);
});
});
$("corpusSearch").addEventListener("input", filterCorpus);
$("corpusSelect").addEventListener("change", function () {
state.corpusIndex = Number(this.value) || 0;
renderCorpus();
});
$("corpusPrev").addEventListener("click", function () {
state.corpusIndex = move(state.corpusIndex, -1, state.corpusView.length);
renderCorpus();
});
$("corpusNext").addEventListener("click", function () {
state.corpusIndex = move(state.corpusIndex, 1, state.corpusView.length);
renderCorpus();
});
["evalSearch", "evalDifficulty", "evalType"].forEach(function (id) {
$(id).addEventListener(id === "evalSearch" ? "input" : "change", filterEval);
});
$("evalSelect").addEventListener("change", function () {
state.evalIndex = Number(this.value) || 0;
renderEval();
});
$("evalPrev").addEventListener("click", function () {
state.evalIndex = move(state.evalIndex, -1, state.evalView.length);
renderEval();
});
$("evalNext").addEventListener("click", function () {
state.evalIndex = move(state.evalIndex, 1, state.evalView.length);
renderEval();
});
$("structureSearch").addEventListener("input", filterStructures);
$("structureSelect").addEventListener("change", function () {
state.structuresIndexPosition = Number(this.value) || 0;
renderStructureRecord();
});
$("structurePrev").addEventListener("click", function () {
state.structuresIndexPosition = move(
state.structuresIndexPosition, -1, state.structuresView.length
);
renderStructureRecord();
});
$("structureNext").addEventListener("click", function () {
state.structuresIndexPosition = move(
state.structuresIndexPosition, 1, state.structuresView.length
);
renderStructureRecord();
});
$("runSelect").addEventListener("change", async function () {
state.runSlot = this.value;
await loadCurrentRun();
});
document.querySelectorAll("#runSubtabs button").forEach(function (button) {
button.addEventListener("click", function () {
state.runViewMode = button.dataset.runView;
document.querySelectorAll("#runSubtabs button").forEach(function (candidate) {
candidate.classList.toggle("active", candidate === button);
});
renderRunRecord();
});
});
$("runSearch").addEventListener("input", filterRun);
$("runStatus").addEventListener("change", filterRun);
$("runQidSelect").addEventListener("change", function () {
state.runPositions[state.runSlot] = Number(this.value) || 0;
renderRunRecord();
});
$("runPrev").addEventListener("click", function () {
var rows = state.runViews[state.runSlot] || [];
state.runPositions[state.runSlot] = move(
state.runPositions[state.runSlot] || 0, -1, rows.length
);
renderRunRecord();
});
$("runNext").addEventListener("click", function () {
var rows = state.runViews[state.runSlot] || [];
state.runPositions[state.runSlot] = move(
state.runPositions[state.runSlot] || 0, 1, rows.length
);
renderRunRecord();
});
$("compareSearch").addEventListener("input", filterCompare);
$("compareFilter").addEventListener("change", filterCompare);
$("compareSelect").addEventListener("change", function () {
state.comparePosition = Number(this.value) || 0;
renderCompareRecord();
});
$("comparePrev").addEventListener("click", function () {
state.comparePosition = move(
state.comparePosition, -1, state.compareView.length
);
renderCompareRecord();
});
$("compareNext").addEventListener("click", function () {
state.comparePosition = move(
state.comparePosition, 1, state.compareView.length
);
renderCompareRecord();
});
document.addEventListener("keydown", function (event) {
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
var tag = String(event.target.tagName || "").toLowerCase();
if (["input", "select", "textarea"].indexOf(tag) >= 0) return;
var button = {
corpus: event.key === "ArrowLeft" ? "corpusPrev" : "corpusNext",
eval: event.key === "ArrowLeft" ? "evalPrev" : "evalNext",
structures: event.key === "ArrowLeft" ? "structurePrev" : "structureNext",
runs: event.key === "ArrowLeft" ? "runPrev" : "runNext",
compare: event.key === "ArrowLeft" ? "comparePrev" : "compareNext",
}[state.mode];
if (button) $(button).click();
});
}
function populateRunSelect() {
var select = $("runSelect");
select.innerHTML = "";
state.manifest.runs.forEach(function (run) {
var option = document.createElement("option");
option.value = run.slot;
option.textContent = run.label;
select.appendChild(option);
});
state.runSlot = state.manifest.runs[0].slot;
select.value = state.runSlot;
}
function renderScope() {
$("scopeCard").innerHTML =
'' + esc(state.manifest.total_qids) + " matched questions
" +
esc(state.manifest.universe) + "
" +
esc(state.manifest.qid_sha256) + "";
$("sidebarFooter").innerHTML =
esc(state.manifest.corpus_documents) + " corpus documents · " +
esc(state.manifest.runs.length) + " completed runs
" +
"All scores use deterministic normalized answer-set F1.";
}
async function init() {
bindEvents();
try {
state.manifest = await fetchJson("data/manifest.json");
var data = await Promise.all([
fetchJson(state.manifest.files.corpus),
fetchJson(state.manifest.files.eval),
]);
state.corpus = data[0] || [];
state.eval = data[1] || [];
state.corpus.forEach(function (row, index) {
state.docByTitle[row.title] = index;
});
state.corpusView = state.corpus.slice();
state.evalView = state.eval.slice();
rebuildCorpusSelect();
populateFacet($("evalDifficulty"), evalFacetValues("Difficulty"));
populateFacet($("evalType"), evalFacetValues("Type"));
populateRunSelect();
renderScope();
var savedMode = localStorage.getItem(MODE_KEY);
await setMode(MODES.indexOf(savedMode) >= 0 ? savedMode : "corpus");
} catch (error) {
$("loading").hidden = false;
$("loading").textContent = "Failed to initialize viewer: " + error;
}
}
init();
})();