Modifying the Universe

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

Jump to: navigation, search

The universe is mutable. You have the power to change it! Let’s create a new node using the Atlas Shell.

GraphElement bob = Graph.U.createNode();
bob.attr().put(Node.NAME, "bob");
bob.tags().add("PERSON");
show(universe.nodesTaggedWithAny("PERSON"))

You've now changed the original index created by Atlas. To keep the universe somewhat sane, Atlas keeps track of what was originally in the universe and what was not. Atlas does this by providing two sets Common.universe() and Common.index(), where index is the universe before changes were made.

The following query will show an empty graph, even though "bob" exists in the universe.

show(index.nodesTaggedWithAny("PERSON"))

Since "bob" exists in the universe and not in the index, we should query for the new node using the universe.

show(universe.nodesTaggedWithAny("PERSON"))

This is important to remember when using convenience methods provided by Atlas such as Common.edges(). The convenience wrappers will use Common.index() not Common.universe().

Let’s create one more node and add an edge between the two nodes.

GraphElement bill = Graph.U.createNode();
bill.attr().put(Node.NAME, "bill");
bill.tags().add("PERSON");
GraphElement friends = Graph.U.createEdge(bill, bob);
friends.attr().put(Edge.NAME, "FRIENDS");
friends.tags().add("FRIENDS");

show(universe.edgesTaggedWithAny("FRIENDS").retainEdges())


← Toolbox Analyzers | Learning Atlas