Class DependentAllowedValues
- Namespace
- LMKit.Extraction
- Assembly
- LM-Kit.NET.dll
Constrains an element's allowed values by the value of a sibling element, so that only declared combinations can be produced. The typical shape is a two-level taxonomy: a category field whose value decides which subcategory values are valid.
public sealed class DependentAllowedValues
- Inheritance
-
DependentAllowedValues
- Inherited Members
Examples
var category = new TextExtractionElement("category", ElementType.String);
var subCategory = new TextExtractionElement("subCategory", ElementType.String);
var taxonomy = new DependentAllowedValues("category");
taxonomy.Add("Baggage", new[] { "Delay", "Damage", "Loss" });
taxonomy.Add("Flight Disruption", new[] { "Cancellation", "Delay", "Downgrade" });
subCategory.Format.DependentValues = taxonomy;
textExtraction.Elements = new List<TextExtractionElement> { category, subCategory };
Remarks
Assign an instance to DependentValues on the dependent element. The discriminator is the sibling element named by DiscriminatorName, and it must be declared immediately before the dependent element: the constraint is compiled into the generation grammar, which branches on the discriminator's literal value, so the two fields are generated as one unit and an undeclared combination cannot be produced.
The discriminator's own allowed values are the declared keys: when its AllowedValues is left unset it is constrained to the keys automatically, and when it is set it must match them exactly.
In a JSON schema, the same constraint is declared with standard draft-07 conditionals,
one allOf entry per discriminator value:
"allOf": [
{
"if": { "properties": { "category": { "const": "Baggage" } } },
"then": { "properties": { "subCategory": { "enum": ["Delay", "Damage", "Loss"] } } }
}
]
Constructors
- DependentAllowedValues(string)
Initializes a new instance keyed on the sibling element named
discriminatorName.
Properties
- DiscriminatorName
Gets the name of the sibling element whose value selects the allowed values.
- DiscriminatorValues
Gets the declared discriminator values, in declaration order.
Methods
- Add(string, IEnumerable<string>)
Declares the values allowed on the dependent element when the discriminator holds
discriminatorValue.
- GetAllowedValues(string)
Returns the values allowed under
discriminatorValue, ornullwhen that discriminator value is not declared.
- IsAllowed(string, string)
True when
discriminatorValueandvalueform a declared combination.