Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | 13x 13x 13x 10x 9x 6x 5x 4x 17x 931x 1037x 1037x 1037x 1037x 352x 1037x 239x 1037x 38x 1037x 76x 1037x 138x 1037x 41x 1037x 15x 1037x 1037x 2x 1037x 20x 1037x 4x 1037x 6x 1037x 17x 17x 204x 204x 2856x 2652x 2652x 17x 17x 408x 408x 408x 408x 408x 408x 408x 461x 461x 408x 408x 408x 408x 408x 408x 53x 461x 5x 5x 4x 1x 4x 4x 4x 49x 49x 318x 318x 318x 318x 17x | /**
* @module data-transformers/policy-analysis
* @description Policy domain detection and analysis for parliamentary
* documents. Detects fiscal, defence, environmental, education, healthcare,
* migration, EU, justice, labour, housing, transport, and trade domains
* using keyword matching against Swedish document titles.
*
* Also provides confidence level assessment for intelligence analysis.
*
* @author Hack23 AB
* @license Apache-2.0
*/
/**
* Confidence level for intelligence assessments.
* Reflects the quality and quantity of supporting evidence.
*/
export type ConfidenceLevel = 'HIGH' | 'MEDIUM' | 'LOW';
/**
* Assess the confidence level of an intelligence analysis based on
* the number of corroborating evidence items and the quality of sources.
*
* @param evidenceCount - Number of distinct evidence items supporting the assessment
* @param sourceQuality - Quality score of sources (0-100, higher = better)
* @returns Confidence level classification
*/
export function assessConfidenceLevel(evidenceCount: number, sourceQuality: number): ConfidenceLevel {
const normalizedEvidence = Math.max(0, evidenceCount);
const normalizedQuality = Math.max(0, Math.min(100, sourceQuality));
// HIGH: Multiple evidence items with good-quality sources
if (normalizedEvidence >= 5 && normalizedQuality >= 70) return 'HIGH';
if (normalizedEvidence >= 3 && normalizedQuality >= 85) return 'HIGH';
// LOW: Very few evidence items or very poor source quality
if (normalizedEvidence === 0) return 'LOW';
if (normalizedEvidence <= 1 && normalizedQuality < 50) return 'LOW';
if (normalizedQuality < 30) return 'LOW';
// MEDIUM: everything in between
return 'MEDIUM';
}
import { escapeHtml } from '../html-utils.js';
import type { Language } from '../types/language.js';
import type { RawDocument } from './types.js';
import { COMMITTEE_NAMES } from './constants.js';
import {
L,
svSpan,
cleanMotionText,
isPersonProfileText,
extractKeyPassage,
getCommitteeName,
} from './helpers.js';
// ---------------------------------------------------------------------------
// Per-language domain name translations (12 domains × 14 languages)
// English keys are used internally; localised names are returned to callers.
// ---------------------------------------------------------------------------
type DomainKey = 'fiscal' | 'defence' | 'environment' | 'education' | 'healthcare'
| 'migration' | 'eu-foreign' | 'justice' | 'labour' | 'housing' | 'transport' | 'trade';
const DOMAIN_NAMES: Readonly<Record<DomainKey, Record<string, string>>> = {
fiscal: {
en: 'fiscal policy', sv: 'finanspolitik', da: 'finanspolitik', no: 'finanspolitikk',
fi: 'finanssipolitiikka', de: 'Finanzpolitik', fr: 'politique fiscale',
es: 'política fiscal', nl: 'begrotingsbeleid', ar: 'السياسة المالية',
he: 'מדיניות פיסקלית', ja: '財政政策', ko: '재정 정책', zh: '财政政策',
},
defence: {
en: 'defence and security policy', sv: 'försvars- och säkerhetspolitik',
da: 'forsvars- og sikkerhedspolitik', no: 'forsvars- og sikkerhetspolitikk',
fi: 'puolustus- ja turvallisuuspolitiikka', de: 'Verteidigungs- und Sicherheitspolitik',
fr: 'politique de défense et de sécurité', es: 'política de defensa y seguridad',
nl: 'defensie- en veiligheidsbeleid', ar: 'سياسة الدفاع والأمن',
he: 'מדיניות ביטחון והגנה', ja: '防衛・安全保障政策', ko: '국방·안보 정책', zh: '国防和安全政策',
},
environment: {
en: 'environmental and climate policy', sv: 'miljö- och klimatpolitik',
da: 'miljø- og klimapolitik', no: 'miljø- og klimapolitikk',
fi: 'ympäristö- ja ilmastopolitiikka', de: 'Umwelt- und Klimapolitik',
fr: 'politique environnementale et climatique', es: 'política medioambiental y climática',
nl: 'milieu- en klimaatbeleid', ar: 'سياسة البيئة والمناخ',
he: 'מדיניות סביבה ואקלים', ja: '環境・気候政策', ko: '환경·기후 정책', zh: '环境和气候政策',
},
education: {
en: 'education policy', sv: 'utbildningspolitik', da: 'uddannelsespolitik',
no: 'utdanningspolitikk', fi: 'koulutuspolitiikka', de: 'Bildungspolitik',
fr: 'politique éducative', es: 'política educativa', nl: 'onderwijsbeleid',
ar: 'سياسة التعليم', he: 'מדיניות חינוך', ja: '教育政策', ko: '교육 정책', zh: '教育政策',
},
healthcare: {
en: 'healthcare policy', sv: 'hälso- och sjukvårdspolitik',
da: 'sundhedspolitik', no: 'helsepolitikk', fi: 'terveyspolitiikka',
de: 'Gesundheitspolitik', fr: 'politique de santé', es: 'política sanitaria',
nl: 'gezondheidsbeleid', ar: 'سياسة الرعاية الصحية', he: 'מדיניות בריאות',
ja: '医療政策', ko: '보건 정책', zh: '医疗政策',
},
migration: {
en: 'migration policy', sv: 'migrationspolitik', da: 'migrationspolitik',
no: 'migrasjonspolitikk', fi: 'maahanmuuttopolitiikka', de: 'Migrationspolitik',
fr: 'politique migratoire', es: 'política migratoria', nl: 'migratiebeleid',
ar: 'سياسة الهجرة', he: 'מדיניות הגירה', ja: '移民政策', ko: '이민 정책', zh: '移民政策',
},
'eu-foreign': {
en: 'EU and foreign affairs', sv: 'EU- och utrikespolitik',
da: 'EU- og udenrigspolitik', no: 'EU- og utenrikspolitikk',
fi: 'EU- ja ulkopolitiikka', de: 'EU- und Außenpolitik',
fr: 'affaires européennes et étrangères', es: 'asuntos europeos y exteriores',
nl: 'EU- en buitenlands beleid', ar: 'شؤون الاتحاد الأوروبي والخارجية',
he: 'יחסי חוץ ואיחוד אירופי', ja: 'EU・外交政策', ko: 'EU·외교 정책', zh: '欧盟和外交事务',
},
justice: {
en: 'justice policy', sv: 'rättspolitik', da: 'retspolitik',
no: 'justispolitikk', fi: 'oikeuspolitiikka', de: 'Justizpolitik',
fr: 'politique judiciaire', es: 'política judicial', nl: 'justitiebeleid',
ar: 'سياسة العدالة', he: 'מדיניות משפט', ja: '司法政策', ko: '사법 정책', zh: '司法政策',
},
labour: {
en: 'labour market policy', sv: 'arbetsmarknadspolitik',
da: 'arbejdsmarkedspolitik', no: 'arbeidsmarkedspolitikk',
fi: 'työmarkkinapolitiikka', de: 'Arbeitsmarktpolitik',
fr: 'politique du marché du travail', es: 'política del mercado laboral',
nl: 'arbeidsmarktbeleid', ar: 'سياسة سوق العمل', he: 'מדיניות שוק העבודה',
ja: '労働市場政策', ko: '노동시장 정책', zh: '劳动市场政策',
},
housing: {
en: 'housing policy', sv: 'bostadspolitik', da: 'boligpolitik',
no: 'boligpolitikk', fi: 'asuntopolitiikka', de: 'Wohnungspolitik',
fr: 'politique du logement', es: 'política de vivienda', nl: 'woningbeleid',
ar: 'سياسة الإسكان', he: 'מדיניות דיור', ja: '住宅政策', ko: '주택 정책', zh: '住房政策',
},
transport: {
en: 'transport policy', sv: 'transportpolitik', da: 'transportpolitik',
no: 'transportpolitikk', fi: 'liikennepolitiikka', de: 'Verkehrspolitik',
fr: 'politique des transports', es: 'política de transporte', nl: 'vervoersbeleid',
ar: 'سياسة النقل', he: 'מדיניות תחבורה', ja: '交通政策', ko: '교통 정책', zh: '交通政策',
},
trade: {
en: 'trade and industry policy', sv: 'näringspolitik',
da: 'erhvervspolitik', no: 'næringspolitikk', fi: 'elinkeino- ja kauppapolitiikka',
de: 'Wirtschafts- und Handelspolitik', fr: 'politique commerciale et industrielle',
es: 'política comercial e industrial', nl: 'handels- en industriebeleid',
ar: 'سياسة التجارة والصناعة', he: 'מדיניות מסחר ותעשייה',
ja: '通商・産業政策', ko: '통상·산업 정책', zh: '贸易和产业政策',
},
};
/** Resolve a localised domain name from a domain key and language. */
function domainName(key: DomainKey, lang: Language | string): string {
return DOMAIN_NAMES[key][lang] ?? DOMAIN_NAMES[key].en;
}
/**
* Detect policy domains from a document's title and committee code.
* Returns a deduplicated array of localised domain strings.
*/
export function detectPolicyDomains(doc: RawDocument, lang: Language | string = 'en'): string[] {
const title = (doc.titel || doc.title || '').toLowerCase();
const organ = doc.organ || doc.committee || '';
const set = new Set<string>();
if (title.includes('skatt') || title.includes('tax') || title.includes('budget') || title.includes('finans')
|| title.includes('makrotillsyn') || title.includes('macroprudential')
|| title.includes('moms') || title.includes('mervärd') || title.includes('skattebedrägeri')
|| title.includes('e-id') || title.includes('e-legitimation') || title.includes('verklig huvudman')
|| title.includes('penningtvätt') || /\bbeneficial owner(ship)?\b/.test(title) || title.includes('fakturabedrägeri')
|| organ === 'SkU' || organ === 'FiU')
set.add(domainName('fiscal', lang));
if (title.includes('försvar') || title.includes('defen') || title.includes('militär') || title.includes('nato')
|| title.includes('vapen') || title.includes('beredskap') || title.includes('totalförsvar')
|| title.includes('krigsmateriel') || title.includes('säkerhetsskydd') || title.includes('preparedness')
|| title.includes('weapon')
|| organ === 'FöU')
set.add(domainName('defence', lang));
if (title.includes('miljö') || title.includes('klimat') || title.includes('environ') || title.includes('energi')
|| title.includes('förnybart') || title.includes('renewable') || title.includes('koldioxid')
|| title.includes('hållbar') || title.includes('sustain')
|| organ === 'MJU')
set.add(domainName('environment', lang));
if (title.includes('utbildning') || title.includes('educ') || title.includes('skola') || title.includes('högskola')
|| organ === 'UbU')
set.add(domainName('education', lang));
if (title.includes('vård') || title.includes('hälsa') || title.includes('health') || title.includes('omsorg')
|| organ === 'SoU')
set.add(domainName('healthcare', lang));
if (title.includes('migration') || title.includes('invandring') || title.includes('asyl') || title.includes('utlänning')
|| title.includes('uppehållstillstånd') || title.includes('medborgarskap') || title.includes('citizenship')
|| title.includes('utvisning') || title.includes('statslöshet')
|| organ === 'SfU')
set.add(domainName('migration', lang));
if (/\beu\b/.test(title) || title.includes('europa') || title.includes('utrik') || title.includes('foreign')
|| organ === 'UU')
set.add(domainName('eu-foreign', lang));
Iif (title.includes('brott') || title.includes('straff') || title.includes('polis') || title.includes('justice')
|| title.includes('kriminal') || organ === 'JuU')
set.add(domainName('justice', lang));
if (title.includes('arbetsmarknad') || title.includes('labour') || title.includes('anställning')
|| title.includes('facklig') || /\bilo\b/.test(title) || title.includes('trakasserier')
|| title.includes('kollektivavtal') || title.includes('lönediskriminering') || title.includes('harassment')
|| organ === 'AU')
set.add(domainName('labour', lang));
if (title.includes('bostad') || title.includes('housing') || title.includes('hyra') || title.includes('bostadsrätt')
|| title.includes('lagfart') || title.includes('fastighet')
|| organ === 'CU')
set.add(domainName('housing', lang));
if (title.includes('trafik') || title.includes('transport') || title.includes('järnväg') || title.includes('väg')
|| organ === 'TU')
set.add(domainName('transport', lang));
if (title.includes('näring') || title.includes('handel') || title.includes('trade') || title.includes('industri')
|| title.includes('företag') || title.includes('jordbruk') || title.includes('lantbruk')
|| title.includes('veterinär') || title.includes('djur') || organ === 'NU')
set.add(domainName('trade', lang));
return Array.from(set);
}
/**
* Dominant political narrative frames detected in document titles.
* These represent recurring rhetorical frames used across parties.
*/
export type NarrativeFrame =
| 'law-and-order'
| 'welfare-state-defence'
| 'fiscal-responsibility'
| 'green-transition'
| 'national-security'
| 'integration-challenge'
| 'eu-sovereignty'
| 'workers-rights';
/**
* Detect dominant narrative frames in a document title.
* Narrative framing reveals which rhetorical strategies are being employed
* regardless of the specific policy domain.
*
* @param doc - Document to analyse
* @returns Array of detected narrative frames (deduplicated)
*/
export function detectNarrativeFrames(doc: RawDocument): NarrativeFrame[] {
const title = (doc.titel || doc.title || '').toLowerCase();
const frames = new Set<NarrativeFrame>();
// Law-and-order: crime, punishment, police
if (title.includes('brott') || title.includes('straff') || title.includes('polis') ||
title.includes('kriminal') || title.includes('gäng') || /\bsäker(het)?\b/.test(title))
frames.add('law-and-order');
// Welfare-state defence: healthcare, social services, welfare
if (title.includes('välfärd') || title.includes('omsorg') || title.includes('social') ||
title.includes('pension') || title.includes('bidrag') || title.includes('trygghet'))
frames.add('welfare-state-defence');
// Fiscal responsibility: budgets, debt, taxes
if (title.includes('budget') || title.includes('skuld') || title.includes('bespar') ||
title.includes('effektiv') || title.includes('kostnad') || title.includes('överskott'))
frames.add('fiscal-responsibility');
// Green transition: climate, environment, energy
if (title.includes('klimat') || title.includes('hållbar') || title.includes('grön') ||
title.includes('utsläpp') || title.includes('förnybar') || title.includes('energiomstäl'))
frames.add('green-transition');
// National security: defence, preparedness, NATO
if (title.includes('försvar') || title.includes('nato') || title.includes('beredskap') ||
title.includes('totalförsvar') || title.includes('säkerhetsskydd'))
frames.add('national-security');
// Integration challenge: migration, asylum, citizenship
if (title.includes('integration') || title.includes('integrera') || title.includes('migration') || title.includes('invandring') ||
title.includes('asyl') || title.includes('utvisning'))
frames.add('integration-challenge');
// EU sovereignty: EU, European, sovereignty
if (/\beu\b/.test(title) || title.includes('europa') || title.includes('suveränitet') ||
title.includes('direktiv') || title.includes('förordning'))
frames.add('eu-sovereignty');
// Workers' rights: labour, unions, wages
if (title.includes('facklig') || title.includes('lön') || title.includes('arbetsrätt') ||
title.includes('kollektivavtal') || title.includes('strejk'))
frames.add('workers-rights');
return Array.from(frames);
}
type _LangPair = { en: Record<string, string>; sv: Record<string, string> };
/**
* Build a reverse lookup from any localised domain name back to the English key.
* This allows getDomainSpecificAnalysis to work with the localised strings
* returned by detectPolicyDomains().
*/
const _LOCALISED_TO_EN: Record<string, string> = {};
for (const [, translations] of Object.entries(DOMAIN_NAMES)) {
const enName = translations.en;
for (const [langKey, localisedName] of Object.entries(translations)) {
// Skip the English entry — it maps to itself and adds no new lookup value
if (langKey === 'en') continue;
_LOCALISED_TO_EN[localisedName] = enName;
_LOCALISED_TO_EN[localisedName.toLowerCase()] = enName;
}
}
/** Module-level constant — allocated once, shared across all calls. */
const DOMAIN_ANALYSES: Record<string, _LangPair> = {
'fiscal policy': {
en: {
mot: 'Fiscal policy motions directly challenge the government\'s budget assumptions and signal opposition readiness to contest tax and spending priorities.',
bet: 'The Finance Committee\'s position on fiscal matters is usually decisive — the chamber almost always follows its recommendation on budgetary questions.',
default: 'Government fiscal proposals must clear rigorous Finance Committee scrutiny and align with Sweden\'s fiscal surplus rule, making the committee\'s verdict pivotal.'
},
sv: {
mot: 'Finanspolitiska motioner utmanar direkt regeringens budgetantaganden och signalerar oppositionens beredskap att bestrida skatte- och utgiftsprioriteringar.',
bet: 'Finansutskottets ståndpunkt i finanspolitiska frågor är i regel avgörande – kammaren följer nästan alltid utskottets rekommendation.',
default: 'Regeringens finanspolitiska förslag måste klara finansutskottets granskning och harmonisera med överskottsmålet för att nå bifall.'
}
},
'defence and security policy': {
en: {
mot: 'Defence motions carry heightened strategic significance following Sweden\'s NATO accession, pressing the government on long-term security commitments.',
bet: 'Committee reports on defence shape Sweden\'s military posture and NATO integration trajectory — decisions here have multi-decade consequences.',
default: 'Defence proposals engage Sweden\'s NATO obligations and cross-party consensus-building mechanisms for national security legislation.'
},
sv: {
mot: 'Försvarsrelaterade motioner har förhöjd strategisk betydelse efter Sveriges NATO-inträde och pressar regeringen om långsiktiga säkerhetsåtaganden.',
bet: 'Utskottsbetänkanden om försvar formar Sveriges militära inriktning och NATO-integration – besluten har konsekvenser i decennier.',
default: 'Försvarspropositioner engagerar Sveriges NATO-förpliktelser och mekanismer för brett partistöd inom säkerhetspolitiken.'
}
},
'environmental and climate policy': {
en: {
mot: 'Climate motions reflect growing parliamentary pressure for faster decarbonisation, often targeting specific industries or the pace of policy implementation.',
bet: 'The Environment Committee\'s recommendations balance climate ambition against economic competitiveness — its position sets the legislative baseline.',
default: 'Environmental proposals must navigate competing interests from industry, regional governments, and EU climate commitments, making parliamentary support critical.'
},
sv: {
mot: 'Klimatmotioner speglar växande parlamentariskt tryck för snabbare koldioxidminskning och riktar sig ofta mot specifika branscher.',
bet: 'Miljöutskottet väger klimatambition mot ekonomisk konkurrenskraft – dess rekommendation sätter lagstiftningens utgångspunkt.',
default: 'Miljöförslag måste navigera konkurrerande intressen från industrin, regionerna och EU:s klimatåtaganden.'
}
},
'healthcare policy': {
en: {
mot: 'Healthcare motions typically target gaps in regional service delivery, pressing for national minimum standards, additional funding, or new patient rights.',
bet: 'Social Affairs Committee reports on healthcare set the framework for Sweden\'s regionally delivered but nationally financed health system.',
default: 'Healthcare proposals require coordination between national government, regional councils, and professional bodies — a complexity that shapes the legislative timeline.'
},
sv: {
mot: 'Hälso- och sjukvårdsmotioner riktar sig typiskt mot brister i regionala tjänster och driver på för nationella miniminivåer eller nya patienträttigheter.',
bet: 'Socialutskottets betänkanden om hälso- och sjukvård sätter ramarna för det regionalt levererade men nationellt finansierade hälsosystemet.',
default: 'Hälso- och sjukvårdspropositioner kräver samordning mellan stat, regioner och professioner – en komplexitet som formar lagstiftningens tidslinje.'
}
},
'migration policy': {
en: {
mot: 'Migration motions reflect one of Sweden\'s most contested policy areas, with parties divided on asylum rules, integration requirements, and deportation procedures.',
bet: 'The Social Insurance Committee\'s migration reports navigate Sweden\'s EU law obligations and UN Refugee Convention commitments alongside domestic political pressures.',
default: 'Migration proposals must balance EU regulatory obligations with national political imperatives, making cross-party support essential for durable legislation.'
},
sv: {
mot: 'Migrationsmotioner speglar ett av Sveriges mest omtvistade politikområden, med partier delade om asylregler, integrationskrav och återvändanderutiner.',
bet: 'Socialförsäkringsutskottets migrationsbetänkanden navigerar Sveriges åtaganden enligt EU-rätten och FN:s flyktingkonvention.',
default: 'Migrationspropositioner måste balansera EU-rättsliga förpliktelser med nationella politiska imperativ.'
}
},
'EU and foreign affairs': {
en: {
mot: 'EU and foreign affairs motions signal parliamentary expectations for government negotiating positions — influential despite executive prerogative in external relations.',
bet: 'The Foreign Affairs Committee\'s reports on EU matters reflect Sweden\'s positioning within the bloc and may bind future negotiating postures.',
default: 'EU and foreign affairs proposals engage Sweden\'s treaty obligations and often require coordination with European partners before domestic enactment.'
},
sv: {
mot: 'EU- och utrikespolitiska motioner signalerar parlamentets förväntningar på regeringens förhandlingspositioner.',
bet: 'Utrikesutskottets betänkanden om EU-frågor speglar Sveriges positionering inom unionen och kan binda framtida förhandlingslinjer.',
default: 'EU- och utrikespropositioner engagerar Sveriges fördragsförpliktelser och kräver samordning med europeiska partner.'
}
},
'justice policy': {
en: {
mot: 'Justice motions address crime, sentencing, and policing — areas with high public salience where opposition parties frequently press for tougher or more targeted measures.',
bet: 'The Justice Committee shapes the criminal law framework; its reports on sentencing and policing directly affect prosecution practice and enforcement priorities.',
default: 'Justice proposals balance rule-of-law principles, human rights obligations, and public safety demands — requiring careful drafting to withstand constitutional scrutiny.'
},
sv: {
mot: 'Rättsliga motioner rör brott, straff och polis – frågor med hög allmän relevans där oppositionen ofta driver på för hårdare åtgärder.',
bet: 'Justitieutskottet formar den straffrättsliga ramen; dess betänkanden om straffsatser och polisverksamhet påverkar direkt åklagarnas praxis.',
default: 'Rättsliga propositioner balanserar rättsstatsprinciper, mänskliga rättigheter och allmän säkerhet.'
}
},
'labour market policy': {
en: {
mot: 'Labour market motions engage sensitive negotiations between employers, unions, and the state — every motion sends a signal to Sweden\'s social partners.',
bet: 'The Labour Committee\'s reports on workplace legislation must navigate collective bargaining autonomy while setting minimum statutory floors.',
default: 'Labour market proposals enter an arena where tripartite negotiation shapes the final legislative outcome as much as parliamentary votes.'
},
sv: {
mot: 'Arbetsmarknadsmotioner engagerar känsliga förhandlingar mellan arbetsgivare, fackförbund och stat – varje motion signalerar till parterna.',
bet: 'Arbetsmarknadsutskottets betänkanden om arbetsplatslagar måste navigera kollektivavtalens självständighet.',
default: 'Arbetsmarknadspropositioner träder in i en arena där trepartsförhandlingar formar det slutliga lagstiftningsresultatet.'
}
},
'housing policy': {
en: {
mot: 'Housing motions reflect structural tension between demand for affordable homes and constraints of planning law, rent regulation, and construction cost pressures.',
bet: 'The Civil Affairs Committee\'s housing reports address one of Sweden\'s most persistent policy challenges, where committee decisions unlock or block major regulatory change.',
default: 'Housing proposals must reconcile competing interests from municipalities, property owners, tenants, and developers — a coalition rarely achieved quickly.'
},
sv: {
mot: 'Bostadsmotioner speglar strukturell spänning mellan efterfrågan på prisvärda bostäder och begränsningarna i plan- och hyreslagstiftning.',
bet: 'Civilutskottets bostadsbetänkanden hanterar en av Sveriges mest ihållande politiska utmaningar.',
default: 'Bostadspropositioner måste balansera konkurrerande intressen från kommuner, fastighetsägare, hyresgäster och byggföretag.'
}
},
'transport policy': {
en: {
mot: 'Transport motions address infrastructure investment, road safety, and public transit — areas where regional and national interests frequently diverge.',
bet: 'The Transport Committee\'s reports guide Sweden\'s national infrastructure planning cycle, directly affecting long-term investment priorities.',
default: 'Transport proposals engage the national infrastructure budget, regional equity, and climate transition targets — all must be balanced in committee deliberation.'
},
sv: {
mot: 'Transportmotioner rör infrastrukturinvesteringar, trafiksäkerhet och kollektivtrafik – frågor där regionala och nationella intressen ofta divergerar.',
bet: 'Trafikutskottets betänkanden vägleder Sveriges nationella infrastrukturplanering och påverkar direkt långsiktiga investeringsprioriteringar.',
default: 'Transportpropositioner engagerar den nationella infrastrukturbudgeten, regional jämlikhet och klimatomställningsmål.'
}
},
'trade and industry policy': {
en: {
mot: 'Industry and trade motions often target competitiveness, innovation, or trade agreements — signalling party positions ahead of EU-level or bilateral negotiations.',
bet: 'The Committee on Industry and Trade shapes Sweden\'s business environment through reports that set conditions for investment, innovation, and exports.',
default: 'Industry and trade proposals engage international commitments, EU single-market rules, and domestic competitiveness imperatives simultaneously.'
},
sv: {
mot: 'Näringspolitiska motioner riktar sig ofta mot konkurrenskraft, innovation eller handelsavtal och signalerar partipositioner inför förhandlingar.',
bet: 'Näringsutskottets betänkanden formar Sveriges affärsmiljö och sätter villkoren för investeringar och export.',
default: 'Näringspolitiska propositioner engagerar internationella åtaganden, EU:s inre marknadsregler och inhemsk konkurrenskraft.'
}
},
'education policy': {
en: {
mot: 'Education motions reflect deep disagreements on school standards, teacher pay, and the role of independent schools — one of Sweden\'s most contested domestic debates.',
bet: 'The Education Committee\'s reports directly shape curriculum standards, funding formulas, and school regulation — decisions with long generational consequences.',
default: 'Education proposals must balance national curriculum standards with municipal delivery autonomy and the contested role of private providers in the Swedish school system.'
},
sv: {
mot: 'Utbildningsmotioner speglar djupa meningsskiljaktigheter om skolstandard, lärarlöner och friskolornas roll.',
bet: 'Utbildningsutskottets betänkanden formar direkt läroplaner, finansieringsmodeller och skolreglering.',
default: 'Utbildningspropositioner måste balansera nationella läroplaner med kommunalt leveransansvar och de privata aktörernas omstridda roll.'
}
}
};
/** Module-level constant — reverse lookup from any localised domain name to English key. */
const EN_DOMAIN_MAP: Record<string, string> = _LOCALISED_TO_EN;
/**
* Return a substantive domain-specific and type-specific analysis sentence.
* Each of 12 policy domains has tailored text for motions (mot), committee
* reports (bet), and propositions/default, in both English and Swedish.
*/
export function getDomainSpecificAnalysis(primaryDomain: string, doktyp: string, lang: Language | string): string {
const isSv = lang === 'sv';
const lookupKey = EN_DOMAIN_MAP[primaryDomain] ?? primaryDomain;
const entry = DOMAIN_ANALYSES[lookupKey];
Iif (!entry) return '';
const langEntry = isSv ? entry.sv : entry.en;
const typeKey = (doktyp === 'mot' || doktyp === 'bet') ? doktyp : 'default';
return langEntry[typeKey] ?? langEntry['default'] ?? '';
}
/**
* Generate policy significance context for a document based on its metadata.
* Uses the localised policySignificanceTouches label plus a domain-specific
* analysis sentence instead of generic boilerplate.
* Falls back to a committee-specific sentence (derived from COMMITTEE_NAMES)
* when no domain keyword matches but the document's organ field identifies a
* known Riksdag committee.
* @param impliedDoktyp - document type inferred from the calling context
* ('mot', 'bet', 'prop') when doc.doktyp / doc.documentType is absent.
*/
export function generatePolicySignificance(doc: RawDocument, lang: Language | string, impliedDoktyp?: string): string {
const domains = detectPolicyDomains(doc, lang);
if (domains.length > 0) {
const domainsStr = domains.join(', ');
const touchesFn = L(lang, 'policySignificanceTouches') as string | ((d: string) => string);
const baseText = typeof touchesFn === 'function'
? touchesFn(escapeHtml(domainsStr))
: `Touches on ${escapeHtml(domainsStr)}.`;
const doktyp = doc.doktyp || doc.documentType || impliedDoktyp || '';
const deepAnalysis = getDomainSpecificAnalysis(domains[0] ?? '', doktyp, lang);
return deepAnalysis ? `${baseText} ${deepAnalysis}` : baseText;
}
// Secondary: committee-specific context when organ is present but no domain matched
const organ = doc.organ || doc.committee || '';
if (organ) {
const organEntry = COMMITTEE_NAMES[organ];
if (organEntry) {
const committeeRefTemplates: Record<string, (name: string) => string> = {
sv: (n) => `Ärendet behandlas av ${n.toLowerCase()} för parlamentarisk beredning.`,
da: (n) => `Sagen behandles af ${n} til parlamentarisk behandling.`,
no: (n) => `Saken behandles av ${n} for parlamentarisk behandling.`,
fi: (n) => `Asia käsitellään valiokunnassa ${n} parlamentaarista käsittelyä varten.`,
de: (n) => `Die Angelegenheit wird dem ${n} zur parlamentarischen Prüfung überwiesen.`,
fr: (n) => `L'affaire est renvoyée à la ${n} pour examen parlementaire.`,
es: (n) => `El asunto se remite a la ${n} para examen parlamentario.`,
nl: (n) => `De zaak wordt verwezen naar de ${n} voor parlementaire behandeling.`,
ar: (n) => `تم إحالة الموضوع إلى ${n} للنظر البرلماني.`,
he: (n) => `הנושא הועבר ל${n} לבחינה פרלמנטרית.`,
ja: (n) => `この件は${n}に付託され、議会審議が行われます。`,
ko: (n) => `이 안건은 ${n}에 회부되어 의회 심의를 받습니다.`,
zh: (n) => `此事项已移交${n}进行议会审查。`,
};
// Use getCommitteeName for consistent localization: Swedish name for sv,
// English name for all others (client-side data-translate handles further l10n)
const committeeName = getCommitteeName(organ, lang);
const tpl = committeeRefTemplates[lang as string];
return tpl
? tpl(committeeName)
: `This matter is referred to the ${organEntry.en} for parliamentary examination.`;
}
}
// Generic significance when no domain detected and no known committee
const genericVal = L(lang, 'policySignificanceGeneric');
return typeof genericVal === 'string' ? genericVal : 'Requires committee review and chamber debate before a decision is reached.';
}
/**
* Generate deep policy analysis for a single document entry.
* Only uses `fullText` / `fullContent` (enriched content fetched separately)
* as the passage source — summary/notis are already shown in the summary line
* above in structured views and must not be duplicated here.
* Falls back to generatePolicySignificance when no enriched text is available.
* @param impliedDoktyp - document type inferred from the calling context
* ('mot', 'bet', 'prop') when doc.doktyp / doc.documentType is absent.
*/
export function generateDeepPolicyAnalysis(doc: RawDocument, lang: Language | string, impliedDoktyp?: string): string {
const effectiveDoktyp = doc.doktyp || doc.documentType || impliedDoktyp || '';
const rawText = doc.fullText || doc.fullContent || '';
Iif (rawText && !isPersonProfileText(rawText)) {
const cleanedText = (effectiveDoktyp === 'mot' && rawText.includes('Motion till riksdagen'))
? cleanMotionText(rawText)
: rawText;
const passage = extractKeyPassage(cleanedText, 300);
if (passage) {
const isSwedishSource = !!(doc.titel && !doc.title);
const passageHtml = isSwedishSource
? svSpan(escapeHtml(passage), lang)
: escapeHtml(passage);
return `${passageHtml} ${generatePolicySignificance(doc, lang, impliedDoktyp)}`;
}
}
return generatePolicySignificance(doc, lang, impliedDoktyp);
}
// ---------------------------------------------------------------------------
// SCB (Statistics Sweden) table mapping for policy domains
// ---------------------------------------------------------------------------
/**
* Maps policy domain keys to relevant SCB table IDs and search queries
* for enriching political analysis with official statistics.
*
* Each entry contains:
* - `query` — Swedish-language search terms for `search_tables()` SCB MCP tool
* - `tables` — Known SCB table IDs (e.g. "TAB5765" for unemployment) for `get_table_data()`
* - `indicators` — Human-readable indicator names expected from the tables
*
* SCB MCP tools: search_tables, get_table_data, get_table_variables, preview_data, find_region_code
* Source: https://scb-mcp.onrender.com/mcp (PxWebAPI 2.0)
*/
export const SCB_DOMAIN_TABLES: Readonly<Record<DomainKey, { query: string; tables: string[]; indicators: string[] }>> = {
fiscal: {
query: 'skatter statsbudget offentliga finanser',
tables: ['TAB1291', 'TAB1292'],
indicators: ['Government revenue', 'Government expenditure', 'Budget balance'],
},
defence: {
query: 'försvar militär offentliga utgifter',
tables: [],
indicators: ['Defence spending as % of GDP'],
},
environment: {
query: 'växthusgaser utsläpp miljö',
tables: ['TAB5404', 'TAB5407'],
indicators: ['GHG emissions (kt CO₂e)', 'Renewable energy share'],
},
education: {
query: 'utbildning studenter skola',
tables: ['TAB4787', 'TAB4790'],
indicators: ['Student enrollment', 'Graduation rates', 'Education spending'],
},
healthcare: {
query: 'hälsa sjukvård vård',
tables: [],
indicators: ['Healthcare spending', 'Hospital beds per capita'],
},
migration: {
query: 'invandring utvandring migration befolkning',
tables: ['TAB637', 'TAB4230'],
indicators: ['Immigration', 'Emigration', 'Net migration'],
},
'eu-foreign': {
query: 'utrikeshandel export import',
tables: ['TAB2661'],
indicators: ['Export value', 'Import value', 'Trade balance'],
},
justice: {
query: 'brott lagföringar kriminalstatistik',
tables: ['TAB1172'],
indicators: ['Reported crimes', 'Conviction rate'],
},
labour: {
query: 'sysselsättning arbetslöshet arbetsmarknad',
tables: ['TAB5765', 'TAB5616'],
indicators: ['Unemployment rate', 'Employment rate', 'Labour force participation'],
},
housing: {
query: 'bostäder nybyggnation hyror',
tables: ['TAB2052', 'TAB4709'],
indicators: ['Housing starts', 'Housing prices index'],
},
transport: {
query: 'trafik transport infrastruktur',
tables: [],
indicators: ['Road traffic volume', 'Public transport ridership'],
},
trade: {
query: 'näringsliv företag BNP',
tables: ['TAB5802', 'TAB5803'],
indicators: ['GDP growth', 'Business starts', 'Industrial production index'],
},
};
|