Java Code Examples for org.eclipse.rdf4j.repository.sail.SailRepository#initialize()

The following examples show how to use org.eclipse.rdf4j.repository.sail.SailRepository#initialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpifSailTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Before
public void setup() throws RepositoryException {
	NotifyingSail baseSail = new MemoryStore();
	DedupingInferencer deduper = new DedupingInferencer(baseSail);
	NotifyingSail rdfsInferencer = new SchemaCachingRDFSInferencer(deduper, false);
	SpinSail spinSail = new SpinSail(rdfsInferencer);
	repo = new SailRepository(spinSail);
	repo.initialize();
	conn = repo.getConnection();

	platformLocale = Locale.getDefault();

	/*
	 * FIXME See #280 . Some tests (e.g. test involving spif:dateFormat) require English locale to succeed, instead
	 * of platform locale.
	 */
	Locale.setDefault(Locale.ENGLISH);
}
 
Example 2
Source File: AbstractLuceneSailGeoSPARQLTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	// setup a LuceneSail
	MemoryStore memoryStore = new MemoryStore();
	// enable lock tracking
	org.eclipse.rdf4j.common.concurrent.locks.Properties.setLockTrackingEnabled(true);
	sail = new LuceneSail();
	configure(sail);
	sail.setBaseSail(memoryStore);

	// create a Repository wrapping the LuceneSail
	repository = new SailRepository(sail);
	repository.initialize();

	// add some statements to it
	loadPoints();
	loadPolygons();
}
 
Example 3
Source File: HBaseSailTest.java    From Halyard with Apache License 2.0 6 votes vote down vote up
@Test
public void testEvaluate() throws Exception {
    ValueFactory vf = SimpleValueFactory.getInstance();
    Resource subj = vf.createIRI("http://whatever/subj/");
    IRI pred = vf.createIRI("http://whatever/pred/");
    Value obj = vf.createLiteral("whatever");
    CloseableIteration<? extends Statement, SailException> iter;
    HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "whatevertable", true, 0, true, 0, null, null);
    SailRepository rep = new SailRepository(sail);
    rep.initialize();
    sail.addStatement(subj, pred, obj);
    sail.commit();
    TupleQuery q = rep.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, "select ?s ?p ?o where {<http://whatever/subj/> <http://whatever/pred/> \"whatever\"}");
    TupleQueryResult res = q.evaluate();
    assertTrue(res.hasNext());
    rep.shutDown();
}
 
Example 4
Source File: RdfCloudTripleStoreTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    connector = new MockInstance().getConnector("", "");

    RdfCloudTripleStore sail = new RdfCloudTripleStore();
    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix("lubm_");
    sail.setConf(conf);
    AccumuloRyaDAO crdfdao = new AccumuloRyaDAO();
    crdfdao.setConnector(connector);
    crdfdao.setConf(conf);
    sail.setRyaDAO(crdfdao);

    repository = new SailRepository(sail);
    repository.initialize();
    connection = repository.getConnection();

    loadData();
}
 
Example 5
Source File: HBaseSailTest.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindWithFilter() throws Exception {
    HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "empty", true, 0, true, 0, null, null);
    SailRepository rep = new SailRepository(sail);
    rep.initialize();
    TupleQueryResult res = rep.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, "SELECT ?x WHERE {BIND (\"x\" AS ?x)\n  FILTER (?x = \"x\")}").evaluate();
    assertTrue(res.hasNext());
    assertEquals("x", res.next().getBinding("x").getValue().stringValue());
    rep.shutDown();
}
 
Example 6
Source File: MemInferencingTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
	public void testPersistence() {
		File datadir = Files.newTemporaryFolder();

		SchemaCachingRDFSInferencer sailStack = new SchemaCachingRDFSInferencer(new MemoryStore(datadir), true);
		SailRepository repo = new SailRepository(sailStack);
		repo.initialize();
		ValueFactory vf = repo.getValueFactory();

		IRI s1 = vf.createIRI("foo:s1");
		IRI c2 = vf.createIRI("foo:c2");
		IRI c1 = vf.createIRI("foo:c1");

		try (RepositoryConnection conn = repo.getConnection()) {
			conn.begin();
			conn.add(s1, RDF.TYPE, c1);
			conn.add(c1, RDFS.SUBCLASSOF, c2);
			conn.commit();
			assertTrue(conn.hasStatement(s1, RDF.TYPE, c2, true));
		}
		repo.shutDown();

		// re-init
//		sailStack = new SchemaCachingRDFSInferencer(new MemoryStore(datadir), true);
//		repo = new SailRepository(sailStack);
		repo.initialize();

		try (RepositoryConnection conn = repo.getConnection()) {
			assertTrue(conn.hasStatement(s1, RDF.TYPE, c2, true));
		}
	}
 
