Boolean Brackets


Introduction

For the user to construct a database query, it is not sufficient to enter individual conditions. The conditions must be combined by the boolean operators AND, OR, and NOT into a single SQL WHERE clause. To keep the query builder graphical and user-friendly, an interface to apply these operators visually was developed. Although this does not relate specifically to the spatial component of the system, this part of the project was done by Alex Hall and is discussed in his report.


The chosen solution to this problem is for the user to draw curly brackets by dragging across the screen, with each bracket representing an operator. An AND or OR bracket groups all the conditions or brackets to the left of it, grouping them together by placing the appropriate operator in between. A NOT bracket is applied to a single condition or bracket to invert it. The entire interface is rendered as Scalable Vector Graphics using the JavaScript library Raphaël.


Demo

An example of the Boolean Brackets interface is presented below. A static list of 'conditions' is supplied, represented simply by single letters. In the PADB query builder, the interface can also handle the addition, removal, and rearranging of conditions. Brief instructions to help you test the interface are given. For more details see the report.


The interface starts with a single bracket, known as the root. The root always spans the entire list of conditions and cannot be removed, otherwise the final expression would be meaningless. Initially the operator of the root is AND, as users typically want a query to require that all given conditions are satisfied. You can change the operator of the root or of any other brackets by clicking on the text indicating the operator.


In order to draw more brackets to create a more complicated expression, you first have to add a new layer. This is done by clicking the blue triangular '+' button at the bottom. Each layer has such a button to insert a new layer to its left. Each layer (apart from the one containing the root bracket) also has a button to delete itself. Layers allow you to place brackets at different levels, so that brackets group other brackets in layers to their left as sub-conditions.


Once a new layer has been added, there is now space to draw more brackets. This is done by dragging the mouse across an empty space in a layer. You can then change the operator of the new bracket, resize it by dragging one of its edges (the mouse cursor should change when you hover over an edge), or delete it by clicking on it (before clicking the bracket should appear blue, and after it should appear thicker) and then clicking on the red 'x' button that appears.


Brackets and layers can be added, removed, and edited arbitrarily. To keep the interface in a meaningful state, brackets must always either fully contain conditions and brackets to their left, or not contain them at all. There can be no partial overlapping. You may notice the interface enforcing this constraint as you draw and resize brackets, such as automatically resizing a bracket to include its children or preventing a bracket from being expanded beyond a certain point. In this way, the interface always represents a valid expression, unless a NOT bracket is applied to more than one child. You can see the represented expression by clicking the 'Generate expression' button.


A
B
C
D
E
F
G
H