feat: introduce comparability assessment before contradiction reasoning
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
assessComparability,
|
||||
formulateTieResolutionQuestion,
|
||||
} from "@/lib/graph/question-formulator.js";
|
||||
import { explainUnknownSelection } from "@/lib/graph/utils.js";
|
||||
import { comparabilityAssessmentFixtures } from "@/tests/fixtures/comparability-assessment.js";
|
||||
|
||||
describe("comparability assessment", () => {
|
||||
it("generates comparison questions only when comparability is uncertain", () => {
|
||||
const summary = comparabilityAssessmentFixtures.map((fixture) => {
|
||||
const assessment = assessComparability(fixture.graph);
|
||||
const question = formulateTieResolutionQuestion({ graph: fixture.graph });
|
||||
const ambiguity = explainUnknownSelection(fixture.graph, []);
|
||||
|
||||
expect(assessment.comparabilityStatus).toBe(
|
||||
fixture.expectedComparabilityStatus,
|
||||
);
|
||||
expect(question.comparabilityStatus).toBe(
|
||||
fixture.expectedComparabilityStatus,
|
||||
);
|
||||
|
||||
if (fixture.expectsComparisonQuestion) {
|
||||
expect(question.question.toLowerCase()).toContain("same");
|
||||
expect(question.contradictionReasoningAllowed).toBe(false);
|
||||
} else {
|
||||
expect(question.question.toLowerCase()).not.toContain(
|
||||
"same period and at the same scale",
|
||||
);
|
||||
}
|
||||
|
||||
if (fixture.key !== "sales-same") {
|
||||
expect(ambiguity.status).toBe("ambiguous");
|
||||
}
|
||||
|
||||
return {
|
||||
scenario: fixture.scenario,
|
||||
comparabilityStatus: assessment.comparabilityStatus,
|
||||
contradictionReasoningAllowed: assessment.contradictionReasoningAllowed,
|
||||
question: question.question,
|
||||
};
|
||||
});
|
||||
|
||||
expect(summary).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"comparabilityStatus": "uncertain",
|
||||
"contradictionReasoningAllowed": false,
|
||||
"question": "Were these figures measured on the same basis and at the same scale?",
|
||||
"scenario": "Revenue increased by 18%, but cash in the bank fell over the same period.",
|
||||
},
|
||||
{
|
||||
"comparabilityStatus": "uncertain",
|
||||
"contradictionReasoningAllowed": false,
|
||||
"question": "Were these figures measured over the same period and at the same scale?",
|
||||
"scenario": "Complaints increased. Production increased.",
|
||||
},
|
||||
{
|
||||
"comparabilityStatus": "uncertain",
|
||||
"contradictionReasoningAllowed": false,
|
||||
"question": "Were these figures measured over the same period and at the same scale?",
|
||||
"scenario": "Average delivery time decreased by 25%, but order cancellations increased.",
|
||||
},
|
||||
{
|
||||
"comparabilityStatus": "uncertain",
|
||||
"contradictionReasoningAllowed": false,
|
||||
"question": "Were these figures measured over the same period and at the same scale?",
|
||||
"scenario": "Customer satisfaction increased, but complaints increased.",
|
||||
},
|
||||
{
|
||||
"comparabilityStatus": "confirmed",
|
||||
"contradictionReasoningAllowed": true,
|
||||
"question": "What changed during the period that could explain why Temperature increased. Ice melted?",
|
||||
"scenario": "Temperature increased. Ice melted.",
|
||||
},
|
||||
{
|
||||
"comparabilityStatus": "confirmed",
|
||||
"contradictionReasoningAllowed": false,
|
||||
"question": "What changed during the period that could explain why Sales doubled. Sales doubled?",
|
||||
"scenario": "Sales doubled. Sales doubled.",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
@@ -253,14 +253,18 @@ describe("lib/graph/orchestrator startCase", () => {
|
||||
id: "q_tie_resolution",
|
||||
selectionStatus: "ambiguous",
|
||||
question:
|
||||
"What changed during the period that could explain why Revenue increased by 18%, but cash in the bank fell over the same period?",
|
||||
"Were these figures measured on the same basis and at the same scale?",
|
||||
tiedCandidateIds: expect.arrayContaining([expect.any(String)]),
|
||||
comparabilityStatus: "uncertain",
|
||||
contradictionReasoningAllowed: false,
|
||||
});
|
||||
expect(result.diagnostics.unknownSelectionExplanation).toMatchObject({
|
||||
status: "ambiguous",
|
||||
tieType: "complete_unresolved_tie",
|
||||
selectedNodeId: null,
|
||||
alphabeticalUsedAsReasoning: false,
|
||||
tieResolutionQuestion:
|
||||
"Were these figures measured on the same basis and at the same scale?",
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user