예제 #1
0
 /* Fact Utils */
 /// <summary>
 /// Populates the Variable predicates of a target Atom, using another Atom as a template
 /// and a Fact as the source of data, i.e. Individual predicates.
 /// </summary>
 /// <param name="data">The data for populating the Atom.</param>
 /// <param name="template">The template of Atom being populated.</param>
 /// <param name="members">The members to populate.</param>
 internal static void Populate(Fact data, Atom template, IPredicate[] members)
 {
     for(int i=0;i<members.Length;i++)
         if (members[i] is Variable) {
             // try to locate a Variable with the same name in the template
             int j = Array.IndexOf(template.Members, members[i]);
             if (j >= 0) {
                 members[i] = data.Members[j];
             }
             else {
                 // try to locate a Slot with the same name in the template
                 j = Array.IndexOf(template.SlotNames, members[i].Value);
                 if (j >= 0) members[i] = data.Members[j];
             }
         }
 }
예제 #2
0
 /// <summary>
 /// Retracts (removes) a Fact from the current working memory.
 /// </summary>
 /// <param name="fact">The Fact to retract.</param>
 public void Retract(Fact fact)
 {
     IE.Retract(fact);
 }
예제 #3
0
 /// <summary>
 /// Modify a Fact by Retracting it and Asserting the replacement one.
 /// If the new Fact has no label (null or Empty), then the Label of the existing fact is kept.
 /// </summary>
 /// <param name="currentFactLabel">The label of the Fact to modify.</param>
 /// <param name="newFact">The Fact to modify to.</param>
 /// <returns>True if <term>currentFact</term> has been retracted from the FactBase, otherwise False ; this whether <term>newFact</term> already exists in the factbase, or not.</returns>
 public bool Modify(string currentFactLabel, Fact newFact)
 {
     return IE.Modify(currentFactLabel, newFact);
 }
예제 #4
0
 /// <summary>
 /// Returns true if a Fact exists in the current working memory.
 /// </summary>
 /// <param name="fact">The Fact to check existence.</param>
 /// <returns>True if the Fact exists.</returns>
 public bool FactExists(Fact fact)
 {
     return IE.FactExists(fact);
 }
예제 #5
0
 protected override void WriteFact(XmlElement target, Fact fact)
 {
     XmlElement eFact = Document.CreateElement("fact", DatalogNamespaceURL);
     WriteLabel(eFact, fact.Label);
     XmlElement head = Document.CreateElement("_head", DatalogNamespaceURL);
     WriteAtom(head, fact, true);
     eFact.AppendChild(head);
     target.AppendChild(eFact);
 }
        public virtual void SimilarNafMatching()
        {
            // regression test for bug 1332214
            ie.LoadRuleBase(NewTestAdapter());

            Assert.IsTrue(ie.Assert(new Fact("naf-probe",
                                             new Individual(123),
                                             new Individual("bar"))), "Asserted naf-probe");

            Assert.IsTrue(ie.Assert(new Fact("naf-switch",
                                             new Individual(123),
                                             new Individual("pivot"),
                                             new Individual("baz"))), "Asserted first naf-switch");

            Fact switchToKill = new Fact("naf-switch",
                                     new Individual(123),
                                     new Individual("pivot"),
                                     new Individual("foo"));

            Assert.IsTrue(ie.Assert(switchToKill), "Asserted second naf-switch");

            Process();

            Assert.AreEqual(0, deducted, "Deducted");

            Assert.IsTrue(ie.Retract(switchToKill));

            Process();

            Assert.AreEqual(1, deducted, "Deducted");
        }
        public void MutexSupport()
        {
            ie.LoadRuleBase(NewTestAdapter());
            Fact locker = new Fact("locker", "flag", new Individual("lock"), new Individual("mutexLock"));
            ie.Assert(locker);
            ie.Assert(new Fact("flag", new Individual("probe"), new Individual("triggeredA")));
            ie.Assert(new Fact("flag", new Individual("probe"), new Individual("triggeredB")));
            Process();
            Assert.AreEqual(1, deducted, "(1) Deducted");

            // no garantee if A or B is deducted because they implications have same priority level
            ie.Retract(locker);
            Process();
            Assert.AreEqual(1, deducted, "(2) Deducted");

            // C should be deducted
            ie.Assert(new Fact("flag", new Individual("probe"), new Individual("triggeredC")));
            deductionsToCheck = new string[] {"mutexC{probe}"};
              	NewFactEvent honf = new NewFactEvent(HandleOrderedNewFact);
              	ie.NewFactHandler += honf;
            Process();
            Assert.AreEqual(1, deducted, "(3) Deducted");
            Assert.IsFalse(wrongDeduction, "Deductions OK");
              	ie.NewFactHandler -= honf;
              	deductionsToCheck = null;

            // nothing must be rededucted as
            Process();
            Assert.AreEqual(0, deducted, "(3) Deducted");
        }
        public void FactExistence()
        {
            ie.LoadRuleBase(NewTestAdapter());
            Assert.IsTrue(ie.FactExists("Porsche Luxury"), "Existing fact label");
            Assert.IsFalse(ie.FactExists("Porsche Regular"), "Non-existing fact label");

            Fact factHondaRegular = new Fact("regular", new Individual("Honda"));
            Fact factHondaLuxury = new Fact("luxury", new Individual("Honda"));
            Assert.IsTrue(ie.FactExists(factHondaRegular), "Existing fact");
            Assert.IsFalse(ie.FactExists(factHondaLuxury), "Non-existing fact");
        }
