Пример #1
0
        private object HandleConceptOrExpressionSlotInAttributeValue(
            TemplateInformationSlot infoSlot,
            ConceptReference attrName,
            OneOf <ConceptReplacementSlot, ExpressionReplacementSlot> valueSlot,
            IDictionary <string, TemplateData.Item> itemData,
            string lang
            )
        {
            var(attrTitle, attrDesc) = GetConceptOrSlotTitleAndDesc(infoSlot, attrName, itemData, lang);
            var result = new Dictionary <string, object>
            {
                ["attribute"] = attrName.SctId
            };

            result["title"] = attrTitle ?? throw new Exception($"No title specified for {attrName.SctId}");
            if (attrDesc != null)
            {
                result["description"] = attrDesc;
            }
            result["cardinality"] = new
            {
                min = infoSlot?.Cardinality?.MinCardinality ?? 1,
                max = infoSlot?.Cardinality?.MaxCardinality
            };
            result["value"] = GetConceptSlotJson(valueSlot.Handle(c => c.ExpressionConstraint, e => e.ExpressionConstraint));
            return(result);
        }
Пример #2
0
        private (string title, string desc) GetConceptOrSlotTitleAndDesc(
            TemplateInformationSlot info, IConceptReferenceOrSlot conceptOrSlot,
            IDictionary <string, TemplateData.Item> itemData,
            string lang)
        {
            var name = info?.SlotName;

            TemplateData.Item currentItem = null;
            if (name != null)
            {
                itemData.TryGetValue(name, out currentItem);
            }

            var title = currentItem?.Title[lang];
            var desc  = currentItem?.Description[lang];

            title ??= conceptOrSlot.Handle(c => c?.Term, cs => null, es => null);
            return(title, desc);
        }