Created
July 8, 2016 22:52
-
-
Save amihalik/61cf870650b7443389e7be7600f8502c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mvm.rya.api.RdfCloudTripleStoreConfiguration; | |
import mvm.rya.indexing.accumulo.ConfigUtils; | |
import mvm.rya.indexing.accumulo.geo.GeoConstants; | |
import mvm.rya.mongodb.MongoDBRdfConfiguration; | |
import mvm.rya.sail.config.RyaSailFactory; | |
import org.apache.commons.io.IOUtils; | |
import org.apache.hadoop.conf.Configuration; | |
import org.openrdf.model.vocabulary.RDFS; | |
import org.openrdf.query.QueryLanguage; | |
import org.openrdf.query.TupleQuery; | |
import org.openrdf.query.resultio.text.csv.SPARQLResultsCSVWriter; | |
import org.openrdf.repository.sail.SailRepository; | |
import org.openrdf.repository.sail.SailRepositoryConnection; | |
import org.openrdf.rio.RDFFormat; | |
import org.openrdf.sail.Sail; | |
import com.mongodb.MongoClient; | |
import de.flapdoodle.embed.mongo.distribution.Version; | |
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory; | |
public class SimpleRyaMongoExample { | |
private static final String DATA = "<u:a> <u:tt> <u:b> .\n <u:a> <u:ww> <u:x> .\n <u:a> <u:ww> <u:y> .\n "; | |
private static final String QUERY = "select ?s ?foo where { ?s <u:ww> ?foo . ?s <u:tt> <u:b> }"; | |
public static void main(String[] args) throws Exception { | |
// Gets two results (correct) | |
// Sail sail = new MemoryStore(); | |
// Gets one result (incorrect) | |
Sail sail = RyaSailFactory.getInstance(getConf()); | |
SailRepository sr = new SailRepository(sail); | |
sr.initialize(); | |
SailRepositoryConnection src = sr.getConnection(); | |
src.add(IOUtils.toInputStream(DATA), "", RDFFormat.NTRIPLES); | |
TupleQuery tq = src.prepareTupleQuery(QueryLanguage.SPARQL, QUERY); | |
tq.evaluate(new SPARQLResultsCSVWriter(System.out)); | |
} | |
private static final boolean PRINT_QUERIES = true; | |
private static final String MONGO_DB = "rya"; | |
private static final String MONGO_COLL_PREFIX = "rya_"; | |
private static Configuration getConf() throws Exception { | |
MongodForTestsFactory testsFactory = MongodForTestsFactory.with(Version.Main.PRODUCTION); | |
MongoClient mongoClient = testsFactory.newMongo(); | |
final int port = mongoClient.getServerAddressList().get(0).getPort(); | |
Configuration conf = new Configuration(); | |
conf.set(ConfigUtils.USE_MONGO, "true"); | |
conf.setInt(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT, port); | |
conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true"); | |
conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, MONGO_DB); | |
conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, MONGO_COLL_PREFIX); | |
conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, MONGO_COLL_PREFIX); | |
conf.set(ConfigUtils.GEO_PREDICATES_LIST, GeoConstants.GEO_AS_WKT.stringValue()); | |
conf.set(ConfigUtils.FREETEXT_PREDICATES_LIST, RDFS.LABEL.stringValue()); | |
return conf; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment