/// <summary> /// Instantiates a new labelled Query based on an AtomGroup. /// </summary> /// <param name="label">The Label of the new Query.</param> /// <param name="atomGroup">The AtomGroup used in the new Query.</param> public Query(string label, AtomGroup atomGroup) { if ((null != label) && (String.Empty == label)) this.label = null; else this.label = label; this.atomGroup = atomGroup; }
/// <summary> /// Instantiates a new Implication. /// </summary> /// <param name="label">The label of the new implication.</param> /// <param name="priority">The priority of the new implication.</param> /// <param name="mutex">String.Empty or the label of an implication mutexed by the new one.</param> /// <param name="precondition">String.Empty or the label of an implication that preconditions the new one.</param> /// <param name="deduction">The Atom used as a prototype for what this Implication tries to proove.</param> /// <param name="atomGroup">The top level group of atoms used in the query part (pattern matching) of the new Implication.</param> /// <see cref="NxBRE.InferenceEngine.Rules.ImplicationPriority"/> public Implication(string label, ImplicationPriority priority, string mutex, string precondition, Atom deduction, AtomGroup atomGroup) : this(label, (int)priority, mutex, precondition, deduction, atomGroup) { }
/// <summary> /// Instantiates a new labelled Query based on an AtomGroup. /// </summary> /// <param name="label">The Label of the new Query.</param> /// <param name="atomGroup">The AtomGroup used in the new Query.</param> public Query(string label, AtomGroup atomGroup) { if ((null != label) && (String.Empty == label)) { this.label = null; } else { this.label = label; } this.atomGroup = atomGroup; }
/// <summary> /// Instantiates a new Implication. /// </summary> /// <param name="label">The label of the new implication.</param> /// <param name="priority">The priority of the new implication.</param> /// <param name="mutex">String.Empty or the label of an implication mutexed by the new one.</param> /// <param name="precondition">String.Empty or the label of an implication that preconditions the new one.</param> /// <param name="deduction">The Atom used as a prototype for what this Implication tries to proove.</param> /// <param name="atomGroup">The top level group of atoms used in the query part (pattern matching) of the new Implication.</param> /// <see cref="NxBRE.InferenceEngine.Rules.ImplicationPriority"/> public Implication(string label, int priority, string mutex, string precondition, Atom deduction, AtomGroup atomGroup) : this(label, priority, mutex, precondition, deduction, atomGroup, ImplicationAction.Assert) { }
/// <summary> /// Instantiates a new Implication. /// </summary> /// <param name="label">The label of the new implication.</param> /// <param name="priority">The priority of the new implication.</param> /// <param name="mutex">String.Empty or the label of an implication mutexed by the new one.</param> /// <param name="precondition">String.Empty or the label of an implication that preconditions the new one.</param> /// <param name="deduction">The Atom used as a prototype for what this Implication tries to proove.</param> /// <param name="atomGroup">The top level group of atoms used in the query part (pattern matching) of the new Implication.</param> /// <param name="action">The implication action.</param> /// <see cref="NxBRE.InferenceEngine.Rules.ImplicationAction"/> /// <see cref="NxBRE.InferenceEngine.Rules.ImplicationPriority"/> public Implication(string label, int priority, string mutex, string precondition, Atom deduction, AtomGroup atomGroup, ImplicationAction action) : base(label, atomGroup) { if (deduction.HasFunction) { throw new BREException("Can not create Implication with functions in the Deduction: " + deduction.ToString()); } if ((mutex != null) && (mutex == label)) { throw new BREException("An Implication can not Mutex itself: " + mutex); } if ((precondition != null) && (precondition == label)) { throw new BREException("An Implication can not Pre-Condition itself: " + precondition); } /* Commented out to solve bug #1469851 : this test was not necessary anymore as the engine can now handle typed data in implications * foreach(object member in AtomGroup.Members) * if ((member is Atom) && (((Atom)member).HasNotStringIndividual)) * throw new BREException("Can not create Implication with non-String individuals in the atoms: " + member.ToString()); */ if ((priority < (int)ImplicationPriority.Minimum) || (priority > (int)ImplicationPriority.Maximum)) { throw new ArgumentOutOfRangeException("Priority must be in the [" + ImplicationPriority.Minimum + "-" + ImplicationPriority.Maximum + "] range."); } if (action == ImplicationAction.Count) { if (deduction.IsFact) { throw new BREException("A counting Implication must have one Variable predicate in its deduction atom."); } var varCount = 0; foreach (var member in deduction.Members) { if (member is Variable) { varCount++; } if (varCount > 1) { throw new BREException("A counting Implication must have only one Variable predicate in its deduction atom."); } } } this.priority = priority; this.deduction = deduction; this.mutex = mutex; this.precondition = precondition; this.action = action; hasNaf = false; foreach (var atom in AtomGroup.AllAtoms.Where(atom => atom.Negative)) { hasNaf = true; break; } }
protected override void WriteAtomGroup(XmlElement target, AtomGroup atomGroup) { WriteAtomGroup(target, atomGroup, "And", "Or"); }
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()); }
/// <summary> /// Instantiates a new Implication. /// </summary> /// <param name="label">The label of the new implication.</param> /// <param name="priority">The priority of the new implication.</param> /// <param name="mutex">String.Empty or the label of an implication mutexed by the new one.</param> /// <param name="precondition">String.Empty or the label of an implication that preconditions the new one.</param> /// <param name="deduction">The Atom used as a prototype for what this Implication tries to proove.</param> /// <param name="atomGroup">The top level group of atoms used in the query part (pattern matching) of the new Implication.</param> /// <param name="action">The implication action.</param> /// <see cref="NxBRE.InferenceEngine.Rules.ImplicationAction"/> /// <see cref="NxBRE.InferenceEngine.Rules.ImplicationPriority"/> public Implication(string label, int priority, string mutex, string precondition, Atom deduction, AtomGroup atomGroup, ImplicationAction action) : base(label, atomGroup) { if (deduction.HasFunction) throw new BREException("Can not create Implication with functions in the Deduction: " + deduction.ToString()); if ((mutex != null) && (mutex == label)) throw new BREException("An Implication can not Mutex itself: " + mutex); if ((precondition != null) && (precondition == label)) throw new BREException("An Implication can not Pre-Condition itself: " + precondition); /* Commented out to solve bug #1469851 : this test was not necessary anymore as the engine can now handle typed data in implications foreach(object member in AtomGroup.Members) if ((member is Atom) && (((Atom)member).HasNotStringIndividual)) throw new BREException("Can not create Implication with non-String individuals in the atoms: " + member.ToString()); */ if ((priority < (int)ImplicationPriority.Minimum) || (priority > (int)ImplicationPriority.Maximum)) throw new ArgumentOutOfRangeException("Priority must be in the [" + ImplicationPriority.Minimum + "-" + ImplicationPriority.Maximum + "] range."); if (action == ImplicationAction.Count) { if (deduction.IsFact) throw new BREException("A counting Implication must have one Variable predicate in its deduction atom."); int varCount = 0; foreach(IPredicate member in deduction.Members) { if (member is Variable) varCount++; if (varCount > 1) throw new BREException("A counting Implication must have only one Variable predicate in its deduction atom."); } } this.priority = priority; this.deduction = deduction; this.mutex = mutex; this.precondition = precondition; this.action = action; hasNaf = false; foreach(Atom atom in AtomGroup.AllAtoms) { if (atom.Negative) { hasNaf = true; break; } } }
protected abstract void WriteAtomGroup(XmlElement target, AtomGroup atomGroup);
protected void WriteAtomGroup(XmlElement target, AtomGroup atomGroup, string andElement, string orElement) { if (atomGroup.Members.Length != 1) { XmlElement op = Document.CreateElement((atomGroup.Operator == AtomGroup.LogicalOperator.And)?andElement:orElement, DatalogNamespaceURL); target.AppendChild(op); for(int i=0; i<atomGroup.Members.Length; i++) { if (atomGroup.Members[i] is Atom) WriteAtom(op, (Atom)atomGroup.Members[i], false); else if (atomGroup.Members[i] is AtomGroup) WriteAtomGroup(op, (AtomGroup)atomGroup.Members[i]); } } else WriteAtom(target, (Atom)atomGroup.Members[0], false); }
protected virtual AtomGroup NewAtomGroup(AtomGroup.LogicalOperator logicalOperator, object[] content) { return new AtomGroup(logicalOperator, content); }
/// <summary> /// Instantiates a new anonymous (non-labelled) Query based on an AtomGroup. /// </summary> /// <param name="atomGroup">The AtomGroup used in the new Query.</param> public Query(AtomGroup atomGroup) : this(null, atomGroup) { }
public void AtomGroupMemberOrdering() { AtomGroup child = new AtomGroup(AtomGroup.LogicalOperator.Or, atom2_2, atomF); AtomGroup parent = new AtomGroup(AtomGroup.LogicalOperator.And, child, atom3); Assert.AreEqual(child, parent.Members[0], "First member match"); Assert.AreEqual(atom3, parent.Members[1], "Second member match"); }