Skip to content

Using_Blueprints_with_Blazegraph

Brad Bebee edited this page Feb 13, 2020 · 1 revision

Blueprints is an open-source property graph model interface useful for writing applications on top of a graph database. Gremlin is a domain specific language for traversing property graphs that comes with an excellent REPL useful for interacting with a Blueprints database. Rexster exposes a Blueprints database as a web service and comes with a web-based workbench application called DogHouse.

Getting Started with Gremlin

To get started with Blazegraph via Blueprints, Gremlin, and Rexster, start by getting your Blazegraph server running per the instructions NanoSparqlServer.

Blazegraph comes with an ant task to download, unpack, and configure a Gremlin console for use with Blazegraph:

ant gremlin

You can then start the Gremlin console and begin interacting with Blazegraph:

./ant-build/gremlin-groovy-2.5.0/bin/gremlin.sh
                  \,,,/
                  (o o)
-----oOOo-(_)-oOOo-----
gremlin>

From Gremlin (or Blueprints code) you can then connect to the Blazegraph server and upload the sample GraphML file:

gremlin> import com.bigdata.blueprints.*
gremlin> g = new BigdataGraphClient("http://localhost:9999/bigdata/sparql")
gremlin> g.loadGraphML("./ant-build/gremlin-groovy-2.5.0/data/graph-example-1.xml")
gremlin> g.V
gremlin> g.E

Using Embedded Instance

To get started using Blazegraph with an embedded

         private static final String journalFile = "/tmp/blazegraph/blueprints.jnl";


         public void useEmbeddedBlazegraph()
         {

                final BigdataGraph g = new BigdataGraphEmbedded(getOrCreateRepository(journalFile));
                final String testFile = "graph-example-1.xml";

                try {
                GraphMLReader.inputGraph(graph, this.getClass().getResourceAsStream(testFile));
                for (Vertex v : graph.getVertices()) {
                    System.err.println(v);
                }
                for (Edge e : graph.getEdges()) {
                    System.err.println(e);
                }
             } catch (IOException e) {
                e.printStackTrace();
             }
`

         }

         public BigdataSailRepository getOrCreateRepository(String journalFile) {

        final java.util.Properties props = new java.util.Properties();
        BigdataSailRepository repo = null;

        /*
         * Lax edges allows us to use non-unique edge identifiers
         */
        props.setProperty(BigdataGraph.Options.LAX_EDGES, "true");

        /*
         * SPARQL bottom up evaluation semantics can have performance impact.
         */
        props.setProperty(AbstractTripleStore.Options.BOTTOM_UP_EVALUATION,
                "false");

        if (journalFile == null || !new File(journalFile).exists()) {

            /*
             * No journal specified or journal does not exist yet at specified
             * location. Create a new store. (If journal== null an in-memory
             * store will be created.
             */
            repo = BigdataSailFactory.createRepository(props, journalFile,
                    Option.TextIndex);

        } else {

            /*
             * Journal already exists at specified location. Open existing
             * store.
             */
            repo = BigdataSailFactory.openRepository(journalFile);

        }

        try {
            repo.initialize();
        } catch (RepositoryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return repo;
    }

Using a Remote Instance

Start by getting your Blazegraph server running per the instructions NanoSparqlServer. Valid your url by pointing your browser to the serviceURL in the started instance.

     [java] INFO: com.bigdata.util.config.LogUtil: Configure and watch: bigdata-war/src/WEB-INF/classes/log4j.properties
     [java] WARN : NanoSparqlServer.java:484: Starting NSS
     [java] WARN : ServiceProviderHook.java:162: Running.
     [java] WARN : ServiceRegistry.java:57: New service class com.bigdata.rdf.rio.json.BigdataSPARQLResultsJSONWriterFactory replaces existing service class org.openrdf.query.resultio.sparqljson.SPARQLResultsJSONWriterFactory
     [java] WARN : ServiceRegistry.java:57: New service class com.bigdata.rdf.rio.json.BigdataSPARQLResultsJSONParserFactory replaces existing service class org.openrdf.query.resultio.sparqljson.SPARQLResultsJSONParserFactory
     [java] serviceURL: http://127.0.0.1:9999

In your java code, you can connect to the instance by creating a BigdataGraphClient.

         public void useRemoteBlazegraph()
         {

                final BigdataGraph g = new BigdataGraphClient("http://localhost:9999/bigdata/sparql");
                final String testFile = "graph-example-1.xml";

                try {
                GraphMLReader.inputGraph(graph, this.getClass().getResourceAsStream(testFile));
                for (Vertex v : graph.getVertices()) {
                    System.err.println(v);
                }
                for (Edge e : graph.getEdges()) {
                    System.err.println(e);
                }
             } catch (IOException e) {
                e.printStackTrace();
             }
`

         }

Use In-Memory Blazegraph

 public void useInMemoryBlazegraph()
         {

                final BigdataGraph g = new BigdataGraphFactory.create();;
                final String testFile = "graph-example-1.xml";

                try {
                GraphMLReader.inputGraph(graph, this.getClass().getResourceAsStream(testFile));
                for (Vertex v : graph.getVertices()) {
                    System.err.println(v);
                }
                for (Edge e : graph.getEdges()) {
                    System.err.println(e);
                }
             } catch (IOException e) {
                e.printStackTrace();
             }
`

         }

Using Rexster

In addition to the Gremlin console, you can also connect to Blazegraph via Rexster. Just like Gremlin, there is an ant task to download, unpack, and configure a Rexster server for use with Blazegraph:

ant rexster

You can then start the Rexster server:

cd ant-build/rexster-server-2.5.0 > ./bin/rexster.sh -s -c config/rexster.xml

And begin interacting with Rexster's DogHouse application at http://localhost:8182/doghouse.

Rexster is pre-configured to interact with a Blazegraph server running on localhost:9999. Edit rexster.xml to connect to a different Blazegraph instance.

Rexster.xml

You'll want to make sure your rexster.xml is configured. See BLZG-1374 for using this feature prior to the 1.5.2 release.

#rexster.xml snippet
... 
          <graph>
           <graph-name>bigdata</graph-name>
           <graph-type>com.bigdata.blueprints.BigdataGraphConfiguration</graph-type>
           <properties>
               <type>remote</type>
               <host>localhost</host>
               <port>9999</port>
           </properties>
           <extensions>
               <allows>
                   <allow>tp:gremlin</allow>
               </allows>
           </extensions>
       </graph>
...
Clone this wiki locally