Ejemplo n.º 1
0
        GroupElement IBuilder <GroupElement> .Build()
        {
            Validate();
            var childElements = new List <RuleLeftElement>();

            foreach (var nestedBuilder in _nestedBuilders)
            {
                RuleLeftElement childElement = nestedBuilder.Build();
                childElements.Add(childElement);
            }
            GroupElement groupElement;

            switch (_groupType)
            {
            case GroupType.And:
                groupElement = new AndElement(childElements);
                break;

            case GroupType.Or:
                groupElement = new OrElement(childElements);
                break;

            case GroupType.Not:
                groupElement = new NotElement(childElements);
                break;

            case GroupType.Exists:
                groupElement = new ExistsElement(childElements);
                break;

            default:
                throw new InvalidOperationException(string.Format("Unrecognized group type. GroupType={0}", _groupType));
            }
            return(groupElement);
        }
Ejemplo n.º 2
0
        protected internal override void VisitExists(Context context, ExistsElement element)
        {
            var source = Transform <RuleLeftElement>(context, element.Source);

            if (context.IsModified)
            {
                var newElement = new ExistsElement(element.Declarations, source);
                Result(context, newElement);
            }
        }
Ejemplo n.º 3
0
        protected internal override void VisitExists(Context context, ExistsElement element)
        {
            var source = Transform <RuleElement>(context, element.Source);

            if (context.IsModified)
            {
                var newElement = Element.Exists(source);
                Result(context, newElement);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates an element that represents an existential quantifier.
        /// </summary>
        /// <param name="source">Source element to apply the existential quantifier to.</param>
        /// <returns>Created element.</returns>
        /// <see cref="RuleLeftElement"/>
        public static ExistsElement Exists(RuleLeftElement source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source), "Source element not provided");
            }

            var element = new ExistsElement(source);

            return(element);
        }
Ejemplo n.º 5
0
        protected override void VisitExists(ReteBuilderContext context, ExistsElement element)
        {
            BuildSubnet(context, element.ChildElements.Single());
            var betaNode = new ExistsNode(context.BetaSource, context.AlphaSource);

            if (context.HasSubnet)
            {
                betaNode.Conditions.Add(new SubnetCondition());
            }
            context.BetaSource = BuildBetaMemoryNode(context, betaNode);
            context.ResetAlphaSource();
        }
Ejemplo n.º 6
0
        public static void ValidateExists(ExistsElement element)
        {
            switch (element.Source.ElementType)
            {
            case ElementType.Pattern:
            case ElementType.And:
            case ElementType.Or:
                break;

            default:
                throw new ArgumentException($"Invalid source element. ElementType={element.Source.ElementType}");
            }
        }
Ejemplo n.º 7
0
 protected internal virtual void VisitExists(TContext context, ExistsElement element)
 {
     element.Source.Accept(context, this);
 }
Ejemplo n.º 8
0
 protected override void VisitExists(ReteBuilderContext context, ExistsElement element)
 {
     VisitSource(context, element, element.Source);
     BuildExistsNode(context, element);
 }
Ejemplo n.º 9
0
 protected internal virtual void VisitExists(TContext context, ExistsElement element)
 {
     VisitGroup(context, element);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds an existential element to the group element.
        /// </summary>
        /// <param name="element">Element to add.</param>
        public void Exists(ExistsElement element)
        {
            var builder = BuilderAdapter.Create(element);

            _nestedBuilders.Add(builder);
        }