Difference between revisions of " Using Blueprints"

From Blazegraph
Jump to: navigation, search
(Using a Remote Instance)
(Getting Started with Gremlin)
Line 23: Line 23:
 
<pre>
 
<pre>
 
gremlin> import com.bigdata.blueprints.*  
 
gremlin> import com.bigdata.blueprints.*  
gremlin> g = new BigdataGraphClient("http://localhost:9999/bigdata")  
+
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.loadGraphML("./ant-build/gremlin-groovy-2.5.0/data/graph-example-1.xml")  
 
gremlin> g.V  
 
gremlin> g.V  

Revision as of 22:49, 12 July 2015

Using Blueprints with Blazegraph

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");
                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(); } `

        }