Recent Changes for "Manipulating and Querying Nodes and Edges" - Graph Exploration System (GUESS)http://guess.wikispot.org/Manipulating_and_Querying_Nodes_and_EdgesRecent Changes of the page "Manipulating and Querying Nodes and Edges" on Graph Exploration System (GUESS).en-us Manipulating and Querying Nodes and Edgeshttp://guess.wikispot.org/Manipulating_and_Querying_Nodes_and_Edges2007-08-10 23:52:16EytanAdar <div id="content" class="wikipage content"> Differences for Manipulating and Querying Nodes and Edges<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 1: </td> <td> Line 1: </td> </tr> <tr> <td> </td> <td> <span>+ = Manipulating and Querying Nodes and Edges =<br> + <br> + <br> + From the discussion on databases it should be evident that whatever attributes you define (or are pre-defined) on nodes and edges are accessible through the interpreter. You would access these as you would any attribute of a Python object. When the graph is loaded into memory GUESS will create node and edge objects for you in the top level name space of the interpreter. Nodes will have the same name as their name property.<br> + <br> + <br> + <br> + Going back to our simple office example:<br> + <br> + <br> + {{{nodedef&gt; name,style,dept VARCHAR(32),salary INT default 40000<br> + bob,1,dept1,50000<br> + john,1,dept1,49000<br> + alice,2,dept2,52000<br> + edgedef&gt; node1,node2,directed,relationship VARCHAR(32)<br> + bob,alice,true,reports to<br> + john,alice,true,reports to<br> + bob,john,false,colleague of<br> + }}}<br> + <br> + <br> + We will have 3 nodes defined in the top level namespace, bob, john, and alice. We can get a property by using the construct: &lt;nodename&gt;.&lt;propertyname&gt; and set a property by doing &lt;nodename&gt;.&lt;propertyname&gt; = &lt;value&gt;. If the property represents a visual aspect of the node or edge the set operation will immediately modify the visualization. Any changes will also be committed to the database. Some examples are:<br> + <br> + * bob.color = green (immediately color the bob node green)<br> + * alice.dept = “dept3” (set alice’s dept attribute to “dept3”)<br> + * john.salary = bob.salary * 1.5 (set john’s salary to 1.5 x that of bob’s)<br> + <br> + <br> + Nodes also have a few “special” attributes which are basically shortcuts. For example, the size attribute will set both the width and the height of a node at the same time. So bob.size = 20 is the same as bob.width = 20 and bob.height = 20.<br> + <br> + <br> + <br> + Edge work in a very similar way but they are not set in the top level namespace. Instead you would access the edge between two nodes by placing a “-“ between them (or “&lt;-“, “-&gt;”, or “&lt;-&gt;” for directed nodes). If you want to modify or access a node property you need to remember to place the edge definition in parentheses. For example:<br> + <br> + * (bob-&gt;alice).color = black (to make the link between bob and alice black)<br> + * (bob-john).relationship = “joint project” (to redefine the relationship between bob and john)<br> + <br> + <br> + For an edge you can always ask for the attributes node1 and node2 to get the end points (e.g. (bob-john).node1). For directed edges you can additionally ask for the source and destination attributes (e.g. (bob-&gt;alice).source returns bob).<br> + <br> + At certain times you may want to group nodes and/or edges together to modify or access their attributes at the same time. This is simply done by putting objects in parentheses (standard Python). What is unique the Python enhancement used by GUESS is that you can now modify an attribute of every node in that set at the same time. For example (bob,john).color = red will set both the bob and john nodes to red. This will also work for (bob,john,alice-bob).color = blue because nodes and edges have the same attribute (color). The graph attribute nodes (e.g. g.nodes) and edges (g.edges) return a group of all nodes and edges in the graph respectively. So the command g.nodes.color = black will set all nodes in the graph to black.<br> + <br> + One trick of this syntax is finding edges between two sets of nodes. A simple example is the command: (bob,john)-alice which will return two edges bob-alice and john-alice (we could have also typed (bob,john)-(alice) but since the second set was only composed of one node the extra parentheses were not necessary). If you are looking for additional ways to group nodes take a look at the subgraph section later on in this manual.<br> + <br> + A final note on edge and node visibility:<br> + <br> + * If a node is made invisible all edges to that node will also be made invisible.<br> + * If a node is made visible all edges that were previously invisible between that node and any other visible node will be made visible.<br> + * If an edge is made invisible the two nodes at the endpoint are left visible.<br> + * If an edge is made visible any previously invisible endpoint nodes will be made visible.</span> </td> </tr> </table> </div>