Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed guidance towards evaluative boolean logic tree
    primarykey
    data
    text
    <p>I can't seem to find a pointer in the right direction, I am not even sure what the terms are that I should be researching but countless hours of googling seem to be spinning me in circles, so hopefully the collective hive of intelligence of Stack Overflow can help.</p> <p>The problem is this, I need a way to filter data in what I can only call a compound logic tree. Currently the system implements a simple AND filtering system. For example, lets say we have a dataset of people. You add a bunch of filters such that show all the people where (Sex = Female) AND (Age > 23) AND (Age &lt; 30) AND ( Status = Single). Easy enough, iterate through each item, add to a valid items collection only if every condition is true. </p> <p>The problem I'm encountering is how do I handle the user being able to build complex queries involved and's and or's? I'm thinking of something like a tree where each node represents and expression evaluating its children to true or false. A simplistic example would be - filter down to ((Sex == Male AND Age == 25) OR (Sex == Female AND Status == Single)) AND IQ > 120. Sorry I can't think of a better example at the moment. But how would you go about representing this type of expression tree, and evaluating the items in a collection against these filters. What are some references that would help? Hell, what are some damn Google searching that might lead into a positive direction?!</p> <p>Thanks to anyone that can provide any help.</p> <p>Here is an example of a compound query in tree form using a dataset of people</p> <ul> <li>Query - Show me all people where sex is male and eyes are green or sex is female, eyes are blue, or status is single. In Paren form (Sex==Male &amp;&amp; Eyes == Green) || ( Sex == Female &amp;&amp; ( Eyes == Blue || Status == Single))</li> </ul> <p>So In tree form im Thinking</p> <pre><code>o-Root Node - And - Sex = Male - And - Eyes = Blue - Or - Sex = Female - And Eyes = Blue - Or Status = Single </code></pre> <p>I believe the solution is to represent each node such in a data structure like</p> <pre><code>Node { OpType - AND or OR ExpressionField - The field to evaluate ExpressionOp - =, !=, &gt;, &gt;=, &lt;, &lt;= ExpressionValue - the value to compare the field's value against Function Evaluate() - returns a bool } </code></pre> <p>So for a given node, evaluate the chilren, if you are an AND node, then return true if your expression results in true and all your AND children evaluate to true or any OR child evaluates to true and recurse up.</p> <p>Seems to satisfy every conceptual condition I can throw at it, but we will since once I implement it. I will post the real code up later when its working and pictures to help describe this problem better for others.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. COSuggest you clarify what form your data is in : SQL db ? I assume the tag "as3" refers to ActionScript 3 : if so, are you really looking for C# or AS3 specific techniques, or just for "theory" ?
      singulars
    2. COThe data is in memory, although technically the implementation is both in flash and in silverlight, I am much more interested in understanding the general solution than a specific implementation. The crux of the problem involves presenting a UI to the user that allows them to dynamically build a complex query to filter the dataset. I need a solid data structure to represent the query. So far I have the following for a node - Type - And or Or - Field - the field of the dataset this node is targeting - Operation - =, !=, >, < <=, >= - Value - the value to apply the operation against
      singulars
    3. COClearer explanation ! I suggest you clarify if the data structure is in C#/SilverLight : if so, I'd assume you'll use Linq to do the "heavy lifting." If you are already at a high level with Linq, using lambdas, anonymous methods, etc., that's one thing : if you are not, you can get good advice on SO (if you ask for it) on Linq study resources (imho Jon Skeet's "C# in Depth" is the best C# book on the planet with superb coverage of Linq). This may be irrelevant to your idea, but you can use a dictionary with "whatever" as keys and executable (anonymous) methods as Values. – BillW
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload