public class Grakn extends Object
Grakn is the main entry point to connect to a Grakn Knowledge Graph. To connect to a knowledge graph, first make sure you have a Grakn Engine server running by starting it from the shell using:
grakn.sh start
To establish a connection, you first need to obtain a GraknSession by calling
the session(String, String) method. A GraknSession connects to a given physical
location and specific database instance within that location.
Once you've instantiated a session, you can obtain multiple concurrent graph connections,
represented by the GraknGraph interface.
If you are running the Grakn server locally then you can initialise a graph with:
GraknGraph graph = Grakn.session(Grakn.DEFAULT_URI, "keyspace").getGraph();
If you are running the Grakn server remotely you must initialise the graph by providing the IP address of your server:
GraknGraph graph = Grakn.session("127.6.21.2", "keyspace").getGraph();
The string “keyspace” uniquely identifies the graph and allows you to create different graphs.
Please note that graph keyspaces are not case sensitive so the following two graphs are actually the same graph:
GraknGraph graph1 = Grakn.session("127.6.21.2", "keyspace").getGraph();
GraknGraph graph2 = Grakn.session("127.6.21.2", "KeYsPaCe").getGraph();
All graphs are also singletons specific to their keyspaces so be aware that in the following case:
GraknGraph graph1 = Grakn.session("127.6.21.2", "keyspace").getGraph();
GraknGraph graph2 = Grakn.session("127.6.21.2", "keyspace").getGraph();
GraknGraph graph3 = Grakn.session("127.6.21.2", "keyspace").getGraph();
any changes to graph1, graph2, or graph3 will all be persisted to the same graph.
You can alternatively instantiate a 'toy' knowledge graph (which runs in-memory) for experimentation purposes.
You can initialise an in memory graph without having the Grakn server running:
GraknGraph graph = Grakn.session(Grakn.IN_MEMORY, "keyspace").getGraph();
This in memory graph serves as a toy graph for you to become accustomed to the API without needing to setup a
Grakn Server. It is also useful for testing purposes.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_URI
Constant to be passed to
session(String, String) to specify the default localhost Grakn Engine location. |
static String |
IN_MEMORY
Constant to be passed to
session(String, String) to specify an in-memory graph. |
| Constructor and Description |
|---|
Grakn() |
| Modifier and Type | Method and Description |
|---|---|
static GraknSession |
session(String location,
String keyspace)
Returns a session instance to produce concurrent connections to the Grakn knowledge graph.
|
public static final String DEFAULT_URI
session(String, String) to specify the default localhost Grakn Engine location.
This default constant, which is set to localhost: 4567 cannot be changed in development"public static final String IN_MEMORY
session(String, String) to specify an in-memory graph.@CheckReturnValue public static GraknSession session(String location, String keyspace)
This method obtains the GraknSession for the specified location and keyspace.
location - The location from which to create the graph.
For the default, localhost Grakn Engine location, use the DEFAULT_URI constant provided in this class.
For testing or experimentation, you can use a toy in-memory graph be specifying the IN_MEMORY constant.keyspace - The keyspace, or database name, where the knowledge graph is stored. A given
database server will support multiple database instances. You need to explicitly name
the instance to be used. Please note that graph keyspaces are not case sensitive.
If one doesn't exist, it will be created for you.Copyright © 2017 Grakn Labs Ltd. All rights reserved.