-
Notifications
You must be signed in to change notification settings - Fork 173
Blueprints_API_embedded_mode
Brad Bebee edited this page Feb 13, 2020
·
1 revision
A sample Java application demonstrates using Blazegraph™ in embedded mode with Blueprints. See Using Blueprints with Blazegraph tutorial for more details. This project was created in Eclipse IDE with Maven. If you are not familiar with Eclipse and Maven you may take a look at our step by step tutorial on how to create a Java project using Blazegraph™ in Eclipse.
You can download the sample-blueprints-embedded application here.
package sample.blueprints.embedded;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.openrdf.repository.RepositoryException;
import com.bigdata.blueprints.BigdataGraph;
import com.bigdata.blueprints.BigdataGraphEmbedded;
import com.bigdata.journal.Options;
import com.bigdata.rdf.sail.BigdataSailRepository;
import com.bigdata.rdf.sail.remote.BigdataSailFactory;
import com.bigdata.rdf.sail.remote.BigdataSailFactory.Option;
import com.bigdata.rdf.store.AbstractTripleStore;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.io.graphml.GraphMLReader;
public class SampleBlazegraphBlueprintsEmbedded {
protected static final Logger log = Logger.getLogger(SampleBlazegraphBlueprintsEmbedded.class);
private static final String journalFile = "/tmp/blazegraph/test.jnl";
public static void main(String[] args) throws IOException,
RepositoryException {
final Properties props = new Properties();
props.put(Options.BUFFER_MODE, "DiskRW");
/*
* 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");
props.put("com.bigdata.journal.AbstractJournal.file", journalFile);
BigdataSailRepository repo = getOrCreateRepository(props);
try {
final BigdataGraph g = new BigdataGraphEmbedded(repo);
GraphMLReader.inputGraph(g, SampleBlazegraphBlueprintsEmbedded.class
.getResourceAsStream("/graph-example-1.xml"));
for (Vertex v : g.getVertices()) {
log.info(v);
}
for (Edge e : g.getEdges()) {
log.info(e);
}
} finally {
repo.shutDown();
}
}
private static BigdataSailRepository getOrCreateRepository(Properties props) throws RepositoryException {
BigdataSailRepository repo = null;
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);
}
repo.initialize();
return repo;
}
}
==Comments==
===Configure Journal properties===
<pre>
final Properties props = new Properties();
props.put("com.bigdata.journal.AbstractJournal.bufferMode", "DiskRW");
props.setProperty(BigdataGraph.Options.LAX_EDGES, "true");
props.setProperty(AbstractTripleStore.Options.BOTTOM_UP_EVALUATION, "false");
props.put("com.bigdata.journal.AbstractJournal.file", journalFile);
private static BigdataSailRepository getOrCreateRepository(Properties props) throws RepositoryException {
BigdataSailRepository repo = null;
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);
}
repo.initialize();
return repo;
}
GraphMLReader.inputGraph(g, SampleBlazegraphBlueprintsEmbedded.class
.getResourceAsStream(dataset));
for (Vertex v : g.getVertices()) {
log.info(v);
}
for (Edge e : g.getEdges()) {
log.info(e);
}
BlazeGraph(TM) Graph Engine
Flexible
Reliable
Affordable
Web-Scale Computing for the Enterprise
Copyright SYSTAP, LLC 2006-2015. All rights reserved.
192.168.3.3
Thu Apr 23 16:01:32 YEKT 2015
Linux/3.13.0-49-generic amd64
AMD FX(tm)-6100 Six-Core Processor Family 21 Model 1 Stepping 2, AuthenticAMD #CPU=6
Oracle Corporation 1.8.0_40
freeMemory=236453200
buildVersion=1.5.1
Dependency License
ICU http://source.icu-project.org/repos/icu/icu/trunk/license.html
bigdata-ganglia http://www.apache.org/licenses/LICENSE-2.0.html
blueprints-core https://github.com/tinkerpop/blueprints/blob/master/LICENSE.txt
colt http://acs.lbl.gov/software/colt/license.html
commons-codec http://www.apache.org/licenses/LICENSE-2.0.html
commons-fileupload http://www.apache.org/licenses/LICENSE-2.0.html
commons-io http://www.apache.org/licenses/LICENSE-2.0.html
commons-logging http://www.apache.org/licenses/LICENSE-2.0.html
dsiutils http://www.gnu.org/licenses/lgpl-2.1.html
fastutil http://www.apache.org/licenses/LICENSE-2.0.html
flot http://www.opensource.org/licenses/mit-license.php
high-scale-lib http://creativecommons.org/licenses/publicdomain
httpclient http://www.apache.org/licenses/LICENSE-2.0.html
httpclient-cache http://www.apache.org/licenses/LICENSE-2.0.html
httpcore http://www.apache.org/licenses/LICENSE-2.0.html
httpmime http://www.apache.org/licenses/LICENSE-2.0.html
jackson-core http://www.apache.org/licenses/LICENSE-2.0.html
jetty http://www.apache.org/licenses/LICENSE-2.0.html
jquery https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt
log4j http://www.apache.org/licenses/LICENSE-2.0.html
lucene http://www.apache.org/licenses/LICENSE-2.0.html
nanohttp http://elonen.iki.fi/code/nanohttpd/#license
rexster-core https://github.com/tinkerpop/rexster/blob/master/LICENSE.txt
river http://www.apache.org/licenses/LICENSE-2.0.html
servlet-api http://www.apache.org/licenses/LICENSE-2.0.html
sesame http://www.openrdf.org/download.jsp
slf4j http://www.slf4j.org/license.html
zookeeper http://www.apache.org/licenses/LICENSE-2.0.html
INFO: com.bigdata.util.config.LogUtil: Configure: file:/home/maria/workspace_sample/sample-blueprints-embedded/target/classes/log4j.properties
New service class org.openrdf.query.resultio.sparqljson.SPARQLResultsJSONWriterFactory replaces existing service class com.bigdata.rdf.rio.json.BigdataSPARQLResultsJSONWriterFactory
New service class org.openrdf.query.resultio.sparqljson.SPARQLResultsJSONParserFactory replaces existing service class com.bigdata.rdf.rio.json.BigdataSPARQLResultsJSONParserFactory
v[1]
v[2]
v[3]
v[4]
v[5]
v[6]
e[7][1->2]
e[8][1->4]
e[9][1->3]
e[10][4->5]
e[11][4->3]
e[12][6->3]