Beispiel #1
0
 /// <summary>
 /// Runs a new Query in the current working memory.
 /// </summary>
 /// <remarks>
 /// For performance reasons, it is recommended to declare all queries in the rule base
 /// and to use RunQuery(queryLabel)
 /// </remarks>
 /// <param name="query">The new Query to run.</param>
 /// <returns>An <code>IList&lt;IList&lt;Fact>></code> containing the results found.</returns>
 public IList<IList<Fact>> RunQuery(Query query)
 {
     return IE.RunQuery(query);
 }
 protected override void WriteQuery(XmlElement target, Query query)
 {
     WriteQueryBody(target, Document.CreateElement("Query", DatalogNamespaceURL), query);
 }
 protected void WriteQueryBody(XmlElement target, XmlElement queryElement, Query query)
 {
     WriteLabel(queryElement, query.Label);
     WriteAtomGroup(queryElement, query.AtomGroup);
     target.AppendChild(queryElement);
 }
 protected override void WriteQuery(XmlElement target, Query query)
 {
     XmlElement eQuery = Document.CreateElement("query", DatalogNamespaceURL);
     WriteLabel(eQuery, query.Label);
     XmlElement body = Document.CreateElement("_body", DatalogNamespaceURL);
     WriteAtomGroup(body, query.AtomGroup);
     eQuery.AppendChild(body);
     target.AppendChild(eQuery);
 }
        protected virtual void WriteIntegrityQuery(XmlElement target, Query query)
        {
            if (syntax == SaveFormatAttributes.Expanded) {
                XmlElement warden = Document.CreateElement("warden", DatalogNamespaceURL);
                target.AppendChild(warden);
                target = warden;
            }

            WriteQueryBody(target, Document.CreateElement("Integrity", DatalogNamespaceURL), query);
        }
Beispiel #6
0
        /// <summary>
        /// Runs a new Query in the current working memory.
        /// </summary>
        /// <remarks>
        /// For performance reasons, it is recommended to declare all queries in the rule base
        /// and to use RunQuery(queryLabel)
        /// </remarks>
        /// <param name="query">The new Query to run.</param>
        /// <returns>An <code>IList&lt;IList&lt;Fact>></code> containing the results found.</returns>
        public IList<IList<Fact>> RunQuery(Query query)
        {
            CheckInitialized();
            if (query == null) {
                throw new BREException("Query is null or not found.");
            }

            return WM.FB.RunQuery(query);
        }
Beispiel #7
0
 protected abstract void WriteQuery(XmlElement target, Query query);
 protected override void WriteIntegrityQuery(XmlElement target, Query query)
 {
     //TODO FR-1546485: check how integrity queries are actually supposed to be written in Naf Datalog!
     WriteImplication(target, new Implication(query.Label, ImplicationPriority.Medium, String.Empty, String.Empty, IGNORED_DEDUCTION, query.AtomGroup));
 }
Beispiel #9
0
        public void QueryIsNotImplication()
        {
            Query query = new Query("get spending",
                                  new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("spending",
                                                      new Variable("customer"),
                                                      new Individual("min(5000,EUR)"),
                                                      new Individual("previous year"))));

            Implication implication = new Implication("get spending",
                                                      ImplicationPriority.Medium,
                                                      String.Empty,
                                                      String.Empty,
                                                      atom2_2,
                                                      query.AtomGroup);

            Assert.IsFalse(query.Equals(implication), "QueryIsNotImplication");
        }
Beispiel #10
0
        public void QueryBase()
        {
            QueryBase qb = new QueryBase();
            Query query1 = new Query("get spending",
                                          new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("spending",
                                                              new Variable("customer"),
                                                              new Individual("min(5000,EUR)"),
                                                              new Individual("previous year"))));
            qb.Add(query1);
            Assert.AreEqual(1, qb.Count, "(1) QueriesCount");

            Query getQ1 = qb.Get("get spending");
            Assert.AreEqual(query1, getQ1, "Get Query Is Equal");
            Assert.IsTrue(((Atom)query1.AtomGroup.Members[0]).IsIntersecting((Atom)getQ1.AtomGroup.Members[0]), "Get Query Is Similar");

            Assert.IsNull(qb.Get("find me if you can"), "Missing query");

            Query query2 = new Query("get earning",
                                          new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("earning",
                                                              new Variable("customer"),
                                                              new Individual("min(99999,EUR)"),
                                                              new Individual("previous year"))));
            qb.Add(query2);
            Assert.AreEqual(2, qb.Count, "(2) QueriesCount");

            qb.Remove(qb.Get(0));
            Assert.AreEqual(1, qb.Count, "(3) QueriesCount");
            Query getQ2 = qb.Get(0);
            Assert.AreEqual(query2, getQ2, "(3) Get Query Is Equal");
            Assert.IsTrue(((Atom)query2.AtomGroup.Members[0]).IsIntersecting((Atom)getQ2.AtomGroup.Members[0]), "(3) Get Query Is Similar");

            qb.Add(new Query("to be killed",
                                  new AtomGroup(AtomGroup.LogicalOperator.And, new Atom("victim",
                                                      new Variable("test"),
                                                      new Individual("whatsoever")))));
            Assert.AreEqual(2, qb.Count, "(4) QueriesCount");

            qb.Remove(qb.Get("to be killed"));
            Assert.AreEqual(1, qb.Count, "(5) QueriesCount");

            qb.Remove(query2);
            Assert.AreEqual(0, qb.Count, "(6) QueriesCount");
        }