Queries and Sets
In addition to defining nodes for you in the top level namespace, GUESS will also define special objects called fields which will have the same name as node and edge properties. For example, the field “height” exists as a variable named height. These variables are used in the construction of queries that select specific nodes. For example, for our previous example GUESS generated additional fields called dept, salary, and relationship. Using these and the operators ==, <=, >=, !=, <, >, and like we can begin to select out nodes and edges that match certain criteria. Some examples in this instance are:
-
In order to grab all nodes in department 2 we would type:
-
dept == ‘dept2’ (answer: alice)
-
In order to find nodes with salary less than or equal to 50,000 we would type:
-
salary <= 50000 (answer: bob,john)
-
To find all edges with a relationship matching the regular expression “reports*” we would type:
-
relationship like “reports%” (answer: bob->alice, john->alice)
-
If we wanted to make all square nodes red we would do:
-
(style == 1).color = red
You can also make more complicated queries by combining sub-expressions with the & and | operators (and/or respectively). For example:
-
If we want all nodes in dept1 with a salary of 50000 or more we would do:
-
(dept == ‘dept1’) & (salary >= 50000) (result: bob)
-
If we wanted all nodes in dept1 or that have a salary of over 50000 we would type:
-
(dept == ‘dept1’) | (salary > 50000) (result: bob, alice, john)
One important note is that for fields that belong to nodes and edges (e.g. color, visible, width) the field object in the top level namespace will default to node attributes. The expression “color == blue” will return nodes that are blue. In order to specify that you want an edge or node attribute, prepend the attribute name with “Node.” or “Edge.” This means that to get all blue edges we would use the expression: “Edge.color = blue.”
In order to find all nodes or edges not in a given set, you may use the complement method. The method will take either a set or individual node/edge as an argument and return a set of all nodes/edges not in the set. If the argument set contains only nodes the result will contain only nodes. Similarly if the set contains only edges the result will contain only edges. If both nodes and edges are in the input set nodes and edges will be returned in the output set. Example usage includes:
-
complement(v44) – all nodes other than v44
-
complement(v44?v55) - all edges not between node 44 and 55
-
complement((v44,v44?v55)) - all nodes AND edges not in the set
-
complement(dept == ‘dept1’) – all nodes not in department 1
If a set contains a mixture of nodes and edges you can apply the findEdges() and findNode() methods to extract just the nodes or edges.
In addition to the operations listed above there are a number of constructs/operators that are specific to state based operations. Take a look at the States and Animations chapter to get a sense of those.