예제 #9
0
        private void CommonDiscountVisio2003(IRuleBaseAdapter rba)
        {
            ie.LoadRuleBase(rba);
            Process();
            Assert.AreEqual(3, deducted, "(1) Deducted");
            Assert.AreEqual(6, ie.FactsCount, "(2) Total Facts Count");

            deductionsToCheck = new string[] {"Discount{Peter Miller,Honda,5.0}",
                                                                                "Discount{Peter Miller,Porsche,7.5}"};

            qrs = ie.RunQuery(new Query(new AtomGroup(AtomGroup.LogicalOperator.And,
                                                      new Atom("Discount", new Variable("customer"),
                                                                              				 new Variable("product"),
                                                                              				 new Variable("amount")))));

            Assert.AreEqual(2, qrs.Count, "(1) Query Result Size");
            ParseResult();
            Assert.IsFalse(wrongDeduction, "(1) Query Results");

            // Spending JQDoe
            Assert.IsTrue(ie.Assert(new Fact("Spending",
                                  new Individual("John Q. Doe"),
                     						  new Individual(2004),
                     						  new Individual(123.45f))),
                     		"jqdoeSpending asserted");

            Fact jqdoePremiumRating = new Fact("Customer Rating",
                                               new Individual("John Q. Doe"),
                                               new Individual("Premium"));

            Assert.IsTrue(ie.Assert(jqdoePremiumRating), "jqdoePremiumRating asserted");

            // SpendingJDupont
            Assert.IsTrue(ie.Assert(new Fact("Spending",
                                        new Individual("Jean Dupont"),
                         						new Individual(2004),
                         						new Individual(3245.25f))),
                     		"jdupontSpending asserted");

            Process();

            Assert.IsFalse(ie.FactExists(jqdoePremiumRating), "jqdoePremiumRating was retracted");

            Assert.AreEqual(4, deducted, "(2) Deducted");
            Assert.AreEqual(12, ie.FactsCount, "(2) Total Facts Count");

            // Run named queries
            deductionsToCheck = new string[] {"Discount{Peter Miller,Honda,5.0}",
                                                                                "Discount{Peter Miller,Porsche,7.5}",
                                                                                "Discount{Jean Dupont,Honda,5.0}",
                                                                                "Discount{Jean Dupont,Porsche,7.5}"};
            qrs = ie.RunQuery("Calculated Discounts");
            Assert.AreEqual(4, qrs.Count, "(2) Query Result Size");
            ParseResult();
            Assert.IsFalse(wrongDeduction, "(2) Query Results");

            deductionsToCheck = new string[] {"Customer Rating{Peter Miller,Premium}",
                                                                                "Customer Rating{John Q. Doe,Regular}",
                                                                                "Customer Rating{Jean Dupont,Premium}"};
            qrs = ie.RunQuery("Customer Ratings");
            Assert.AreEqual(3, qrs.Count, "(3) Query Result Size");
            ParseResult();
            Assert.IsFalse(wrongDeduction, "(3) Query Results");
        }
