public void Add(Query query) { if (queryDefs.Contains(query)) throw new BREException("The knowledge base already contains a similar query: " + query); queryDefs.Add(query); }
/// <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); }
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)); }
private void WriteQueryBody(XmlElement target, XmlElement queryElement, Query query) { WriteLabel(queryElement, query.Label); WriteAtomGroup(queryElement, query.AtomGroup); target.AppendChild(queryElement); }
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); }
protected override void WriteQuery(XmlElement target, Query query) { WriteQueryBody(target, Document.CreateElement("Query", DatalogNamespaceURL), query); }
/// <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); }
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); }
public void Remove(Query query) { queryDefs.Remove(query); }
/// <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)); }
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"); }
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); }
protected abstract void WriteQuery(XmlElement target, Query query);