Attributes and Tags

From AtlasWiki
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(;
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.


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 Here we iterate over each node in the methodNodes set and get the methods name attribute value.

for(GraphElement methodNode : methodNodes){
   String name = (String) methodNode.getAttr(;

We can store lots of information in the 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 graph we can select all method nodes with the attribute key that have the value "main".

Q mainMethods = graph.nodesTaggedWithAny(XCSG.Method).selectNode(, "main");


Tags can be thought of as special attributes where the value is always a Boolean true. The presence of a tag denotes that a node or edge is a member of a set. For example all nodes in the Atlas index that are methods are tagged with XCSG.Method. A tag is just a string key, but for Atlas provided tags such as XCSG.Method, we have defined constants for you that should be used to make your code cleaner (and safer from possible Schema changes in the future!).

We've already seen how to use tags using the nodesTaggedWithAny/nodesTaggedWithAll and edgesTaggedWithAny/edgesTaggedWithAll Q methods, but you should take some time to look through the Atlas Schema to see what tags are predefined for you. You get a lot for free!

← Common Queries | Learning Atlas | Atlas Schema →