예제 #10
0
        public void Discount()
        {
            ie.LoadRuleBase(new RuleML08DatalogAdapter(ruleFilesFolder + "discount.ruleml", FileAccess.Read));

            Process();
            Assert.AreEqual(3, deducted, "(1) Deducted");
            Assert.AreEqual(6, ie.FactsCount, "(1) Total Facts Count");

            deductionsToCheck = new string[] {"discount{Peter Miller,Honda,5.0 percent}",
                                                                                "discount{Peter Miller,Porsche,7.5 percent}"};
            qrs = ie.RunQuery(new Query(new AtomGroup(AtomGroup.LogicalOperator.And,
                                                      new Atom("discount", new Variable("customer"),
                                                                              				 new Variable("product"),
                                                                              				 new Variable("amount")))));
            Assert.AreEqual(2, qrs.Count, "(1) Query Result Size");
            ParseResult();
            Assert.IsFalse(wrongDeduction, "(1) Query Results");

            // Fact 4 - this is a bummer
            Fact fact4 = new Fact("bummer",
                            "spending",
                            new Individual("John Q. Doe"),
               						  new Individual("min 5000 euro"),
               						  new Individual("previous year"),
               						  new Individual("current year"));
            ie.Assert(fact4);

            // Fact 5
            ie.Assert(new Fact("spending",
                                new Individual("Jean Dupont"),
                 						new Individual("min 5000 euro"),
                 						new Individual("previous year")));

            Process();

            Assert.AreEqual(3, deducted, "(2) Deducted");
            Assert.AreEqual(11, ie.FactsCount, "(2) Total Facts Count");

            // Run anonymous (not named) query
            deductionsToCheck = new string[] {"discount{Peter Miller,Honda,5.0 percent}",
                                                                                "discount{Peter Miller,Porsche,7.5 percent}",
                                                                                "discount{Jean Dupont,Honda,5.0 percent}",
                                                                                "discount{Jean Dupont,Porsche,7.5 percent}"};
            qrs = ie.RunQuery(0);
            Assert.AreEqual(4, qrs.Count, "(2) Query Result Size");
            ParseResult();
            Assert.IsFalse(wrongDeduction, "(2) Query Results");
        }
예제 #11
0
 protected abstract void WriteFact(XmlElement target, Fact fact);
예제 #12
0
 /// <summary>
 /// Instantiates a new Fact event definition.
 /// </summary>
 /// <remarks>
 /// DO NOT ASSERT OR RETRACT FACTS WHEN HANDLING THIS EVENT!
 /// </remarks>
 /// <param name="fact">The Fact that generated the event.</param>
 /// <param name="otherFact">The Other Fact that generated the event.</param>
 /// <param name="context">The context of the event.</param>
 public NewFactEventArgs(Fact fact, Fact otherFact, IEventContext context)
 {
     this.fact = fact;
     this.otherFact = otherFact;
     this.context = context;
 }
예제 #13
0
 /// <summary>
 /// Instantiates a new Fact event definition.
 /// </summary>
 /// <remarks>
 /// DO NOT ASSERT OR RETRACT FACTS WHEN HANDLING THIS EVENT!
 /// </remarks>
 /// <param name="fact">The Fact that generated the event.</param>
 /// <param name="otherFact">The Other Fact that generated the event.</param>
 public NewFactEventArgs(Fact fact, Fact otherFact)
     : this(fact, otherFact, null)
 {
 }
예제 #14
0
 /// <summary>
 /// Instantiates a new Fact event definition.
 /// </summary>
 /// <remarks>
 /// DO NOT ASSERT OR RETRACT FACTS WHEN HANDLING THIS EVENT!
 /// </remarks>
 /// <param name="fact">The Fact that generated the event.</param>
 /// <param name="context">The context of the event.</param>
 public NewFactEventArgs(Fact fact, IEventContext context)
     : this(fact, null, context)
 {
 }
예제 #15
0
 /// <summary>
 /// Instantiates a new Fact event definition.
 /// </summary>
 /// <remarks>
 /// DO NOT ASSERT OR RETRACT FACTS WHEN HANDLING THIS EVENT!
 /// </remarks>
 /// <param name="fact">The Fact that generated the event.</param>
 public NewFactEventArgs(Fact fact)
     : this(fact, null, null)
 {
 }
예제 #16
0
 private Fact(Fact source, IPredicate[] members) : base(source, members)
 {
     this.label = source.label;
 }
