Attributes and Tags

From AtlasWiki
Revision as of 16:00, 3 February 2015 by BenHolland (Talk | contribs) (Attributes)

Jump to: navigation, search

Graph Elements

In Atlas a Q object can be thought of as a recipe to a constraint satisfaction problem (CSP). Building and chaining together Q’s costs you almost nothing, but when you ask to see what is in the Q (by showing or evaluating the Q) Atlas must evaluate the query and execute the graph traversals. The evaluated result is a Graph. A Graphis a set of GraphElement objects. In Atlas both a node and an edge are GraphElement objects.

Let’s take a look at an example written in Java that shows how to access GraphElement objects after starting with a Q.

Q methods = Common.universe().nodesTaggedWithAny(Node.NAME);
Graph methodsGraph = methods.eval();
AtlasSet<GraphElement> methodNodes = methodsGraph.nodes();
AtlasSet<GraphElement> methodEdges = methodsGraph.edges();

Note that we know methodEdges.size() would return 0 here because nodesTaggedWithAny does not return edges.

Attributes

An attribute is a key that corresponds to a value in the GraphElement attribute map. An attribute that is common to almost all nodes and edges is Node.NAME or Edge.NAME.

for(GraphElement methodNode : methodNodes){
   String name = (String) methodNode.attr().get(Node.NAME);
}

We can store lots of information in GraphElement attribute map. Another common attribute is the source correspondence that stores the file and character offset of where the node corresponds to in source code. Try double clicking on a node or edge to jump to source code!

Attributes can be used to select nodes out of a graph. For example from the methods Q we select all nodes with the attribute key Node.NAME that have the value "main".

Q mainMethods = methods.selectNode(Node.NAME, "main");

Tags

TODO


← Basic Queries | Learning Atlas | Common Queries →