Skip to content

Function: featureValueToInput()

@kortexya/reasoninglayer


@kortexya/reasoninglayer / featureValueToInput

featureValueToInput(value): FeatureInputValueDto

Defined in: src/utils/convert.ts:256

Convert a LISTED feature value (as getRules(), a chaining answer or a fact listing returns it) into the input form a write takes.

FeatureValueDto

One value of a listed term’s features, in the engine’s untagged read format.

FeatureInputValueDto

The equivalent FeatureInputValueDto, ready for addRule, replaceRule or any other homoiconic write.

The read format and the write format differ, so a listed value cannot be sent back unchanged: the write normalizer takes camelCase { sortRef } / { termId } and refuses { sort_ref } with a ValidationError. The mapping:

  • {sort_ref, sort_name?} → { sortRef } (the engine ignores the name)
  • {term_id, var_name} → { termId } (the same variable term)
  • {term_id, literal} → the literal’s own input value (the scalar)
  • an inlined term {term_id, sort_id, …} → { termId } (the same template)
  • {term_id} → { termId }
  • an array → each element converted
  • null → { type: 'Uninstantiated' }, the tagged envelope the engine’s Typed variant takes
  • a string that starts with ? → { type: 'String', value }. A listed rule reports a variable as {term_id, var_name}, never as a bare string, so a bare "?x" is a string constant; sent back bare, the engine’s write path would read it as a variable. The typed envelope keeps it a constant.
  • any other string, a number or a boolean → itself
import { featureValueToInput } from '@kortexya/reasoninglayer';
const { rules } = await client.inference.getRules();
const head = rules[0].head;
const features = Object.fromEntries(
Object.entries(head.features).map(([name, v]) => [name, featureValueToInput(v)]),
);
// features.of === { sortRef: '…' } when the head named a sort.