ezmedicationinput 0.1.56 → 0.1.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,8 @@ export type HpsgType = "sign" | "word-sign" | "phrase-sign" | "headed-phrase" |
5
5
  export interface HpsgEvidence {
6
6
  rule: string;
7
7
  tokenIndices: number[];
8
+ /** Lexical evidence that a schedule field is an inferred, construction-local default. */
9
+ scheduleDefault?: "daily-frequency";
8
10
  }
9
11
  export type HpsgConstructionKind = "head-complement" | "head-adjunct" | "head-marker" | "procedure-sequence" | "conditional-instruction" | "coordination" | "administration-clause" | "generic";
10
12
  export type HpsgConstructionOperation = "unify" | "scope";
@@ -166,4 +168,5 @@ export declare function lexicalSign(args: {
166
168
  siteTokenIndices?: number[];
167
169
  warnings?: string[];
168
170
  score?: number;
171
+ scheduleDefault?: HpsgEvidence["scheduleDefault"];
169
172
  }): HpsgSign;
package/dist/index.cjs CHANGED
@@ -3452,6 +3452,19 @@ var instruction_concept_terminology_default = {
3452
3452
  "\u0E41\u0E1C\u0E48\u0E19\u0E43\u0E2B\u0E21\u0E48"
3453
3453
  ]
3454
3454
  },