예제 #17
0
파일: IEImpl.cs 프로젝트: plamikcho/xbrlpoc
 /// <summary>
 /// Retracts (removes) a Fact from the current working memory.
 /// </summary>
 /// <param name="fact">The Fact to retract.</param>
 /// <returns>True if the Fact has been retracted from the FactBase, otherwise False.</returns>
 public bool Retract(Fact fact)
 {
     CheckInitialized();
     return WM.FB.Retract(fact);
 }
예제 #18
0
 /// <summary>
 /// Prepare the atom to be pattern matched by replacing in a fact:
 /// -  all the predicates that match function predicates in the passed atom with 
 ///   the string representation of these function predicates,
 /// -  all the predicates that match individual predicates in the passed atom with 
 ///   the string representation of these individual predicates.
 /// </summary>
 /// <remarks>
 /// This operation must be done *if and only if* the fact matches the atom.
 /// </remarks>
 /// <param name="factToResolve">The fact that must be resolved.</param>
 /// <param name="atom">The atom with which the current fact matches.</param>
 /// <returns>A new fact with only String individuals.</returns>
 internal static Fact Resolve(Fact factToResolve, Atom atom)
 {
     return Resolve(true, factToResolve, atom);
 }
        public void ImplicationModifySupport()
        {
            ie.LoadRuleBase(NewTestAdapter());

            Assert.IsTrue(ie.Assert(new Fact("modifyTrigger",
                                             new Individual("foo"),
                                             new Individual("bar"))), "Asserted trigger fact");

              	ie.NewWorkingMemory(WorkingMemoryTypes.Isolated);
            Process();
            Assert.AreEqual(0, deducted, "(1) Deducted");

            deductionsToCheck = new string[] {"modifyTarget{bar,after}"};

              	// test with non labeled fact
              	ie.NewWorkingMemory(WorkingMemoryTypes.Isolated);

            Fact toModify = new Fact("modifyTarget",
                               new Individual("bar"),
                               new Individual("before"));

            Assert.IsFalse(ie.FactExists(toModify), "(2) Target fact not present");
            Assert.IsTrue(ie.Assert(toModify), "(2) Asserted target fact");
            Assert.IsTrue(ie.FactExists(toModify), "(2) Target fact present");
            int initialFactsCount = ie.FactsCount;
            Process();
            Assert.AreEqual(initialFactsCount, ie.FactsCount, "(2) Stable FactsCount");
            Assert.AreEqual(0, deducted, "(2) Deducted");
            Assert.AreEqual(0, deleted, "(2) Deleted");
            Assert.AreEqual(1, modified, "(2) Modified");
            Assert.IsFalse(ie.FactExists(toModify), "(2) Target fact retracted");

              	// test with labeled fact
              	ie.NewWorkingMemory(WorkingMemoryTypes.Isolated);

              	string label = "label of modifyTarget";
            toModify = new Fact(label,
                          "modifyTarget",
                          new Individual("bar"),
                          new Individual("before"));

            Assert.IsFalse(ie.FactExists(toModify), "(3) Target fact not present");
            Assert.IsFalse(ie.FactExists(label), "(3) Target fact label not present");
            Assert.IsTrue(ie.Assert(toModify), "(3) Asserted target fact");
            Assert.IsTrue(ie.FactExists(toModify), "(3) Target fact present");
            Assert.IsTrue(ie.FactExists(label), "(3) Target fact label present");
            initialFactsCount = ie.FactsCount;
            Process();
            Assert.AreEqual(initialFactsCount, ie.FactsCount, "(3) Stable FactsCount");
            Assert.AreEqual(0, deducted, "(3) Deducted");
            Assert.AreEqual(0, deleted, "(3) Deleted");
            Assert.AreEqual(1, modified, "(3) Modified");
            Assert.IsFalse(ie.FactExists(toModify), "(3) Target fact retracted");
            Assert.IsTrue(ie.FactExists(label), "(3) Target fact label present");
        }