Example 7
Source File: HalyardUpdate.java    From Halyard with Apache License 2.0 5 votes vote down vote up
public int run(CommandLine cmd) throws Exception {
    SailRepository rep = new SailRepository(new TimeAwareHBaseSail(getConf(), cmd.getOptionValue('s'), false, 0, true, 0, cmd.getOptionValue('i'), null));
    rep.initialize();
    try {
        Update u = rep.getConnection().prepareUpdate(QueryLanguage.SPARQL, cmd.getOptionValue('q'));
        ((MapBindingSet)u.getBindings()).addBinding(new TimeAwareHBaseSail.TimestampCallbackBinding());
        LOG.info("Update execution started");
        u.execute();
        LOG.info("Update finished");
    } finally {
        rep.shutDown();
    }
    return 0;
}
 
Example 8
Source File: SpinSailTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setup() throws RepositoryException {
	NotifyingSail baseSail = new MemoryStore();
	DedupingInferencer deduper = new DedupingInferencer(baseSail);
	SchemaCachingRDFSInferencer rdfsInferencer = new SchemaCachingRDFSInferencer(deduper, false);
	SpinSail spinSail = new SpinSail(rdfsInferencer);
	repo = new SailRepository(spinSail);
	repo.initialize();
	conn = repo.getConnection();
}
 
Example 9
Source File: ReasoningBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private SailRepository createSchema() throws IOException {
	SailRepository schema = new SailRepository(new MemoryStore());
	schema.initialize();

	try (SailRepositoryConnection schemaConnection = schema.getConnection()) {
		schemaConnection.begin();
		schemaConnection.add(resourceAsStream("schema.ttl"), "", RDFFormat.TURTLE);
		schemaConnection.commit();
	}
	return schema;
}
 