3455
+ {
3456
+ code: "thoroughly",
3457
+ role: "manner",
3458
+ display: "thoroughly",
3459
+ i18n: {
3460
+ th: "\u0E43\u0E2B\u0E49\u0E17\u0E31\u0E48\u0E27"
3461
+ },
3462
+ aliases: [
3463
+ "thoroughly",
3464
+ "\u0E43\u0E2B\u0E49\u0E17\u0E31\u0E48\u0E27",
3465
+ "\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E17\u0E31\u0E48\u0E27\u0E16\u0E36\u0E07"
3466
+ ]
3467
+ },
3455
3468
  {
3456
3469
  code: "clean-result",
3457
3470
  role: "result",
@@ -7788,6 +7801,10 @@ var DEFAULT_BODY_SITE_SNOMED_SOURCE = [
7788
7801
  names: [
7789
7802
  "interdigital spaces",
7790
7803
  "interdigital space",
7804
+ "interdigital web spaces",
7805
+ "interdigital web space",
7806
+ "web spaces",
7807
+ "web space",
7791
7808
  "\u0E23\u0E30\u0E2B\u0E27\u0E48\u0E32\u0E07\u0E23\u0E48\u0E2D\u0E07\u0E19\u0E34\u0E49\u0E27",
7792
7809
  "\u0E23\u0E48\u0E2D\u0E07\u0E19\u0E34\u0E49\u0E27",
7793
7810
  "\u0E0B\u0E2D\u0E01\u0E19\u0E34\u0E49\u0E27",
@@ -10282,6 +10299,10 @@ for (const relation of ADVICE_RELATION_VALUES) {
10282
10299
  }
10283
10300
  var ACTION_SEQUENCE_MARKERS = ACTION_SEQUENCE_MARKERS_INTERNAL;
10284
10301
  var ACTION_SEQUENCE_RELATION_SURFACES = ACTION_SEQUENCE_RELATION_SURFACES_INTERNAL;
10302
+ function resolveActionRelationSurfaceCandidates(surface) {
10303
+ var _a26;
10304
+ return (_a26 = ACTION_RELATION_INDEX.get(normalize(surface))) != null ? _a26 : [];
10305
+ }
10285
10306
  function resolveActionRelationSurface(surface, preferredSemanticClasses) {
10286
10307
  var _a26, _b3;
10287
10308
  const normalized = normalize(surface);
@@ -15918,6 +15939,117 @@ function resolveEventTimingExpression(parts, start = 0, endExclusive = parts.len
15918
15939
  return direct ? { timing: direct, length: 1 } : void 0;
15919
15940
  }
15920
15941
 
15942
+ // src/hpsg/timing-lexicon.ts
15943
+ var EVERY_INTERVAL_TOKENS = EVERY_INTERVAL_TOKENS_DATA;
15944
+ var COUNT_MARKER_TOKENS = COUNT_MARKER_TOKENS_DATA;
15945
+ var FREQUENCY_SIMPLE_WORDS = FREQUENCY_SIMPLE_WORDS_DATA;
15946
+ var FREQUENCY_NUMBER_WORDS = FREQUENCY_NUMBER_WORDS_DATA;
15947
+ var FREQUENCY_TIMES_WORDS = FREQUENCY_TIMES_WORDS_DATA;
15948
+ var FREQUENCY_CONNECTOR_WORDS = FREQUENCY_CONNECTOR_WORDS_DATA;
15949
+ function mapPeriodUnitLabel(label) {
15950
+ return FhirPeriodUnit[label];
15951
+ }
15952
+ var FREQUENCY_ADVERB_UNITS = new Map(
15953
+ Array.from(FREQUENCY_ADVERB_UNITS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
15954
+ );
15955
+ var INTERVAL_UNITS = new Map(
15956
+ Array.from(INTERVAL_UNIT_TOKENS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
15957
+ );
15958
+ function normalizePeriodValue(value, unit) {
15959
+ if (unit === "h" /* Hour */ && (!Number.isInteger(value) || value < 1)) {
15960
+ return { value: Math.round(value * 60 * 1e3) / 1e3, unit: "min" /* Minute */ };
15961
+ }
15962
+ return { value, unit };
15963
+ }
15964
+ function normalizePeriodRange(low, high, unit) {
15965
+ if (unit === "h" /* Hour */ && (!Number.isInteger(low) || !Number.isInteger(high) || low < 1 || high < 1)) {
15966
+ return {
15967
+ low: Math.round(low * 60 * 1e3) / 1e3,
15968
+ high: Math.round(high * 60 * 1e3) / 1e3,
15969
+ unit: "min" /* Minute */
15970
+ };
15971
+ }
15972
+ return { low, high, unit };
15973
+ }
15974
+ function periodUnitSuffix(unit) {
15975
+ switch (unit) {
15976
+ case "min" /* Minute */:
15977
+ return "min";
15978
+ case "h" /* Hour */:
15979
+ return "h";
15980
+ case "d" /* Day */:
15981
+ return "d";
15982
+ case "wk" /* Week */:
15983
+ return "wk";
15984
+ case "mo" /* Month */:
15985
+ return "mo";
15986
+ case "a" /* Year */:
15987
+ return "a";
15988
+ default:
15989
+ return void 0;
15990
+ }
15991
+ }
15992
+ function deriveDefaultTimingForPeriod(value, unit, currentTimingCode) {
15993
+ let timingCode = currentTimingCode;
15994
+ const suffix = periodUnitSuffix(unit);
15995
+ if (suffix) {
15996
+ const key2 = `q${value}${suffix}`;
15997
+ const descriptor = TIMING_ABBREVIATIONS[key2];
15998
+ if (descriptor == null ? void 0 : descriptor.code) {
15999
+ timingCode = timingCode != null ? timingCode : descriptor.code;
16000
+ }
16001
+ }
16002
+ if (unit === "wk" /* Week */ && value === 1) {
16003
+ timingCode = timingCode != null ? timingCode : "WK";
16004
+ }
16005
+ if (unit === "mo" /* Month */ && value === 1) {
16006
+ timingCode = timingCode != null ? timingCode : "MO";
16007
+ }
16008
+ return {
16009
+ frequency: unit === "d" /* Day */ && value === 1 ? 1 : void 0,
16010
+ timingCode
16011
+ };
16012
+ }
16013
+ function buildPeriodScheduleFeature(period, unit) {
16014
+ const normalized = normalizePeriodValue(period, unit);
16015
+ const defaults = deriveDefaultTimingForPeriod(normalized.value, normalized.unit);
16016
+ return {
16017
+ period: normalized.value,
16018
+ periodUnit: normalized.unit,
16019
+ frequency: defaults.frequency,
16020
+ timingCode: defaults.timingCode
16021
+ };
16022
+ }
16023
+ function mapIntervalUnit(token) {
16024
+ const unit = INTERVAL_UNITS.get(token);
16025
+ return unit === "min" /* Minute */ || unit === "h" /* Hour */ || unit === "d" /* Day */ || unit === "wk" /* Week */ || unit === "mo" /* Month */ ? unit : void 0;
16026
+ }
16027
+ function mapFrequencyAdverb(token) {
16028
+ return FREQUENCY_ADVERB_UNITS.get(token);
16029
+ }
16030
+ function parseNumericRange(token) {
16031
+ const rangeMatch = token.match(/^([0-9]+(?:\.[0-9]+)?)[-–—]([0-9]+(?:\.[0-9]+)?)$/);
16032
+ if (!rangeMatch) {
16033
+ return void 0;
16034
+ }
16035
+ const low = parseFloat(rangeMatch[1]);
16036
+ const high = parseFloat(rangeMatch[2]);
16037
+ if (!Number.isFinite(low) || !Number.isFinite(high) || high < low) {
16038
+ return void 0;
16039
+ }
16040
+ return { low, high };
16041
+ }
16042
+ function buildDurationScheduleFeature(value, unit, max) {
16043
+ if (value === void 0 || !Number.isFinite(value) || value <= 0 || !unit) {
16044
+ return void 0;
16045
+ }
16046
+ return {
16047
+ duration: value,
16048
+ durationMax: max !== void 0 && Number.isFinite(max) && max > value ? max : void 0,
16049
+ durationUnit: unit
16050
+ };
16051
+ }
16052
+
15921
16053
  // src/instruction-graph.ts
15922
16054
  var SNOMED_SYSTEM4 = "http://snomed.info/sct";
15923
16055
  var ACTION_ROUTE_TAIL_SURFACES = /* @__PURE__ */ new Set([
@@ -16978,8 +17110,17 @@ function actionTailIsRegimenModifier(parts, actionStart, index, definition) {
16978
17110
  return true;
16979
17111
  }
16980
17112
  if (ACTION_ROUTE_TAIL_SURFACES.has(token)) return true;
16981
- const timing = Boolean(TIMING_ABBREVIATIONS[token] || WORD_FREQUENCIES[token] || EVENT_TIMING_TOKENS[token]);
16982
- if (!timing) return false;
17113
+ const timing = Boolean(
17114
+ TIMING_ABBREVIATIONS[token] || WORD_FREQUENCIES[token] || EVENT_TIMING_TOKENS[token] || FREQUENCY_SIMPLE_WORDS[token] !== void 0
17115
+ );
17116
+ if (!timing) {
17117
+ const previous = parts[index - 1];
17118
+ if (!previous || !/^[,;:]$/u.test(previous.original.trim())) return false;
17119
+ const relation = resolveActionRelationSurface(token);
17120
+ if (!relation) return false;
17121
+ const eventTail = parts.slice(index + 1, Math.min(parts.length, index + 4));
17122
+ if (!eventTail.some((part) => Boolean(EVENT_TIMING_TOKENS[key(part)]))) return false;
17123
+ }
16983
17124
  if ((definition == null ? void 0 : definition.argumentParser) === "object-time") return false;
16984
17125
  return !actionHasLocalRelationBefore(parts, actionStart, index);
16985
17126
  }
@@ -17769,6 +17910,7 @@ var RESULT_REALIZER = (c) => c.thai ? `${c.label}${c.result ? `\u0E43\u0E2B\u0E4
17769
17910
  var SITE_RELATION_REALIZER = (c) => {
17770
17911
  var _a26, _b3, _c2, _d, _e, _f, _g, _h, _i;
17771
17912
  const relationTarget = (_a26 = c.time) != null ? _a26 : c.activity;
17913
+ const mannerSuffix = c.manner ? c.thai ? c.manner : ` ${c.manner}` : "";
17772
17914
  if (relationTarget) {
17773
17915
  const siteArg = c.frame.args.find((arg) => arg.role === "site" /* Site */);
17774
17916
  const suppressThaiSite = Boolean(
@@ -17778,22 +17920,22 @@ var SITE_RELATION_REALIZER = (c) => {
17778
17920
  if (c.time && relationHasGrammarFeature(c.frame.relation, "directTimeRealization")) {
17779
17921
  if (c.thai) {
17780
17922
  const timePhrase2 = c.time === "\u0E01\u0E25\u0E32\u0E07\u0E04\u0E37\u0E19" ? "\u0E15\u0E2D\u0E19\u0E01\u0E25\u0E32\u0E07\u0E04\u0E37\u0E19" : c.time === "\u0E19\u0E2D\u0E19" || c.time === "bedtime" ? "\u0E01\u0E48\u0E2D\u0E19\u0E19\u0E2D\u0E19" : c.time;
17781
- return `${c.label}${target}${timePhrase2}`;
17923
+ return `${c.label}${target}${mannerSuffix}${timePhrase2}`;
17782
17924
  }
17783
17925
  const lower = c.time.toLowerCase();
17784
17926
  const timePhrase = lower === "night" ? "at night" : lower === "bed" || lower === "bedtime" || lower === "sleep" ? "at bedtime" : /^(?:the )?(?:morning|afternoon|evening)$/.test(lower) ? `in ${lower.startsWith("the ") ? lower : `the ${lower}`}` : `at ${c.time}`;
17785
- return `${c.label}${target} ${timePhrase}`;
17927
+ return `${c.label}${target}${mannerSuffix} ${timePhrase}`;
17786
17928
  }
17787
17929
  const semanticRelation = (_f = (_e = c.frame.relation) != null ? _e : getUniqueAdviceRelationByGrammarFeature("defaultSiteRelation")) != null ? _f : (() => {
17788
17930
  throw new Error("Missing declarative default site relation");
17789
17931
  })();
17790
17932
  const relationProfile = (_h = (_g = getAdviceRelationDefinition(semanticRelation)) == null ? void 0 : _g.grammar.timeRealizationProfile) != null ? _h : "default";
17791
17933
  const relationText = (_i = localizeAdviceRelation(semanticRelation, c.locale, relationProfile)) != null ? _i : semanticRelation;
17792
- return c.thai ? `${c.label}${target}${relationText}${relationTarget}` : `${c.label}${target} ${relationText} ${relationTarget}`;
17934
+ return c.thai ? `${c.label}${target}${mannerSuffix}${relationText}${relationTarget}` : `${c.label}${target}${mannerSuffix} ${relationText} ${relationTarget}`;
17793
17935
  }
17794
17936
  const resultSuffix = c.result ? c.thai ? `\u0E43\u0E2B\u0E49${c.result}` : ` until ${c.result}` : "";
17795
- if (c.site) return c.thai ? `${c.label}${c.site}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label} ${c.site}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17796
- return c.thai ? `${c.label}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17937
+ if (c.site) return c.thai ? `${c.label}${c.site}${mannerSuffix}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label} ${c.site}${mannerSuffix}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17938
+ return c.thai ? `${c.label}${mannerSuffix}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label}${mannerSuffix}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17797
17939
  };
17798
17940
  var OBJECT_AMOUNT_MATERIAL_REALIZER = (c) => {
17799
17941
  var _a26;
@@ -17952,6 +18094,7 @@ function realizeAction(frame, locale, roundtripSafe = false) {
17952
18094
  const time = timeArg ? thai && /[\u0E00-\u0E7F]/u.test(timeArg.text) ? timeArg.text : translatedArgument(timeArg, locale) : void 0;
17953
18095
  const duration = first("duration" /* Duration */);
17954
18096
  const material = first("material" /* Material */);
18097
+ const manner = first("manner" /* Manner */);
17955
18098
  if (frame.polarity === "negate" /* Negate */) {
17956
18099
  const object = (_c2 = (_b3 = site != null ? site : theme) != null ? _b3 : substance) != null ? _c2 : material;
17957
18100
  const relationTarget = activity != null ? activity : time;
@@ -17990,6 +18133,7 @@ function realizeAction(frame, locale, roundtripSafe = false) {
17990
18133
  time,
17991
18134
  duration,
17992
18135
  material,
18136
+ manner,
17993
18137
  realizerConfig: (_i = frame.predicate.realizerConfig) != null ? _i : definition == null ? void 0 : definition.realizerConfig,
17994
18138
  definition
17995
18139
  });
@@ -18032,6 +18176,28 @@ function instructionGraphRepresentsText(graph, text) {
18032
18176
  return Boolean(candidate && (candidate === normalized || candidate.includes(normalized)));
18033
18177
  });
18034
18178
  }
18179
+ function instructionGraphTextParticipatesInRelation(graph, text) {
18180
+ var _a26, _b3;
18181
+ const normalized = normalizedInstructionSurface(text);
18182
+ if (!normalized) return false;
18183
+ const compact = (value) => value.replace(/\s+/gu, "");
18184
+ const matchingIndices = [];
18185
+ for (let index = 0; index < graph.actions.length; index += 1) {
18186
+ const source = normalizedInstructionSurface((_b3 = (_a26 = graph.actions[index]) == null ? void 0 : _a26.sourceText) != null ? _b3 : "");
18187
+ if (!source) continue;
18188
+ if (source === normalized || compact(source).includes(compact(normalized)) || compact(normalized).includes(compact(source))) {
18189
+ matchingIndices.push(index);
18190
+ }
18191
+ }
18192
+ return matchingIndices.some(
18193
+ (index) => {
18194
+ var _a27, _b4;
18195
+ return (_b4 = (_a27 = graph.relations) == null ? void 0 : _a27.some(
18196
+ (relation) => relation.fromActionIndex === index || relation.toActionIndex === index
18197
+ )) != null ? _b4 : false;
18198
+ }
18199
+ );
18200
+ }
18035
18201
  function instructionGraphSingleActionRepresentsText(graph, text) {
18036
18202
  const normalized = normalizedInstructionSurface(text);
18037
18203
  if (!normalized) return false;
@@ -19520,7 +19686,8 @@ function formatLong(clause, options) {
19520
19686
  const graphWarnings = (_v = (_u = clause.instructionGraph) == null ? void 0 : _u.actions.filter(
19521
19687
  (action) => action.polarity === "negate" /* Negate */
19522
19688
  )) != null ? _v : [];
19523
- const graphOwnedAdditional = ((_w = clause.additionalInstructions) != null ? _w : []).filter((instruction) => {
19689
+ const positionedGraph = Boolean((_w = clause.instructionGraph) == null ? void 0 : _w.primaryAdministrationSpan);
19690
+ const graphOwnedAdditional = ((_x = clause.additionalInstructions) != null ? _x : []).filter((instruction) => {
19524
19691
  var _a27, _b4;
19525
19692
  if (((_a27 = instruction.coding) == null ? void 0 : _a27.code) || !instruction.text || !clause.instructionGraph) return false;
19526
19693
  const normalized = normalizeInstruction(instruction.text);
@@ -19528,9 +19695,9 @@ function formatLong(clause, options) {
19528
19695
  const source = normalizeInstruction(action.sourceText);
19529
19696
  return source === normalized || source.includes(normalized) || normalized.includes(source);
19530
19697
  });
19531
- return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
19698
+ return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || positionedGraph && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text) && instructionGraphTextParticipatesInRelation(clause.instructionGraph, instruction.text) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
19532
19699
  });
19533
- const additionalForDirectRendering = ((_x = clause.additionalInstructions) != null ? _x : []).filter(
19700
+ const additionalForDirectRendering = ((_y = clause.additionalInstructions) != null ? _y : []).filter(
19534
19701
  (instruction) => graphOwnedAdditional.indexOf(instruction) === -1 && instruction !== integratedThinLayer
19535
19702
  );
19536
19703
  const additionalTexts = additionalForDirectRendering.map((instruction) => {
@@ -19539,8 +19706,8 @@ function formatLong(clause, options) {
19539
19706
  }).filter((text) => Boolean(text));
19540
19707
  const additionalSemanticSourceTexts = additionalTexts.slice();
19541
19708
  for (const instruction of additionalForDirectRendering) {
19542
- for (const frame of (_y = instruction.frames) != null ? _y : []) {
19543
- const source = (_z = frame.sourceText) == null ? void 0 : _z.trim();
19709
+ for (const frame of (_z = instruction.frames) != null ? _z : []) {
19710
+ const source = (_A = frame.sourceText) == null ? void 0 : _A.trim();
19544
19711
  if (source && additionalSemanticSourceTexts.indexOf(source) === -1) {
19545
19712
  additionalSemanticSourceTexts.push(source);
19546
19713
  }
@@ -19555,7 +19722,6 @@ function formatLong(clause, options) {
19555
19722
  });
19556
19723
  })
19557
19724
  );
19558
- const positionedGraph = Boolean((_A = clause.instructionGraph) == null ? void 0 : _A.primaryAdministrationSpan);
19559
19725
  const positionedRoundTrip = Boolean(roundTrip && positionedGraph);
19560
19726
  const graphWholeInstruction = clause.instructionGraph && !positionedGraph && !hasCodedAdditionalInstruction && allAdditionalRepresentedByGraphWarnings ? realizeInstructionGraph(clause.instructionGraph, "en", {
19561
19727
  includeWarnings: true,
@@ -25451,7 +25617,8 @@ function formatLongThai(clause, options) {
25451
25617
  }
25452
25618
  const richGraphAdministrationText = richPrimaryGraphText ? [richPrimaryGraphText, ...graphRegimenTail].filter(Boolean).join(" ").replace(/\s+/g, " ").trim() : void 0;
25453
25619
  const roundTrip = (options == null ? void 0 : options.realizationMode) === "roundtrip";
25454
- const graphOwnedAdditional = ((_k = clause.additionalInstructions) != null ? _k : []).filter((instruction) => {
25620
+ const positionedGraph = Boolean((_k = clause.instructionGraph) == null ? void 0 : _k.primaryAdministrationSpan);
25621
+ const graphOwnedAdditional = ((_l = clause.additionalInstructions) != null ? _l : []).filter((instruction) => {
25455
25622
  var _a27, _b4;
25456
25623
  if (((_a27 = instruction.coding) == null ? void 0 : _a27.code) || !instruction.text || !clause.instructionGraph) return false;
25457
25624
  const normalized = instruction.text.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
@@ -25459,9 +25626,9 @@ function formatLongThai(clause, options) {
25459
25626
  const source = action.sourceText.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
25460
25627
  return source === normalized || source.includes(normalized) || normalized.includes(source);
25461
25628
  });
25462
- return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
25629
+ return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || positionedGraph && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text) && instructionGraphTextParticipatesInRelation(clause.instructionGraph, instruction.text) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
25463
25630
  });
25464
- const directAdditional = ((_l = clause.additionalInstructions) != null ? _l : []).filter(
25631
+ const directAdditional = ((_m = clause.additionalInstructions) != null ? _m : []).filter(
25465
25632
  (instruction) => graphOwnedAdditional.indexOf(instruction) === -1 && !integratedQualifiers.has(instruction)
25466
25633
  );
25467
25634
  const additionalSemanticSourceTexts = directAdditional.map((instruction) => {
@@ -25469,14 +25636,13 @@ function formatLongThai(clause, options) {
25469
25636
  return (_a27 = instruction.text) == null ? void 0 : _a27.trim();
25470
25637
  }).filter((text) => Boolean(text));
25471
25638
  for (const instruction of directAdditional) {
25472
- for (const frame of (_m = instruction.frames) != null ? _m : []) {
25473
- const source = (_n = frame.sourceText) == null ? void 0 : _n.trim();
25639
+ for (const frame of (_n = instruction.frames) != null ? _n : []) {
25640
+ const source = (_o = frame.sourceText) == null ? void 0 : _o.trim();
25474
25641
  if (source && additionalSemanticSourceTexts.indexOf(source) === -1) {
25475
25642
  additionalSemanticSourceTexts.push(source);
25476
25643
  }
25477
25644
  }
25478
25645
  }
25479
- const positionedGraph = Boolean((_o = clause.instructionGraph) == null ? void 0 : _o.primaryAdministrationSpan);
25480
25646
  const graphRealizationOmissions = richPrimaryGraphAction ? [...additionalSemanticSourceTexts, richPrimaryGraphAction.sourceText] : additionalSemanticSourceTexts;
25481
25647
  const graphRealizationOptions = {
25482
25648
  includeWarnings: true,
@@ -27134,19 +27300,45 @@ function unifySynsem(left, right, context) {
27134
27300
  }
27135
27301
  };
27136
27302
  }
27303
+ function hasDailyFrequencyDefaultEvidence(sign) {
27304
+ return sign.evidence.some((item) => item.scheduleDefault === "daily-frequency");
27305
+ }
27306
+ function schedulePeriodMatches(left, right) {
27307
+ return left.period !== void 0 && right.period !== void 0 && left.period === right.period && left.periodUnit !== void 0 && left.periodUnit === right.periodUnit;
27308
+ }
27309
+ function refinedDailyCadenceSynsem(cadenceSign, explicitSign) {
27310
+ const cadence = cadenceSign.synsem.head.schedule;
27311
+ const explicit = explicitSign.synsem.head.schedule;
27312
+ if (!cadence || !explicit || !hasDailyFrequencyDefaultEvidence(cadenceSign)) return void 0;
27313
+ if (cadence.frequency !== 1 || explicit.frequency === void 0 || explicit.frequency === 1) return void 0;
27314
+ if (!schedulePeriodMatches(cadence, explicit)) return void 0;
27315
+ return __spreadProps(__spreadValues({}, cadenceSign.synsem), {
27316
+ head: __spreadProps(__spreadValues({}, cadenceSign.synsem.head), {
27317
+ schedule: __spreadProps(__spreadValues({}, cadence), { frequency: void 0, timingCode: void 0 })
27318
+ })
27319
+ });
27320
+ }
27321
+ function scheduleRefinementSynsems(left, right) {
27322
+ const refinedLeft = refinedDailyCadenceSynsem(left, right);
27323
+ if (refinedLeft) return { left: refinedLeft, right: right.synsem, refined: true };
27324
+ const refinedRight = refinedDailyCadenceSynsem(right, left);
27325
+ if (refinedRight) return { left: left.synsem, right: refinedRight, refined: true };
27326
+ return { left: left.synsem, right: right.synsem, refined: false };
27327
+ }
27137
27328
  function combineSigns(left, right, context, rule) {
27138
27329
  const selectedConstruction = selectHpsgConstruction(left, right);
27139
27330
  if (!selectedConstruction) return void 0;
27140
27331
  const target = selectedConstruction.construction.headSide === "left" ? left : right;
27141
27332
  const condition = selectedConstruction.construction.headSide === "left" ? right : left;
27142
- const synsem = selectedConstruction.construction.operation === "scope" ? scopeSynsem(condition, target) : unifySynsem(left.synsem, right.synsem, context);
27333
+ const refinement = scheduleRefinementSynsems(left, right);
27334
+ const synsem = selectedConstruction.construction.operation === "scope" ? scopeSynsem(condition, target) : unifySynsem(refinement.left, refinement.right, context);
27143
27335
  if (!synsem) return void 0;
27144
27336
  const fs = combineSignFeatureStructures(
27145
27337
  left.fs,
27146
27338
  right.fs,
27147
27339
  selectedConstruction.motherType,
27148
27340
  selectedConstruction.construction.headSide,
27149
- selectedConstruction.construction.operation === "scope" ? synsem : void 0
27341
+ selectedConstruction.construction.operation === "scope" || refinement.refined ? synsem : void 0
27150
27342
  );
27151
27343
  if (!fs) {
27152
27344
  return void 0;
@@ -27642,117 +27834,6 @@ function getPrimarySiteMeaningCandidate(token) {
27642
27834
  return candidates && candidates.length > 0 ? candidates[0] : void 0;
27643
27835
  }
27644
27836
 
27645
- // src/hpsg/timing-lexicon.ts
27646
- var EVERY_INTERVAL_TOKENS = EVERY_INTERVAL_TOKENS_DATA;
27647
- var COUNT_MARKER_TOKENS = COUNT_MARKER_TOKENS_DATA;
27648
- var FREQUENCY_SIMPLE_WORDS = FREQUENCY_SIMPLE_WORDS_DATA;
27649
- var FREQUENCY_NUMBER_WORDS = FREQUENCY_NUMBER_WORDS_DATA;
27650
- var FREQUENCY_TIMES_WORDS = FREQUENCY_TIMES_WORDS_DATA;
27651
- var FREQUENCY_CONNECTOR_WORDS = FREQUENCY_CONNECTOR_WORDS_DATA;
27652
- function mapPeriodUnitLabel(label) {
27653
- return FhirPeriodUnit[label];
27654
- }
27655
- var FREQUENCY_ADVERB_UNITS = new Map(
27656
- Array.from(FREQUENCY_ADVERB_UNITS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
27657
- );
27658
- var INTERVAL_UNITS = new Map(
27659
- Array.from(INTERVAL_UNIT_TOKENS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
27660
- );
27661
- function normalizePeriodValue(value, unit) {
27662
- if (unit === "h" /* Hour */ && (!Number.isInteger(value) || value < 1)) {
27663
- return { value: Math.round(value * 60 * 1e3) / 1e3, unit: "min" /* Minute */ };
27664
- }
27665
- return { value, unit };
27666
- }
27667
- function normalizePeriodRange(low, high, unit) {
27668
- if (unit === "h" /* Hour */ && (!Number.isInteger(low) || !Number.isInteger(high) || low < 1 || high < 1)) {
27669
- return {
27670
- low: Math.round(low * 60 * 1e3) / 1e3,
27671
- high: Math.round(high * 60 * 1e3) / 1e3,
27672
- unit: "min" /* Minute */
27673
- };
27674
- }
27675
- return { low, high, unit };
27676
- }
27677
- function periodUnitSuffix(unit) {
27678
- switch (unit) {
27679
- case "min" /* Minute */:
27680
- return "min";
27681
- case "h" /* Hour */:
27682
- return "h";
27683
- case "d" /* Day */:
27684
- return "d";
27685
- case "wk" /* Week */:
27686
- return "wk";
27687
- case "mo" /* Month */:
27688
- return "mo";
27689
- case "a" /* Year */:
27690
- return "a";
27691
- default:
27692
- return void 0;
27693
- }
27694
- }
27695
- function deriveDefaultTimingForPeriod(value, unit, currentTimingCode) {
27696
- let timingCode = currentTimingCode;
27697
- const suffix = periodUnitSuffix(unit);
27698
- if (suffix) {
27699
- const key2 = `q${value}${suffix}`;
27700
- const descriptor = TIMING_ABBREVIATIONS[key2];
27701
- if (descriptor == null ? void 0 : descriptor.code) {
27702
- timingCode = timingCode != null ? timingCode : descriptor.code;
27703
- }
27704
- }
27705
- if (unit === "wk" /* Week */ && value === 1) {
27706
- timingCode = timingCode != null ? timingCode : "WK";
27707
- }
27708
- if (unit === "mo" /* Month */ && value === 1) {
27709
- timingCode = timingCode != null ? timingCode : "MO";
27710
- }
27711
- return {
27712
- frequency: unit === "d" /* Day */ && value === 1 ? 1 : void 0,
27713
- timingCode
27714
- };
27715
- }
27716
- function buildPeriodScheduleFeature(period, unit) {
27717
- const normalized = normalizePeriodValue(period, unit);
27718
- const defaults = deriveDefaultTimingForPeriod(normalized.value, normalized.unit);
27719
- return {
27720
- period: normalized.value,
27721
- periodUnit: normalized.unit,
27722
- frequency: defaults.frequency,
27723
- timingCode: defaults.timingCode
27724
- };
27725
- }
27726
- function mapIntervalUnit(token) {
27727
- const unit = INTERVAL_UNITS.get(token);
27728
- return unit === "min" /* Minute */ || unit === "h" /* Hour */ || unit === "d" /* Day */ || unit === "wk" /* Week */ || unit === "mo" /* Month */ ? unit : void 0;
27729
- }
27730
- function mapFrequencyAdverb(token) {
27731
- return FREQUENCY_ADVERB_UNITS.get(token);
27732
- }
27733
- function parseNumericRange(token) {
27734
- const rangeMatch = token.match(/^([0-9]+(?:\.[0-9]+)?)[-–—]([0-9]+(?:\.[0-9]+)?)$/);
27735
- if (!rangeMatch) {
27736
- return void 0;
27737
- }
27738
- const low = parseFloat(rangeMatch[1]);
27739
- const high = parseFloat(rangeMatch[2]);
27740
- if (!Number.isFinite(low) || !Number.isFinite(high) || high < low) {
27741
- return void 0;
27742
- }
27743
- return { low, high };
27744
- }
27745
- function buildDurationScheduleFeature(value, unit, max) {
27746
- if (value === void 0 || !Number.isFinite(value) || value <= 0 || !unit) {
27747
- return void 0;
27748
- }
27749
- return {
27750
- duration: value,
27751
- durationMax: max !== void 0 && Number.isFinite(max) && max > value ? max : void 0,
27752
- durationUnit: unit
27753
- };
27754
- }
27755
-
27756
27837
  // src/hpsg/rule-context.ts
27757
27838
  function normalizeTokenLower(token) {
27758
27839
  var _a26;
@@ -27929,7 +28010,8 @@ function lexicalSign(args) {
27929
28010
  evidence: [
27930
28011
  {
27931
28012
  rule: args.rule,
27932
- tokenIndices
28013
+ tokenIndices,
28014
+ scheduleDefault: args.scheduleDefault
27933
28015
  }
27934
28016
  ],
27935
28017
  score: (_b3 = args.score) != null ? _b3 : 1
@@ -28215,6 +28297,7 @@ function separatedIntervalRule() {
28215
28297
  valence: {},
28216
28298
  cont: { clauseKind: "administration" }
28217
28299
  },
28300
+ scheduleDefault: directUnit === "d" /* Day */ ? "daily-frequency" : void 0,
28218
28301
  score: 9
28219
28302
  })
28220
28303
  ];
@@ -30955,6 +31038,28 @@ function anchoredModifierLeadsToResolvableSite(context, start) {
30955
31038
  }
30956
31039
  return false;
30957
31040
  }
31041
+ function relationIntroducesNonSiteComplement(context, index) {
31042
+ const token = context.tokens[index];
31043
+ if (!token) return false;
31044
+ const relations = resolveActionRelationSurfaceCandidates(normalizeTokenLower(token));
31045
+ if (!relations.length) return false;
31046
+ for (let cursor = index + 1; cursor < Math.min(context.limit, index + 4); cursor += 1) {
31047
+ const candidate = context.tokens[cursor];
31048
+ if (!candidate || context.state.consumed.has(candidate.index) || isPunctuation(normalizeTokenLower(candidate))) {
31049
+ break;
31050
+ }
31051
+ if (EVENT_TIMING_TOKENS[normalizeTokenLower(candidate)]) return true;
31052
+ }
31053
+ return false;
31054
+ }
31055
+ function coordinationStartsAction(context, index) {
31056
+ const token = context.tokens[index];
31057
+ if (!token || !ACTION_COORDINATION_CONNECTORS.has(normalizeTokenLower(token))) return false;
31058
+ const next = context.tokens[index + 1];
31059
+ return Boolean(
31060
+ next && !context.state.consumed.has(next.index) && resolveMedicationInstructionAction(normalizeTokenLower(next), context.options)
31061
+ );
31062
+ }
30958
31063
  function siteBoundary(lower, context) {
30959
31064
  var _a26, _b3, _c2;
30960
31065
  if (SITE_MULTIPLICITY_WORDS.has(lower)) {
@@ -31075,8 +31180,9 @@ function siteLexicalRule() {
31075
31180
  if (getDayOfWeekMeaning(candidate)) {
31076
31181
  break;
31077
31182
  }
31183
+ if (coordinationStartsAction(context, cursor)) break;
31078
31184
  const siteModifierCanBridgeBoundary = (SITE_SELF_DISPLAY_ANCHORS.has(candidateLower) || EXTERNAL_SITE_LOCATIVE_PREFIXES.has(candidateLower) || BODY_SITE_ATTRIBUTIVE_MODIFIERS.has(candidateLower)) && anchoredModifierLeadsToResolvableSite(context, cursor);
31079
- if (siteBoundary(candidateLower, context) && (isPunctuation(candidateLower) || !siteModifierCanBridgeBoundary)) {
31185
+ if ((siteBoundary(candidateLower, context) || relationIntroducesNonSiteComplement(context, cursor)) && (isPunctuation(candidateLower) || !siteModifierCanBridgeBoundary)) {
31080
31186
  const next = context.tokens[cursor + 1];
31081
31187
  const nextLower = next && !context.state.consumed.has(next.index) ? normalizeTokenLower(next) : void 0;
31082
31188
  const continuedText = nextLower ? [...displayTokens, next].map((part) => part.original).join(" ") : "";
package/dist/index.js CHANGED
@@ -3316,6 +3316,19 @@ var instruction_concept_terminology_default = {
3316
3316
  "\u0E41\u0E1C\u0E48\u0E19\u0E43\u0E2B\u0E21\u0E48"
3317
3317
  ]
3318
3318
  },
3319
+ {
3320
+ code: "thoroughly",
3321
+ role: "manner",
3322
+ display: "thoroughly",
3323
+ i18n: {
3324
+ th: "\u0E43\u0E2B\u0E49\u0E17\u0E31\u0E48\u0E27"
3325
+ },
3326
+ aliases: [
3327
+ "thoroughly",
3328
+ "\u0E43\u0E2B\u0E49\u0E17\u0E31\u0E48\u0E27",
3329
+ "\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E17\u0E31\u0E48\u0E27\u0E16\u0E36\u0E07"
3330
+ ]
3331
+ },
3319
3332
  {
3320
3333
  code: "clean-result",
3321
3334
  role: "result",
@@ -7652,6 +7665,10 @@ var DEFAULT_BODY_SITE_SNOMED_SOURCE = [
7652
7665
  names: [
7653
7666
  "interdigital spaces",
7654
7667
  "interdigital space",
7668
+ "interdigital web spaces",
7669
+ "interdigital web space",
7670
+ "web spaces",
7671
+ "web space",
7655
7672
  "\u0E23\u0E30\u0E2B\u0E27\u0E48\u0E32\u0E07\u0E23\u0E48\u0E2D\u0E07\u0E19\u0E34\u0E49\u0E27",
7656
7673
  "\u0E23\u0E48\u0E2D\u0E07\u0E19\u0E34\u0E49\u0E27",
7657
7674
  "\u0E0B\u0E2D\u0E01\u0E19\u0E34\u0E49\u0E27",
@@ -10146,6 +10163,10 @@ for (const relation of ADVICE_RELATION_VALUES) {
10146
10163
  }
10147
10164
  var ACTION_SEQUENCE_MARKERS = ACTION_SEQUENCE_MARKERS_INTERNAL;
10148
10165
  var ACTION_SEQUENCE_RELATION_SURFACES = ACTION_SEQUENCE_RELATION_SURFACES_INTERNAL;
10166
+ function resolveActionRelationSurfaceCandidates(surface) {
10167
+ var _a26;
10168
+ return (_a26 = ACTION_RELATION_INDEX.get(normalize(surface))) != null ? _a26 : [];
10169
+ }
10149
10170
  function resolveActionRelationSurface(surface, preferredSemanticClasses) {
10150
10171
  var _a26, _b3;
10151
10172
  const normalized = normalize(surface);
@@ -15782,6 +15803,117 @@ function resolveEventTimingExpression(parts, start = 0, endExclusive = parts.len
15782
15803
  return direct ? { timing: direct, length: 1 } : void 0;
15783
15804
  }
15784
15805
 
15806
+ // src/hpsg/timing-lexicon.ts
15807
+ var EVERY_INTERVAL_TOKENS = EVERY_INTERVAL_TOKENS_DATA;
15808
+ var COUNT_MARKER_TOKENS = COUNT_MARKER_TOKENS_DATA;
15809
+ var FREQUENCY_SIMPLE_WORDS = FREQUENCY_SIMPLE_WORDS_DATA;
15810
+ var FREQUENCY_NUMBER_WORDS = FREQUENCY_NUMBER_WORDS_DATA;
15811
+ var FREQUENCY_TIMES_WORDS = FREQUENCY_TIMES_WORDS_DATA;
15812
+ var FREQUENCY_CONNECTOR_WORDS = FREQUENCY_CONNECTOR_WORDS_DATA;
15813
+ function mapPeriodUnitLabel(label) {
15814
+ return FhirPeriodUnit[label];
15815
+ }
15816
+ var FREQUENCY_ADVERB_UNITS = new Map(
15817
+ Array.from(FREQUENCY_ADVERB_UNITS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
15818
+ );
15819
+ var INTERVAL_UNITS = new Map(
15820
+ Array.from(INTERVAL_UNIT_TOKENS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
15821
+ );
15822
+ function normalizePeriodValue(value, unit) {
15823
+ if (unit === "h" /* Hour */ && (!Number.isInteger(value) || value < 1)) {
15824
+ return { value: Math.round(value * 60 * 1e3) / 1e3, unit: "min" /* Minute */ };
15825
+ }
15826
+ return { value, unit };
15827
+ }
15828
+ function normalizePeriodRange(low, high, unit) {
15829
+ if (unit === "h" /* Hour */ && (!Number.isInteger(low) || !Number.isInteger(high) || low < 1 || high < 1)) {
15830
+ return {
15831
+ low: Math.round(low * 60 * 1e3) / 1e3,
15832
+ high: Math.round(high * 60 * 1e3) / 1e3,
15833
+ unit: "min" /* Minute */
15834
+ };
15835
+ }
15836
+ return { low, high, unit };
15837
+ }
15838
+ function periodUnitSuffix(unit) {
15839
+ switch (unit) {
15840
+ case "min" /* Minute */:
15841
+ return "min";
15842
+ case "h" /* Hour */:
15843
+ return "h";
15844
+ case "d" /* Day */:
15845
+ return "d";
15846
+ case "wk" /* Week */:
15847
+ return "wk";
15848
+ case "mo" /* Month */:
15849
+ return "mo";
15850
+ case "a" /* Year */:
15851
+ return "a";
15852
+ default:
15853
+ return void 0;
15854
+ }
15855
+ }
15856
+ function deriveDefaultTimingForPeriod(value, unit, currentTimingCode) {
15857
+ let timingCode = currentTimingCode;
15858
+ const suffix = periodUnitSuffix(unit);
15859
+ if (suffix) {
15860
+ const key2 = `q${value}${suffix}`;
15861
+ const descriptor = TIMING_ABBREVIATIONS[key2];
15862
+ if (descriptor == null ? void 0 : descriptor.code) {
15863
+ timingCode = timingCode != null ? timingCode : descriptor.code;
15864
+ }
15865
+ }
15866
+ if (unit === "wk" /* Week */ && value === 1) {
15867
+ timingCode = timingCode != null ? timingCode : "WK";
15868
+ }
15869
+ if (unit === "mo" /* Month */ && value === 1) {
15870
+ timingCode = timingCode != null ? timingCode : "MO";
15871
+ }
15872
+ return {
15873
+ frequency: unit === "d" /* Day */ && value === 1 ? 1 : void 0,
15874
+ timingCode
15875
+ };
15876
+ }
15877
+ function buildPeriodScheduleFeature(period, unit) {
15878
+ const normalized = normalizePeriodValue(period, unit);
15879
+ const defaults = deriveDefaultTimingForPeriod(normalized.value, normalized.unit);
15880
+ return {
15881
+ period: normalized.value,
15882
+ periodUnit: normalized.unit,
15883
+ frequency: defaults.frequency,
15884
+ timingCode: defaults.timingCode
15885
+ };
15886
+ }
15887
+ function mapIntervalUnit(token) {
15888
+ const unit = INTERVAL_UNITS.get(token);
15889
+ return unit === "min" /* Minute */ || unit === "h" /* Hour */ || unit === "d" /* Day */ || unit === "wk" /* Week */ || unit === "mo" /* Month */ ? unit : void 0;
15890
+ }
15891
+ function mapFrequencyAdverb(token) {
15892
+ return FREQUENCY_ADVERB_UNITS.get(token);
15893
+ }
15894
+ function parseNumericRange(token) {
15895
+ const rangeMatch = token.match(/^([0-9]+(?:\.[0-9]+)?)[-–—]([0-9]+(?:\.[0-9]+)?)$/);
15896
+ if (!rangeMatch) {
15897
+ return void 0;
15898
+ }
15899
+ const low = parseFloat(rangeMatch[1]);
15900
+ const high = parseFloat(rangeMatch[2]);
15901
+ if (!Number.isFinite(low) || !Number.isFinite(high) || high < low) {
15902
+ return void 0;
15903
+ }
15904
+ return { low, high };
15905
+ }
15906
+ function buildDurationScheduleFeature(value, unit, max) {
15907
+ if (value === void 0 || !Number.isFinite(value) || value <= 0 || !unit) {
15908
+ return void 0;
15909
+ }
15910
+ return {
15911
+ duration: value,
15912
+ durationMax: max !== void 0 && Number.isFinite(max) && max > value ? max : void 0,
15913
+ durationUnit: unit
15914
+ };
15915
+ }
15916
+
15785
15917
  // src/instruction-graph.ts
15786
15918
  var SNOMED_SYSTEM4 = "http://snomed.info/sct";
15787
15919
  var ACTION_ROUTE_TAIL_SURFACES = /* @__PURE__ */ new Set([
@@ -16842,8 +16974,17 @@ function actionTailIsRegimenModifier(parts, actionStart, index, definition) {
16842
16974
  return true;
16843
16975
  }
16844
16976
  if (ACTION_ROUTE_TAIL_SURFACES.has(token)) return true;
16845
- const timing = Boolean(TIMING_ABBREVIATIONS[token] || WORD_FREQUENCIES[token] || EVENT_TIMING_TOKENS[token]);
16846
- if (!timing) return false;
16977
+ const timing = Boolean(
16978
+ TIMING_ABBREVIATIONS[token] || WORD_FREQUENCIES[token] || EVENT_TIMING_TOKENS[token] || FREQUENCY_SIMPLE_WORDS[token] !== void 0
16979
+ );
16980
+ if (!timing) {
16981
+ const previous = parts[index - 1];
16982
+ if (!previous || !/^[,;:]$/u.test(previous.original.trim())) return false;
16983
+ const relation = resolveActionRelationSurface(token);
16984
+ if (!relation) return false;
16985
+ const eventTail = parts.slice(index + 1, Math.min(parts.length, index + 4));
16986
+ if (!eventTail.some((part) => Boolean(EVENT_TIMING_TOKENS[key(part)]))) return false;
16987
+ }
16847
16988
  if ((definition == null ? void 0 : definition.argumentParser) === "object-time") return false;
16848
16989
  return !actionHasLocalRelationBefore(parts, actionStart, index);
16849
16990
  }
@@ -17633,6 +17774,7 @@ var RESULT_REALIZER = (c) => c.thai ? `${c.label}${c.result ? `\u0E43\u0E2B\u0E4
17633
17774
  var SITE_RELATION_REALIZER = (c) => {
17634
17775
  var _a26, _b3, _c2, _d, _e, _f, _g, _h, _i;
17635
17776
  const relationTarget = (_a26 = c.time) != null ? _a26 : c.activity;
17777
+ const mannerSuffix = c.manner ? c.thai ? c.manner : ` ${c.manner}` : "";
17636
17778
  if (relationTarget) {
17637
17779
  const siteArg = c.frame.args.find((arg) => arg.role === "site" /* Site */);
17638
17780
  const suppressThaiSite = Boolean(
@@ -17642,22 +17784,22 @@ var SITE_RELATION_REALIZER = (c) => {
17642
17784
  if (c.time && relationHasGrammarFeature(c.frame.relation, "directTimeRealization")) {
17643
17785
  if (c.thai) {
17644
17786
  const timePhrase2 = c.time === "\u0E01\u0E25\u0E32\u0E07\u0E04\u0E37\u0E19" ? "\u0E15\u0E2D\u0E19\u0E01\u0E25\u0E32\u0E07\u0E04\u0E37\u0E19" : c.time === "\u0E19\u0E2D\u0E19" || c.time === "bedtime" ? "\u0E01\u0E48\u0E2D\u0E19\u0E19\u0E2D\u0E19" : c.time;
17645
- return `${c.label}${target}${timePhrase2}`;
17787
+ return `${c.label}${target}${mannerSuffix}${timePhrase2}`;
17646
17788
  }
17647
17789
  const lower = c.time.toLowerCase();
17648
17790
  const timePhrase = lower === "night" ? "at night" : lower === "bed" || lower === "bedtime" || lower === "sleep" ? "at bedtime" : /^(?:the )?(?:morning|afternoon|evening)$/.test(lower) ? `in ${lower.startsWith("the ") ? lower : `the ${lower}`}` : `at ${c.time}`;
17649
- return `${c.label}${target} ${timePhrase}`;
17791
+ return `${c.label}${target}${mannerSuffix} ${timePhrase}`;
17650
17792
  }
17651
17793
  const semanticRelation = (_f = (_e = c.frame.relation) != null ? _e : getUniqueAdviceRelationByGrammarFeature("defaultSiteRelation")) != null ? _f : (() => {
17652
17794
  throw new Error("Missing declarative default site relation");
17653
17795
  })();
17654
17796
  const relationProfile = (_h = (_g = getAdviceRelationDefinition(semanticRelation)) == null ? void 0 : _g.grammar.timeRealizationProfile) != null ? _h : "default";
17655
17797
  const relationText = (_i = localizeAdviceRelation(semanticRelation, c.locale, relationProfile)) != null ? _i : semanticRelation;
17656
- return c.thai ? `${c.label}${target}${relationText}${relationTarget}` : `${c.label}${target} ${relationText} ${relationTarget}`;
17798
+ return c.thai ? `${c.label}${target}${mannerSuffix}${relationText}${relationTarget}` : `${c.label}${target}${mannerSuffix} ${relationText} ${relationTarget}`;
17657
17799
  }
17658
17800
  const resultSuffix = c.result ? c.thai ? `\u0E43\u0E2B\u0E49${c.result}` : ` until ${c.result}` : "";
17659
- if (c.site) return c.thai ? `${c.label}${c.site}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label} ${c.site}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17660
- return c.thai ? `${c.label}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17801
+ if (c.site) return c.thai ? `${c.label}${c.site}${mannerSuffix}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label} ${c.site}${mannerSuffix}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17802
+ return c.thai ? `${c.label}${mannerSuffix}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label}${mannerSuffix}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17661
17803
  };
17662
17804
  var OBJECT_AMOUNT_MATERIAL_REALIZER = (c) => {
17663
17805
  var _a26;
@@ -17816,6 +17958,7 @@ function realizeAction(frame, locale, roundtripSafe = false) {
17816
17958
  const time = timeArg ? thai && /[\u0E00-\u0E7F]/u.test(timeArg.text) ? timeArg.text : translatedArgument(timeArg, locale) : void 0;
17817
17959
  const duration = first("duration" /* Duration */);
17818
17960
  const material = first("material" /* Material */);
17961
+ const manner = first("manner" /* Manner */);
17819
17962
  if (frame.polarity === "negate" /* Negate */) {
17820
17963
  const object = (_c2 = (_b3 = site != null ? site : theme) != null ? _b3 : substance) != null ? _c2 : material;
17821
17964
  const relationTarget = activity != null ? activity : time;
@@ -17854,6 +17997,7 @@ function realizeAction(frame, locale, roundtripSafe = false) {
17854
17997
  time,
17855
17998
  duration,
17856
17999
  material,
18000
+ manner,
17857
18001
  realizerConfig: (_i = frame.predicate.realizerConfig) != null ? _i : definition == null ? void 0 : definition.realizerConfig,
17858
18002
  definition
17859
18003
  });
@@ -17896,6 +18040,28 @@ function instructionGraphRepresentsText(graph, text) {
17896
18040
  return Boolean(candidate && (candidate === normalized || candidate.includes(normalized)));
17897
18041
  });
17898
18042
  }
18043
+ function instructionGraphTextParticipatesInRelation(graph, text) {
18044
+ var _a26, _b3;
18045
+ const normalized = normalizedInstructionSurface(text);
18046
+ if (!normalized) return false;
18047
+ const compact = (value) => value.replace(/\s+/gu, "");
18048
+ const matchingIndices = [];
18049
+ for (let index = 0; index < graph.actions.length; index += 1) {
18050
+ const source = normalizedInstructionSurface((_b3 = (_a26 = graph.actions[index]) == null ? void 0 : _a26.sourceText) != null ? _b3 : "");
18051
+ if (!source) continue;
18052
+ if (source === normalized || compact(source).includes(compact(normalized)) || compact(normalized).includes(compact(source))) {
18053
+ matchingIndices.push(index);
18054
+ }
18055
+ }
18056
+ return matchingIndices.some(
18057
+ (index) => {
18058
+ var _a27, _b4;
18059
+ return (_b4 = (_a27 = graph.relations) == null ? void 0 : _a27.some(
18060
+ (relation) => relation.fromActionIndex === index || relation.toActionIndex === index
18061
+ )) != null ? _b4 : false;
18062
+ }
18063
+ );
18064
+ }
17899
18065
  function instructionGraphSingleActionRepresentsText(graph, text) {
17900
18066
  const normalized = normalizedInstructionSurface(text);
17901
18067
  if (!normalized) return false;
@@ -19384,7 +19550,8 @@ function formatLong(clause, options) {
19384
19550
  const graphWarnings = (_v = (_u = clause.instructionGraph) == null ? void 0 : _u.actions.filter(
19385
19551
  (action) => action.polarity === "negate" /* Negate */
19386
19552
  )) != null ? _v : [];
19387
- const graphOwnedAdditional = ((_w = clause.additionalInstructions) != null ? _w : []).filter((instruction) => {
19553
+ const positionedGraph = Boolean((_w = clause.instructionGraph) == null ? void 0 : _w.primaryAdministrationSpan);
19554
+ const graphOwnedAdditional = ((_x = clause.additionalInstructions) != null ? _x : []).filter((instruction) => {
19388
19555
  var _a27, _b4;
19389
19556
  if (((_a27 = instruction.coding) == null ? void 0 : _a27.code) || !instruction.text || !clause.instructionGraph) return false;
19390
19557
  const normalized = normalizeInstruction(instruction.text);
@@ -19392,9 +19559,9 @@ function formatLong(clause, options) {
19392
19559
  const source = normalizeInstruction(action.sourceText);
19393
19560
  return source === normalized || source.includes(normalized) || normalized.includes(source);
19394
19561
  });
19395
- return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
19562
+ return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || positionedGraph && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text) && instructionGraphTextParticipatesInRelation(clause.instructionGraph, instruction.text) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
19396
19563
  });
19397
- const additionalForDirectRendering = ((_x = clause.additionalInstructions) != null ? _x : []).filter(
19564
+ const additionalForDirectRendering = ((_y = clause.additionalInstructions) != null ? _y : []).filter(
19398
19565
  (instruction) => graphOwnedAdditional.indexOf(instruction) === -1 && instruction !== integratedThinLayer
19399
19566
  );
19400
19567
  const additionalTexts = additionalForDirectRendering.map((instruction) => {
@@ -19403,8 +19570,8 @@ function formatLong(clause, options) {
19403
19570
  }).filter((text) => Boolean(text));
19404
19571
  const additionalSemanticSourceTexts = additionalTexts.slice();
19405
19572
  for (const instruction of additionalForDirectRendering) {
19406
- for (const frame of (_y = instruction.frames) != null ? _y : []) {
19407
- const source = (_z = frame.sourceText) == null ? void 0 : _z.trim();
19573
+ for (const frame of (_z = instruction.frames) != null ? _z : []) {
19574
+ const source = (_A = frame.sourceText) == null ? void 0 : _A.trim();
19408
19575
  if (source && additionalSemanticSourceTexts.indexOf(source) === -1) {
19409
19576
  additionalSemanticSourceTexts.push(source);
19410
19577
  }
@@ -19419,7 +19586,6 @@ function formatLong(clause, options) {
19419
19586
  });
19420
19587
  })
19421
19588
  );
19422
- const positionedGraph = Boolean((_A = clause.instructionGraph) == null ? void 0 : _A.primaryAdministrationSpan);
19423
19589
  const positionedRoundTrip = Boolean(roundTrip && positionedGraph);
19424
19590
  const graphWholeInstruction = clause.instructionGraph && !positionedGraph && !hasCodedAdditionalInstruction && allAdditionalRepresentedByGraphWarnings ? realizeInstructionGraph(clause.instructionGraph, "en", {
19425
19591
  includeWarnings: true,
@@ -25315,7 +25481,8 @@ function formatLongThai(clause, options) {
25315
25481
  }
25316
25482
  const richGraphAdministrationText = richPrimaryGraphText ? [richPrimaryGraphText, ...graphRegimenTail].filter(Boolean).join(" ").replace(/\s+/g, " ").trim() : void 0;
25317
25483
  const roundTrip = (options == null ? void 0 : options.realizationMode) === "roundtrip";
25318
- const graphOwnedAdditional = ((_k = clause.additionalInstructions) != null ? _k : []).filter((instruction) => {
25484
+ const positionedGraph = Boolean((_k = clause.instructionGraph) == null ? void 0 : _k.primaryAdministrationSpan);
25485
+ const graphOwnedAdditional = ((_l = clause.additionalInstructions) != null ? _l : []).filter((instruction) => {
25319
25486
  var _a27, _b4;
25320
25487
  if (((_a27 = instruction.coding) == null ? void 0 : _a27.code) || !instruction.text || !clause.instructionGraph) return false;
25321
25488
  const normalized = instruction.text.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
@@ -25323,9 +25490,9 @@ function formatLongThai(clause, options) {
25323
25490
  const source = action.sourceText.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
25324
25491
  return source === normalized || source.includes(normalized) || normalized.includes(source);
25325
25492
  });
25326
- return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
25493
+ return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || positionedGraph && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text) && instructionGraphTextParticipatesInRelation(clause.instructionGraph, instruction.text) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
25327
25494
  });
25328
- const directAdditional = ((_l = clause.additionalInstructions) != null ? _l : []).filter(
25495
+ const directAdditional = ((_m = clause.additionalInstructions) != null ? _m : []).filter(
25329
25496
  (instruction) => graphOwnedAdditional.indexOf(instruction) === -1 && !integratedQualifiers.has(instruction)
25330
25497
  );
25331
25498
  const additionalSemanticSourceTexts = directAdditional.map((instruction) => {
@@ -25333,14 +25500,13 @@ function formatLongThai(clause, options) {
25333
25500
  return (_a27 = instruction.text) == null ? void 0 : _a27.trim();
25334
25501
  }).filter((text) => Boolean(text));
25335
25502
  for (const instruction of directAdditional) {
25336
- for (const frame of (_m = instruction.frames) != null ? _m : []) {
25337
- const source = (_n = frame.sourceText) == null ? void 0 : _n.trim();
25503
+ for (const frame of (_n = instruction.frames) != null ? _n : []) {
25504
+ const source = (_o = frame.sourceText) == null ? void 0 : _o.trim();
25338
25505
  if (source && additionalSemanticSourceTexts.indexOf(source) === -1) {
25339
25506
  additionalSemanticSourceTexts.push(source);
25340
25507
  }
25341
25508
  }
25342
25509
  }
25343
- const positionedGraph = Boolean((_o = clause.instructionGraph) == null ? void 0 : _o.primaryAdministrationSpan);
25344
25510
  const graphRealizationOmissions = richPrimaryGraphAction ? [...additionalSemanticSourceTexts, richPrimaryGraphAction.sourceText] : additionalSemanticSourceTexts;
25345
25511
  const graphRealizationOptions = {
25346
25512
  includeWarnings: true,
@@ -26998,19 +27164,45 @@ function unifySynsem(left, right, context) {
26998
27164
  }
26999
27165
  };
27000
27166
  }
27167
+ function hasDailyFrequencyDefaultEvidence(sign) {
27168
+ return sign.evidence.some((item) => item.scheduleDefault === "daily-frequency");
27169
+ }
27170
+ function schedulePeriodMatches(left, right) {
27171
+ return left.period !== void 0 && right.period !== void 0 && left.period === right.period && left.periodUnit !== void 0 && left.periodUnit === right.periodUnit;
27172
+ }
27173
+ function refinedDailyCadenceSynsem(cadenceSign, explicitSign) {
27174
+ const cadence = cadenceSign.synsem.head.schedule;
27175
+ const explicit = explicitSign.synsem.head.schedule;
27176
+ if (!cadence || !explicit || !hasDailyFrequencyDefaultEvidence(cadenceSign)) return void 0;
27177
+ if (cadence.frequency !== 1 || explicit.frequency === void 0 || explicit.frequency === 1) return void 0;
27178
+ if (!schedulePeriodMatches(cadence, explicit)) return void 0;
27179
+ return __spreadProps(__spreadValues({}, cadenceSign.synsem), {
27180
+ head: __spreadProps(__spreadValues({}, cadenceSign.synsem.head), {
27181
+ schedule: __spreadProps(__spreadValues({}, cadence), { frequency: void 0, timingCode: void 0 })
27182
+ })
27183
+ });
27184
+ }
27185
+ function scheduleRefinementSynsems(left, right) {
27186
+ const refinedLeft = refinedDailyCadenceSynsem(left, right);
27187
+ if (refinedLeft) return { left: refinedLeft, right: right.synsem, refined: true };
27188
+ const refinedRight = refinedDailyCadenceSynsem(right, left);
27189
+ if (refinedRight) return { left: left.synsem, right: refinedRight, refined: true };
27190
+ return { left: left.synsem, right: right.synsem, refined: false };
27191
+ }
27001
27192
  function combineSigns(left, right, context, rule) {
27002
27193
  const selectedConstruction = selectHpsgConstruction(left, right);
27003
27194
  if (!selectedConstruction) return void 0;
27004
27195
  const target = selectedConstruction.construction.headSide === "left" ? left : right;
27005
27196
  const condition = selectedConstruction.construction.headSide === "left" ? right : left;
27006
- const synsem = selectedConstruction.construction.operation === "scope" ? scopeSynsem(condition, target) : unifySynsem(left.synsem, right.synsem, context);
27197
+ const refinement = scheduleRefinementSynsems(left, right);
27198
+ const synsem = selectedConstruction.construction.operation === "scope" ? scopeSynsem(condition, target) : unifySynsem(refinement.left, refinement.right, context);
27007
27199
  if (!synsem) return void 0;
27008
27200
  const fs = combineSignFeatureStructures(
27009
27201
  left.fs,
27010
27202
  right.fs,
27011
27203
  selectedConstruction.motherType,
27012
27204
  selectedConstruction.construction.headSide,
27013
- selectedConstruction.construction.operation === "scope" ? synsem : void 0
27205
+ selectedConstruction.construction.operation === "scope" || refinement.refined ? synsem : void 0
27014
27206
  );
27015
27207
  if (!fs) {
27016
27208
  return void 0;
@@ -27506,117 +27698,6 @@ function getPrimarySiteMeaningCandidate(token) {
27506
27698
  return candidates && candidates.length > 0 ? candidates[0] : void 0;
27507
27699
  }
27508
27700
 
27509
- // src/hpsg/timing-lexicon.ts
27510
- var EVERY_INTERVAL_TOKENS = EVERY_INTERVAL_TOKENS_DATA;
27511
- var COUNT_MARKER_TOKENS = COUNT_MARKER_TOKENS_DATA;
27512
- var FREQUENCY_SIMPLE_WORDS = FREQUENCY_SIMPLE_WORDS_DATA;
27513
- var FREQUENCY_NUMBER_WORDS = FREQUENCY_NUMBER_WORDS_DATA;
27514
- var FREQUENCY_TIMES_WORDS = FREQUENCY_TIMES_WORDS_DATA;
27515
- var FREQUENCY_CONNECTOR_WORDS = FREQUENCY_CONNECTOR_WORDS_DATA;
27516
- function mapPeriodUnitLabel(label) {
27517
- return FhirPeriodUnit[label];
27518
- }
27519
- var FREQUENCY_ADVERB_UNITS = new Map(
27520
- Array.from(FREQUENCY_ADVERB_UNITS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
27521
- );
27522
- var INTERVAL_UNITS = new Map(
27523
- Array.from(INTERVAL_UNIT_TOKENS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
27524
- );
27525
- function normalizePeriodValue(value, unit) {
27526
- if (unit === "h" /* Hour */ && (!Number.isInteger(value) || value < 1)) {
27527
- return { value: Math.round(value * 60 * 1e3) / 1e3, unit: "min" /* Minute */ };
27528
- }
27529
- return { value, unit };
27530
- }
27531
- function normalizePeriodRange(low, high, unit) {
27532
- if (unit === "h" /* Hour */ && (!Number.isInteger(low) || !Number.isInteger(high) || low < 1 || high < 1)) {
27533
- return {
27534
- low: Math.round(low * 60 * 1e3) / 1e3,
27535
- high: Math.round(high * 60 * 1e3) / 1e3,
27536
- unit: "min" /* Minute */
27537
- };
27538
- }
27539
- return { low, high, unit };
27540
- }
27541
- function periodUnitSuffix(unit) {
27542
- switch (unit) {
27543
- case "min" /* Minute */:
27544
- return "min";
27545
- case "h" /* Hour */:
27546
- return "h";
27547
- case "d" /* Day */:
27548
- return "d";
27549
- case "wk" /* Week */:
27550
- return "wk";
27551
- case "mo" /* Month */:
27552
- return "mo";
27553
- case "a" /* Year */:
27554
- return "a";
27555
- default:
27556
- return void 0;
27557
- }
27558
- }
27559
- function deriveDefaultTimingForPeriod(value, unit, currentTimingCode) {
27560
- let timingCode = currentTimingCode;
27561
- const suffix = periodUnitSuffix(unit);
27562
- if (suffix) {
27563
- const key2 = `q${value}${suffix}`;
27564
- const descriptor = TIMING_ABBREVIATIONS[key2];
27565
- if (descriptor == null ? void 0 : descriptor.code) {
27566
- timingCode = timingCode != null ? timingCode : descriptor.code;
27567
- }
27568
- }
27569
- if (unit === "wk" /* Week */ && value === 1) {
27570
- timingCode = timingCode != null ? timingCode : "WK";
27571
- }
27572
- if (unit === "mo" /* Month */ && value === 1) {
27573
- timingCode = timingCode != null ? timingCode : "MO";
27574
- }
27575
- return {
27576
- frequency: unit === "d" /* Day */ && value === 1 ? 1 : void 0,
27577
- timingCode
27578
- };
27579
- }
27580
- function buildPeriodScheduleFeature(period, unit) {
27581
- const normalized = normalizePeriodValue(period, unit);
27582
- const defaults = deriveDefaultTimingForPeriod(normalized.value, normalized.unit);
27583
- return {
27584
- period: normalized.value,
27585
- periodUnit: normalized.unit,
27586
- frequency: defaults.frequency,
27587
- timingCode: defaults.timingCode
27588
- };
27589
- }
27590
- function mapIntervalUnit(token) {
27591
- const unit = INTERVAL_UNITS.get(token);
27592
- return unit === "min" /* Minute */ || unit === "h" /* Hour */ || unit === "d" /* Day */ || unit === "wk" /* Week */ || unit === "mo" /* Month */ ? unit : void 0;
27593
- }
27594
- function mapFrequencyAdverb(token) {
27595
- return FREQUENCY_ADVERB_UNITS.get(token);
27596
- }
27597
- function parseNumericRange(token) {
27598
- const rangeMatch = token.match(/^([0-9]+(?:\.[0-9]+)?)[-–—]([0-9]+(?:\.[0-9]+)?)$/);
27599
- if (!rangeMatch) {
27600
- return void 0;
27601
- }
27602
- const low = parseFloat(rangeMatch[1]);
27603
- const high = parseFloat(rangeMatch[2]);
27604
- if (!Number.isFinite(low) || !Number.isFinite(high) || high < low) {
27605
- return void 0;
27606
- }
27607
- return { low, high };
27608
- }
27609
- function buildDurationScheduleFeature(value, unit, max) {
27610
- if (value === void 0 || !Number.isFinite(value) || value <= 0 || !unit) {
27611
- return void 0;
27612
- }
27613
- return {
27614
- duration: value,
27615
- durationMax: max !== void 0 && Number.isFinite(max) && max > value ? max : void 0,
27616
- durationUnit: unit
27617
- };
27618
- }
27619
-
27620
27701
  // src/hpsg/rule-context.ts
27621
27702
  function normalizeTokenLower(token) {
27622
27703
  var _a26;
@@ -27793,7 +27874,8 @@ function lexicalSign(args) {
27793
27874
  evidence: [
27794
27875
  {
27795
27876
  rule: args.rule,
27796
- tokenIndices
27877
+ tokenIndices,
27878
+ scheduleDefault: args.scheduleDefault
27797
27879
  }
27798
27880
  ],
27799
27881
  score: (_b3 = args.score) != null ? _b3 : 1
@@ -28079,6 +28161,7 @@ function separatedIntervalRule() {
28079
28161
  valence: {},
28080
28162
  cont: { clauseKind: "administration" }
28081
28163
  },
28164
+ scheduleDefault: directUnit === "d" /* Day */ ? "daily-frequency" : void 0,
28082
28165
  score: 9
28083
28166
  })
28084
28167
  ];
@@ -30819,6 +30902,28 @@ function anchoredModifierLeadsToResolvableSite(context, start) {
30819
30902
  }
30820
30903
  return false;
30821
30904
  }
30905
+ function relationIntroducesNonSiteComplement(context, index) {
30906
+ const token = context.tokens[index];
30907
+ if (!token) return false;
30908
+ const relations = resolveActionRelationSurfaceCandidates(normalizeTokenLower(token));
30909
+ if (!relations.length) return false;
30910
+ for (let cursor = index + 1; cursor < Math.min(context.limit, index + 4); cursor += 1) {
30911
+ const candidate = context.tokens[cursor];
30912
+ if (!candidate || context.state.consumed.has(candidate.index) || isPunctuation(normalizeTokenLower(candidate))) {
30913
+ break;
30914
+ }
30915
+ if (EVENT_TIMING_TOKENS[normalizeTokenLower(candidate)]) return true;
30916
+ }
30917
+ return false;
30918
+ }
30919
+ function coordinationStartsAction(context, index) {
30920
+ const token = context.tokens[index];
30921
+ if (!token || !ACTION_COORDINATION_CONNECTORS.has(normalizeTokenLower(token))) return false;
30922
+ const next = context.tokens[index + 1];
30923
+ return Boolean(
30924
+ next && !context.state.consumed.has(next.index) && resolveMedicationInstructionAction(normalizeTokenLower(next), context.options)
30925
+ );
30926
+ }
30822
30927
  function siteBoundary(lower, context) {
30823
30928
  var _a26, _b3, _c2;
30824
30929
  if (SITE_MULTIPLICITY_WORDS.has(lower)) {
@@ -30939,8 +31044,9 @@ function siteLexicalRule() {
30939
31044
  if (getDayOfWeekMeaning(candidate)) {
30940
31045
  break;
30941
31046
  }
31047
+ if (coordinationStartsAction(context, cursor)) break;
30942
31048
  const siteModifierCanBridgeBoundary = (SITE_SELF_DISPLAY_ANCHORS.has(candidateLower) || EXTERNAL_SITE_LOCATIVE_PREFIXES.has(candidateLower) || BODY_SITE_ATTRIBUTIVE_MODIFIERS.has(candidateLower)) && anchoredModifierLeadsToResolvableSite(context, cursor);
30943
- if (siteBoundary(candidateLower, context) && (isPunctuation(candidateLower) || !siteModifierCanBridgeBoundary)) {
31049
+ if ((siteBoundary(candidateLower, context) || relationIntroducesNonSiteComplement(context, cursor)) && (isPunctuation(candidateLower) || !siteModifierCanBridgeBoundary)) {
30944
31050
  const next = context.tokens[cursor + 1];
30945
31051
  const nextLower = next && !context.state.consumed.has(next.index) ? normalizeTokenLower(next) : void 0;
30946
31052
  const continuedText = nextLower ? [...displayTokens, next].map((part) => part.original).join(" ") : "";
@@ -4,6 +4,7 @@ export declare function refreshInstructionGraphDerivedState(graph: CanonicalInst
4
4
  export declare function buildInstructionGraph(input: string, clause: CanonicalSigClause, options?: ParseOptions): CanonicalInstructionGraph | undefined;
5
5
  export declare function realizeInstructionAction(frame: AdviceFrame, locale?: string): string;
6
6
  export declare function instructionGraphRepresentsText(graph: CanonicalInstructionGraph, text: string): boolean;
7
+ export declare function instructionGraphTextParticipatesInRelation(graph: CanonicalInstructionGraph, text: string): boolean;
7
8
  export declare function instructionGraphSingleActionRepresentsText(graph: CanonicalInstructionGraph, text: string): boolean;
8
9
  export declare function instructionGraphRichPrimaryAction(clause: CanonicalSigClause): AdviceFrame | undefined;
9
10
  export declare function instructionGraphPrimaryAdministrationModality(clause: CanonicalSigClause): AdviceModality | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezmedicationinput",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
4
4
  "description": "Parse concise medication sigs into FHIR R5 Dosage JSON",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -14,15 +14,6 @@
14
14
  "default": "./dist/index.js"
15
15
  }
16
16
  },
17
- "scripts": {
18
- "test:dist": "npm run build && vitest run test-dist",
19
- "build": "tsup && tsc -p tsconfig.types.json",
20
- "test": "vitest run --dir test",
21
- "bench:torture": "npm run build && node bench/real-world-torture.mjs",
22
- "bench:adversarial": "npm run build && node bench/adversarial.mjs",
23
- "bench:roundtrip": "npm run build && node bench/roundtrip.mjs",
24
- "bench:suggest": "npm run build && node --expose-gc bench/suggest.mjs"
25
- },
26
17
  "files": [
27
18
  "dist"
28
19
  ],
@@ -43,5 +34,14 @@
43
34
  "tsup": "^8.5.1",
44
35
  "typescript": "^5.4.0",
45
36
  "vitest": "^1.5.0"
37
+ },
38
+ "scripts": {
39
+ "test:dist": "npm run build && vitest run test-dist",
40
+ "build": "tsup && tsc -p tsconfig.types.json",
41
+ "test": "vitest run --dir test",
42
+ "bench:torture": "npm run build && node bench/real-world-torture.mjs",
43
+ "bench:adversarial": "npm run build && node bench/adversarial.mjs",
44
+ "bench:roundtrip": "npm run build && node bench/roundtrip.mjs",
45
+ "bench:suggest": "npm run build && node --expose-gc bench/suggest.mjs"
46
46
  }
47
- }
47
+ }