예제 #20
0
        /// <summary>
        /// Prepare the atom to be pattern matched by replacing in a fact:
        /// -  all the predicates that match function predicates in the passed atom with 
        ///   the string representation of these function predicates,
        /// -  in fully mode, all the predicates that match individual predicates in the passed atom with 
        ///   the string representation of these individual predicates.
        /// </summary>
        /// <remarks>
        /// This operation must be done *if and only if* the fact matches the atom.
        /// </remarks>
        /// <param name="fully">Forces resolution of non-string individual to String.</param>
        /// <param name="factToResolve">The fact that must be resolved.</param>
        /// <param name="atom">The atom with which the current fact matches.</param>
        /// <returns>A new fact with only String individuals.</returns>
        internal static Fact Resolve(bool fully, Fact factToResolve, Atom atom)
        {
            IPredicate[] predicates = new IPredicate[factToResolve.Members.Length];

            for(int i=0; i<factToResolve.Members.Length; i++) {
                if ((atom.Members[i] is Function)
                        || ((fully) && (atom.Members[i] is Individual) && (!(factToResolve.Members[i].Value is System.String)))) {
                    predicates[i] = new Individual(atom.Members[i].ToString());
                }
                else {
                    predicates[i] = factToResolve.Members[i];
                }
            }

            return (Fact)factToResolve.CloneWithNewMembers(predicates);
        }
        public void RetractingImplication()
        {
            ie.LoadRuleBase(NewTestAdapter());

            Fact factToRetract = new Fact("toRetract", new Individual("easy target"));
            Assert.IsFalse(ie.FactExists(factToRetract), "1st Pre-check before target assertion");
            ie.Assert(factToRetract);
            Assert.IsTrue(ie.FactExists(factToRetract), "2nd Pre-check before target assertion");

            // this process should leave the target unchanged
            Process();
            Assert.IsTrue(ie.FactExists(factToRetract), "1st process: fact unchanged");
            Assert.AreEqual(0, deleted, "1st process: deleted");
            Assert.AreEqual(0, deducted, "1st process: deleted");

            // after asserting the trigger, process should retract the target
            Fact factRetractionTrigger = new Fact("retractionTrigger", new Individual("easy target"));
            Fact factRetractionConfirmation = new Fact("retractionConfirmation", new Individual("easy target"));
            ie.Assert(factRetractionTrigger);
            Process();
            Assert.IsFalse(ie.FactExists(factToRetract), "2nd process: fact retracted");
            Assert.IsTrue(ie.FactExists(factRetractionConfirmation), "2nd process: retracting implication positive pre-conditionned");
            Assert.AreEqual(1, deleted, "2nd process: deleted");
            Assert.AreEqual(1, deducted, "2nd process: deducted");
        }