Example 10
Source File: TimeAwareHBaseSailTest.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Test
public void timestampDateTimeTest() throws Exception {
    CloseableIteration<? extends Statement, SailException> iter;
    HBaseSail sail = new TimeAwareHBaseSail(HBaseServerTestInstance.getInstanceConfig(), "timestamptable", true, 0, true, 0, null, null);
    SailRepository rep = new SailRepository(sail);
    rep.initialize();
    SailRepositoryConnection con = rep.getConnection();
    assertTrue(testUpdate(con, "insert {<http://whatever> <http://whatever> <http://whatever>} where {bind(\"2002-05-30T09:30:10.2\"^^<http://www.w3.org/2001/XMLSchema#dateTime> as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
    assertTrue(testUpdate(con, "delete {<http://whatever> <http://whatever> <http://whatever>} where {bind(\"2002-05-30T09:30:10.1\"^^<http://www.w3.org/2001/XMLSchema#dateTime> as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
    assertFalse(testUpdate(con, "delete {<http://whatever> <http://whatever> <http://whatever>} where {bind(\"2002-05-30T09:30:10.4\"^^<http://www.w3.org/2001/XMLSchema#dateTime> as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
    assertFalse(testUpdate(con, "insert {<http://whatever> <http://whatever> <http://whatever>} where {bind(\"2002-05-30T09:30:10.3\"^^<http://www.w3.org/2001/XMLSchema#dateTime> as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
    assertTrue(testUpdate(con, "insert {<http://whatever> <http://whatever> <http://whatever>} where {bind(\"2002-05-30T09:30:10.4\"^^<http://www.w3.org/2001/XMLSchema#dateTime> as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
    rep.shutDown();
}
 
Example 11
Source File: Utils.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static SailRepository getInitializedShaclRepository(URL resourceName) {
	SailRepository repo = new SailRepository(new ShaclSail(new MemoryStore()));
	repo.initialize();
	try {
		Utils.loadShapeData(repo, resourceName);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
	return repo;
}
 
Example 12
Source File: SpinSailWithoutRDFSInferencerTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setup() throws RepositoryException {
	NotifyingSail baseSail = new MemoryStore();
	SpinSail spinSail = new SpinSail(baseSail);
	repo = new SailRepository(spinSail);
	repo.initialize();
	conn = repo.getConnection();
}
 
Example 13
Source File: FederationNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Repository createMember(String memberID, String name)
		throws RepositoryException, RDFParseException, IOException {
	SailRepository member = new SailRepository(new MemoryStore());
	member.initialize();
	try (SailRepositoryConnection con = member.getConnection()) {
		con.setNamespace(PREFIX, name);
	}
	return member;
}
 
Example 14
Source File: SolrSailExample.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Create a LuceneSail and add some triples to it, ask a query.
 */
public static void createSimple() throws Exception {
	// create a sesame memory sail
	MemoryStore memoryStore = new MemoryStore();

	// create a lucenesail to wrap the memorystore
	LuceneSail lucenesail = new LuceneSail();
	lucenesail.setParameter(LuceneSail.INDEX_CLASS_KEY, SolrIndex.class.getName());
	lucenesail.setParameter(SolrIndex.SERVER_KEY, "embedded:");

	// wrap memorystore in a lucenesail
	lucenesail.setBaseSail(memoryStore);

	// create a Repository to access the sails
	SailRepository repository = new SailRepository(lucenesail);
	repository.initialize();

	try ( // add some test data, the FOAF ont
			SailRepositoryConnection connection = repository.getConnection()) {
		connection.begin();
		connection.add(SolrSailExample.class.getResourceAsStream("/org/openrdf/sail/lucene/examples/foaf.rdfs"), "",
				RDFFormat.RDFXML);
		connection.commit();

		// search for resources that mention "person"
		String queryString = "PREFIX search:   <" + LuceneSailSchema.NAMESPACE + "> \n"
				+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + "SELECT * WHERE { \n"
				+ "?subject search:matches ?match . \n" + "?match search:query \"person\" ; \n"
				+ "       search:property ?property ; \n" + "       search:score ?score ; \n"
				+ "       search:snippet ?snippet . \n" + "?subject rdf:type ?type . \n" + "} LIMIT 3 \n"
				+ "BINDINGS ?type { \n" + " (<http://www.w3.org/2002/07/owl#Class>) \n" + "}";
		tupleQuery(queryString, connection);

		// search for property "name" with domain "person"
		queryString = "PREFIX search: <" + LuceneSailSchema.NAMESPACE + "> \n"
				+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + "SELECT * WHERE { \n"
				+ "?subject rdfs:domain ?domain . \n" + "?subject search:matches ?match . \n"
				+ "?match search:query \"chat\" ; \n" + "       search:score ?score . \n"
				+ "?domain search:matches ?match2 . \n" + "?match2 search:query \"person\" ; \n"
				+ "        search:score ?score2 . \n" + "} LIMIT 5";
		tupleQuery(queryString, connection);

		// search in subquery and filter results
		queryString = "PREFIX search:   <" + LuceneSailSchema.NAMESPACE + "> \n" + "SELECT * WHERE { \n"
				+ "{ SELECT * WHERE { \n" + "  ?subject search:matches ?match . \n"
				+ "  ?match search:query \"person\" ; \n" + "         search:property ?property ; \n"
				+ "         search:score ?score ; \n" + "         search:snippet ?snippet . \n" + "} } \n"
				+ "FILTER(CONTAINS(STR(?subject), \"Person\")) \n" + "} \n" + "";
		tupleQuery(queryString, connection);

		// search for property "homepage" with domain foaf:Person
		queryString = "PREFIX search: <" + LuceneSailSchema.NAMESPACE + "> \n"
				+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"
				+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
				+ "CONSTRUCT { ?x rdfs:domain foaf:Person } \n" + "WHERE { \n" + "?x rdfs:domain foaf:Person . \n"
				+ "?x search:matches ?match . \n" + "?match search:query \"homepage\" ; \n"
				+ "       search:property ?property ; \n" + "       search:score ?score ; \n"
				+ "       search:snippet ?snippet . \n" + "} LIMIT 3 \n";
		graphQuery(queryString, connection);
	} finally {
		repository.shutDown();
	}
}
 
Example 15
Source File: ArbitraryLengthPathTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Before
public void setUp() throws Exception {
	repo = new SailRepository(new MemoryStore());
	repo.initialize();
	con = repo.getConnection();
}
 
Example 16
Source File: LuceneNativeStoreTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Before
public void setUp() throws Exception {
	// repository folder
	File tmpDirFolder = tempDir.newFolder();
	log.debug("data file: {}", tmpDirFolder);

	// activate sail debug mode
	// System.setProperty("org.eclipse.rdf4j.repository.debug", "true");
	// load data into native store
	NativeStore store = new NativeStore(tmpDirFolder, "spoc,ospc,posc");

	// add Support for SPIN function
	SpinSail spin = new SpinSail(store);

	// add Lucene Spin Sail support
	LuceneSpinSail luc = new LuceneSpinSail(spin);
	repository = new SailRepository(luc);

	// set up parameters
	configure(luc.getParameters(), store.getDataDir());

	repository.initialize();
	// local connection used only for population
	try (RepositoryConnection localConn = repository.getConnection()) {
		localConn.begin();
		populate(localConn);
		localConn.commit();
	}

	// local connection for verification only
	try (RepositoryConnection localConn = repository.getConnection()) {
		// validate population. Transaction is not required
		// localConn.begin();
		int count = countStatements(localConn);
		log.trace("storage contains {} triples", count);
		Assert.assertTrue(count > 0);
		// localConn.commit();
		localConn.close();
	}

	// testing connection
	connection = repository.getConnection();
	connection.begin();
	Assert.assertTrue("connection is not active", connection.isActive());
}
 
Example 17
Source File: SchemaCachingRDFSInferencerRDFSchemaMemoryRepositoryConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testUpdateInsertData() {

	SailRepository sail = new SailRepository(new SchemaCachingRDFSInferencer(new MemoryStore()));
	sail.initialize();

	try (SailRepositoryConnection connection = sail.getConnection()) {

		IRI foo_s1 = connection.getValueFactory().createIRI("foo:s1");
		IRI foo_C2 = connection.getValueFactory().createIRI("foo:C2");

		connection.begin();
		connection.prepareUpdate("insert data { <foo:s1> a <foo:C1> . <foo:C1> rdfs:subClassOf <foo:C2> } ")
				.execute();
		connection.commit();

		assertTrue(connection.hasStatement(foo_s1, RDF.TYPE, foo_C2, true));

	}

}
 
Example 18
Source File: LuceneIndexTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
	 * Contexts can only be tested in combination with a sail, as the triples have to be retrieved from the sail
	 *
	 * @throws Exception
	 */
	@Test
	public void testContextsRemoveContext2() throws Exception {
		// add a sail
		MemoryStore memoryStore = new MemoryStore();
		// enable lock tracking
		org.eclipse.rdf4j.common.concurrent.locks.Properties.setLockTrackingEnabled(true);
		LuceneSail sail = new LuceneSail();
		sail.setBaseSail(memoryStore);
		sail.setLuceneIndex(index);

		// create a Repository wrapping the LuceneSail
		SailRepository repository = new SailRepository(sail);
		repository.initialize();

		try ( // now add the statements through the repo
				// add statements with context
				SailRepositoryConnection connection = repository.getConnection()) {
			connection.begin();
			connection.add(statementContext111, statementContext111.getContext());
			connection.add(statementContext121, statementContext121.getContext());
			connection.add(statementContext211, statementContext211.getContext());
			connection.add(statementContext222, statementContext222.getContext());
			connection.add(statementContext232, statementContext232.getContext());
			connection.commit();

			// check if they are there
			assertStatement(statementContext111);
			assertStatement(statementContext121);
			assertStatement(statementContext211);
			assertStatement(statementContext222);
			assertStatement(statementContext232);

			// delete context 2
			connection.begin();
			connection.clear(new Resource[] { CONTEXT_2 });
			connection.commit();
			assertStatement(statementContext111);
			assertStatement(statementContext121);
			assertStatement(statementContext211);
			assertNoStatement(statementContext222);
			assertNoStatement(statementContext232);
		} finally {
// close repo
			repository.shutDown();
		}
	}
 
Example 19
Source File: SchemaCachingRDFSInferencerRDFSchemaMemoryRepositoryConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
@Test
public void testUpdateRemove() {

	SailRepository sail = new SailRepository(new SchemaCachingRDFSInferencer(new MemoryStore()));
	sail.initialize();

	try (SailRepositoryConnection connection = sail.getConnection()) {

		IRI foo_s1 = connection.getValueFactory().createIRI("foo:s1");
		IRI foo_C2 = connection.getValueFactory().createIRI("foo:C2");

		connection.begin();
		connection.prepareUpdate("insert data { <foo:s1> a <foo:C1> . <foo:C1> rdfs:subClassOf <foo:C2> } ")
				.execute();
		connection.commit();

		assertTrue(connection.hasStatement(foo_s1, RDF.TYPE, foo_C2, true));

		connection.begin();
		connection.prepareUpdate("delete data { <foo:s1> a <foo:C1> . <foo:C1> rdfs:subClassOf <foo:C2> } ")
				.execute();
		connection.commit();

		assertFalse(connection.hasStatement(foo_s1, RDF.TYPE, foo_C2, true));

	}

}
 
Example 20
Source File: QueryStorage.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Create a new object for accessing the store of user queries.
 *
 * @param appConfig the application configuration, for obtaining the data directory
 * @throws RepositoryException if there is an issue creating the object to access the repository
 * @throws IOException
 */
protected QueryStorage(final AppConfiguration appConfig) throws RepositoryException, IOException {
	queries = new SailRepository(new NativeStore(new File(appConfig.getDataDir(), "queries")));
	queries.initialize();
}