Ejemplo n.º 1
0
        protected override AtomGroup NewAtomGroup(AtomGroup.LogicalOperator logicalOperator, object[] content)
        {
            if (equivalents.Count == 0)
            {
                return(new AtomGroup(logicalOperator, content));
            }

            // if we have equivalent atoms, try to translate content into equivalent sub-groups
            ArrayList enrichedContent = new ArrayList();

            foreach (object atomOrAtomGroup in content)
            {
                if (atomOrAtomGroup is Atom)
                {
                    Atom      atom            = (Atom)atomOrAtomGroup;
                    ArrayList atomEquivalents = RulesUtil.GetAll(equivalents, atom, new ArrayList());

                    if (atomEquivalents.Count > 1)
                    {
                        if (logicalOperator == AtomGroup.LogicalOperator.Or)
                        {
                            // in an OR block, negative atoms are surrounded by AND
                            if (atom.Negative)
                            {
                                enrichedContent.Add(new AtomGroup(AtomGroup.LogicalOperator.And, atomEquivalents.ToArray()));
                            }
                            else
                            {
                                enrichedContent.AddRange(atomEquivalents);
                            }
                        }
                        else
                        {
                            // in an AND block, positive atoms are surrounded by OR
                            if (atom.Negative)
                            {
                                enrichedContent.AddRange(atomEquivalents);
                            }
                            else
                            {
                                enrichedContent.Add(new AtomGroup(AtomGroup.LogicalOperator.Or, atomEquivalents.ToArray()));
                            }
                        }
                    }
                    else
                    {
                        // add atoms that have found no equivalents
                        enrichedContent.AddRange(atomEquivalents);
                    }
                }
                else
                {
                    // directly add atom groups
                    enrichedContent.Add(atomOrAtomGroup);
                }
            }

            return(new AtomGroup(logicalOperator, content, enrichedContent.ToArray()));
        }
Ejemplo n.º 2
0
 protected virtual AtomGroup NewAtomGroup(AtomGroup.LogicalOperator logicalOperator, object[] content)
 {
     return(new AtomGroup(logicalOperator, content));
 }