Function: featureValueToInput()
@kortexya/reasoninglayer / featureValueToInput
Function: featureValueToInput()
Section titled “Function: 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.
Parameters
Section titled “Parameters”One value of a listed term’s features, in the engine’s
untagged read format.
Returns
Section titled “Returns”The equivalent FeatureInputValueDto, ready for addRule,
replaceRule or any other homoiconic write.
Remarks
Section titled “Remarks”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’sTypedvariant 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
Example
Section titled “Example”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.