예제 #22
0
파일: IEImpl.cs 프로젝트: plamikcho/xbrlpoc
        private int RunImplication(Implication implication)
        {
            int implicationResultsCount = 0;

            IList<IList<FactBase.PositiveMatchResult>> processResults = WM.FB.ProcessAtomGroup(implication.AtomGroup);

            if (implication.Action == ImplicationAction.Count)
            {
                if (Logger.IsInferenceEngineVerbose) Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, "Counting Implication '" + implication.Label + "' counted: " + processResults.Count);

                bool variableFound = false;
                IPredicate[] members = (IPredicate[])implication.Deduction.Members.Clone();
                for(int i=0; !variableFound && i<members.Length; i++) {
                    if (members[i] is Variable) {
                        members[i] = new Individual(processResults.Count);
                        variableFound = true;
                        break;
                    }
                }

                if ((strictImplication) && (!variableFound))
                    throw new BREException("Strict counting implication rejected the assertion due to lack of variable predicate: " + implication.Deduction);

                Fact deductedFact = new Fact(implication.Deduction.Type, members);
                implicationResultsCount++;

                // counting implication factbase action
                bool result = WM.FB.Assert(deductedFact);

                if ((result) && (NewFactHandler != null)) {
                    if (exposeEventContext) {
                        NewFactHandler(new NewFactEventArgs(deductedFact,
                                                            EventContextFactory.NewEventContext(processResults, implication)));
                    } else {
                        NewFactHandler(new NewFactEventArgs(deductedFact));
                    }
                }

                if (Logger.IsInferenceEngineVerbose) {
                    Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, (result?"Asserted":"Ignored Assertion of ") + " Fact: " + deductedFact.ToString());
                }
            }
            else if ((implication.Action == ImplicationAction.Assert)
              		|| (implication.Action == ImplicationAction.Retract))
            {
                // loop on each result and try to build a new fact out of the predicates coming for each result
                foreach(IList<FactBase.PositiveMatchResult> processResult in processResults) {
                    Fact deductedFact = BuildFact(implication.Deduction, processResult);

                    if (deductedFact != null) {
                        implicationResultsCount++;

                        if (implication.Action == ImplicationAction.Retract) {
                            // retracting implication factbase action
                            bool result = WM.FB.Retract(deductedFact);

                            if ((result) && (DeleteFactHandler != null)) {
                                if (exposeEventContext) {
                                    DeleteFactHandler(new NewFactEventArgs(deductedFact,
                                                                           EventContextFactory.NewEventContext(processResult, implication)));
                                } else {
                                    DeleteFactHandler(new NewFactEventArgs(deductedFact));
                                }
                            }

                            if (Logger.IsInferenceEngineVerbose) {
                                Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, (result?"Retracted":"Ignored Retraction of ") + " Fact: " + deductedFact.ToString());
                            }
                        }
                        else {
                            // asserting implication factbase action
                            bool result = WM.FB.Assert(deductedFact);

                            if ((result) && (NewFactHandler != null)) {
                                if (exposeEventContext) {
                                    NewFactHandler(new NewFactEventArgs(deductedFact,
                                                                        EventContextFactory.NewEventContext(processResult, implication)));
                                } else {
                                    NewFactHandler(new NewFactEventArgs(deductedFact));
                                }
                            }

                            if (Logger.IsInferenceEngineVerbose) {
                                Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, (result?"Asserted":"Ignored Assertion of ") + " Fact: " + deductedFact.ToString());
                            }
                        }
                    }
                }
            }
            else if (implication.Action == ImplicationAction.Modify)
            {
              foreach(IList<FactBase.PositiveMatchResult> processResult in processResults) {
                  // look for facts to modify by:
                  //  - resolving variable predicates of the deduction
                  //  - replacing formulas with variables
                  // and performing a search in the fact base
                  Atom modificationTargetLookup = FactBase.BuildQueryFromDeduction(implication.Deduction, processResult);

                  if (Logger.IsInferenceEngineVerbose) Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, "Modifying Implication '" + implication.Label + "' will target matches of: " + modificationTargetLookup);

                 	foreach(Fact factToModify in FactBase.ExtractAllFacts(WM.FB.ProcessAtomGroup(new AtomGroup(AtomGroup.LogicalOperator.And, modificationTargetLookup)))) {
                      if (Logger.IsInferenceEngineVerbose) Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, "-> found target: " + factToModify);

                      // for each fact, perform the modification
                  	Fact deductedFact = BuildFact(implication.Deduction,
                  	                              FactBase.EnrichResults(processResult, modificationTargetLookup, factToModify));

                      if (Logger.IsInferenceEngineVerbose) Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, "-> modified target: " + deductedFact);

                      if ((deductedFact != null) && (!factToModify.Equals(deductedFact))) {
                            implicationResultsCount++;
                            bool result = WM.FB.Modify(factToModify, deductedFact);

                            if ((result) && (ModifyFactHandler != null)) {
                                if (exposeEventContext) {
                                    ModifyFactHandler(new NewFactEventArgs(factToModify,
                                                                           deductedFact,
                                                                           EventContextFactory.NewEventContext(processResult, implication)));
                                } else {
                                    ModifyFactHandler(new NewFactEventArgs(factToModify, deductedFact));
                                }
                            }

                            if (Logger.IsInferenceEngineVerbose) {
                                Logger.InferenceEngineSource.TraceEvent(TraceEventType.Verbose, 0, (result?"Modified":"Ignored Modification of ") + " Fact: " + factToModify.ToString());
                            }
                        }
                  }
                }
            }
            else {
                throw new BREException("Implication action not supported: " + implication.Action);
            }

            return implicationResultsCount;
        }
예제 #23
0
파일: Fact.cs 프로젝트: plamikcho/xbrlpoc
 private Fact(Fact source, IPredicate[] members)
     : base(source, members)
 {
     this.label = source.label;
 }
예제 #24
0
파일: IEImpl.cs 프로젝트: plamikcho/xbrlpoc
 /// <summary>
 /// Asserts (adds) a Fact in the current working memory.
 /// </summary>
 /// <param name="fact">The Fact to assert.</param>
 /// <returns>True if the Fact was added to the Fact Base, i.e. if it was really new!</returns>
 public bool Assert(Fact fact)
 {
     CheckInitialized();
     return WM.FB.Assert(fact);
 }
