Esempio n. 1
0
        public void Add(Query query)
        {
            if (queryDefs.Contains(query))
                throw new BREException("The knowledge base already contains a similar query: " + query);

            queryDefs.Add(query);
        }
Esempio n. 2
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>A QueryResultSet containing the results found.</returns>
 /// <see cref="org.nxbre.ie.rule.QueryResultSet"/>
 public QueryResultSet RunQuery(Query query)
 {
     return RunQuery(query, true);
 }
Esempio n. 3
0
 private QueryResultSet RunQuery(Query query, bool newQuery)
 {
     CheckInitialized();
     if (query == null) throw new BREException("Query is null or not found.");
     if (newQuery) WM.FB.RegisterAtoms(query.AtomGroup.AllAtoms);
     return new QueryResultSet(WM.FB.RunQuery(query));
 }
Esempio n. 4
0
 private void WriteQueryBody(XmlElement target, XmlElement queryElement, Query query)
 {
     WriteLabel(queryElement, query.Label);
     WriteAtomGroup(queryElement, query.AtomGroup);
     target.AppendChild(queryElement);
 }
Esempio n. 5
0
        private 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);
        }
Esempio n. 6
0
 protected override void WriteQuery(XmlElement target, Query query)
 {
     WriteQueryBody(target, Document.CreateElement("Query", DatalogNamespaceURL), query);
 }
Esempio n. 7
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>A QueryResultSet containing the results found.</returns>
 /// <see cref="org.nxbre.ie.rule.QueryResultSet"/>
 public QueryResultSet RunQuery(Query query)
 {
     return IE.RunQuery(query);
 }
Esempio n. 8
0
 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);
 }
Esempio n. 9
0
		public void Remove(Query query) {
			queryDefs.Remove(query);
		}
Esempio n. 10
0
 /// <summary>
 /// Runs a Query against a the FactBase.
 /// </summary>
 /// <param name="query">The Query to run.</param>
 /// <returns>An ArrayList containing references to facts matching the pattern of the Query.</returns>
 public ArrayList RunQuery(Query query)
 {
     return FilterDistinct(ProcessAtomGroup(query.AtomGroup));
 }
Esempio n. 11
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");
        }
Esempio n. 12
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");
        }
		private void WriteQuery(XmlElement target, Query query) {
			XmlElement eQuery = document.CreateElement("query", GetDatalogNamespaceURL());
			WriteLabel(eQuery, "_rlab", query.Label);
			XmlElement body = document.CreateElement("_body", GetDatalogNamespaceURL());
			WriteAtomGroup(body, query.AtomGroup);
			eQuery.AppendChild(body);
			target.AppendChild(eQuery);
		}
Esempio n. 14
0
 protected abstract void WriteQuery(XmlElement target, Query query);