예제 #25
0
 protected override void WriteFact(XmlElement target, Fact fact)
 {
     if (syntax == SaveFormatAttributes.Expanded) {
         XmlElement formula = Document.CreateElement("formula", DatalogNamespaceURL);
         WriteAtom(formula, fact, true);
         target.AppendChild(formula);
     }
     else {
         WriteAtom(target, fact, true);
     }
 }
예제 #26
0
파일: IEImpl.cs 프로젝트: plamikcho/xbrlpoc
 /// <summary>
 /// Returns true if a Fact exists in the current working memory.
 /// </summary>
 /// <param name="fact">The Fact to check existence.</param>
 /// <returns>True if the Fact exists.</returns>
 public bool FactExists(Fact fact)
 {
     CheckInitialized();
     return WM.FB.Exists(fact);
 }
예제 #27
0
 /// <summary>
 /// Modify a Fact by Retracting it and Asserting the replacement one.
 /// If the new Fact has no label (null or Empty), then the Label of the existing fact is kept.
 /// </summary>
 /// <param name="currentFact">The Fact to modify.</param>
 /// <param name="newFact">The Fact to modify to.</param>
 /// <returns>True if <term>currentFact</term> has been retracted from the FactBase, otherwise False ; this whether <term>newFact</term> already exists in the factbase, or not.</returns>
 public bool Modify(Fact currentFact, Fact newFact)
 {
     return IE.Modify(currentFact, newFact);
 }
예제 #28
0
파일: IEImpl.cs 프로젝트: plamikcho/xbrlpoc
 /// <summary>
 /// Modify a Fact by Retracting it and Asserting the replacement one.
 /// If the new Fact has no label (null or Empty), then the Label of the existing fact is kept.
 /// </summary>
 /// <param name="currentFact">The Fact to modify.</param>
 /// <param name="newFact">The Fact to modify to.</param>
 /// <returns>True if <term>currentFact</term> has been retracted from the FactBase, otherwise False ; this whether <term>newFact</term> already exists in the factbase, or not.</returns>
 public bool Modify(Fact currentFact, Fact newFact)
 {
     CheckInitialized();
     return WM.FB.Modify(currentFact, newFact);
 }
예제 #29
0
        /// <summary>
        /// Creates a new Fact.
        /// </summary>
        /// <remarks>
        /// This method is an helper of the regular Fact instantiation.
        /// </remarks>
        /// <param name="type">The Type of the new Fact to assert.</param>
        /// <param name="individuals">The Individual predicatesthat the Fact will contain.</param>
        /// <returns>A new Fact of desired Type and individuals.</returns>
        public Fact NewFact(string type, params object[] individuals)
        {
            Fact newFact;

            if (individuals.Length == 0) {
                newFact = new Fact(type);
            }
            else if (individuals.Length == 1) {
                newFact = new Fact(type, new Individual(individuals[0]));
            }
            else {
                Individual[] members = new Individual[individuals.Length];
                for (int i=0; i<individuals.Length; i++) members[i] = new Individual(individuals[i]);
                newFact = new Fact(type, members);
            }

            return newFact;
        }
예제 #30
0
파일: IEImpl.cs 프로젝트: plamikcho/xbrlpoc
        /// <summary>
        /// Modify a Fact by Retracting it and Asserting the replacement one.
        /// If the new Fact has no label (null or Empty), then the Label of the existing fact is kept.
        /// </summary>
        /// <param name="currentFactLabel">The label of the Fact to modify.</param>
        /// <param name="newFact">The Fact to modify to.</param>
        /// <returns>True if <term>currentFact</term> has been retracted from the FactBase, otherwise False ; this whether <term>newFact</term> already exists in the factbase, or not.</returns>
        public bool Modify(string currentFactLabel, Fact newFact)
        {
            Fact currentFact = GetFact(currentFactLabel);

            if (currentFact != null) {
                return WM.FB.Modify(currentFact, newFact);
            }
            else {
                return false;
            }
        }
예제 #31
0
 /// <summary>
 /// Asserts (adds) a Fact in the current working memory.
 /// </summary>
 /// <param name="fact">The Fact to assert.</param>
 /// <returns>True if the Fact was added to the Fact Base, i.e. if it was really new!</returns>
 public bool Assert(Fact fact)
 {
     return IE.Assert(fact);
 }
예제 #32
0
 private Fact(Fact source, IPredicate[] members) : base(source.Label, source, members)
 {
 }