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

The following examples show how to use org.openrdf.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: SPARQLInferenceTest.java    From neo4j-sparql-extension with GNU General Public License v3.0 6 votes vote down vote up
@Before
public void before()
		throws RepositoryException, IOException, RDFParseException,
		       MalformedQueryException, QueryResultParseException,
			   QueryResultHandlerException {
	repo = new SailRepository(new MemoryStore());
	repo.initialize();
	conn = repo.getConnection();
	vf = conn.getValueFactory();
	conn.add(getResource(data), "file://", RDFFormat.TURTLE);
	SPARQLResultsXMLParserFactory factory =
			new SPARQLResultsXMLParserFactory();
	parser = factory.getParser();
	parser.setValueFactory(vf);
	List<Rule> rules;
	rules = Rules.fromOntology(getResource(data));
	QueryRewriter rewriter = new QueryRewriter(conn, rules);
	query = (TupleQuery) rewriter.rewrite(QueryLanguage.SPARQL, queryString);
	nonInfQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
	System.out.println("== QUERY (" + this.name + ") ==");
	System.out.println(nonInfQuery);
	System.out.println("== REWRITTEN QUERY (" + this.name + ") ==");
	System.out.println(query);
}
 
Example 2
Source File: RangeQueriesTest.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * Setup fixture for this test case.
 * 
 * @throws Exception never, otherwise the test fails.
 */
@BeforeClass
public static void setUp() throws Exception {
	_repository = new SailRepository(new MemoryStore());
	_repository.initialize();

	_tripleStore = newTripleStore();
	_tripleStore.enableRangeIndexesSupport();
	_tripleStore.open();

	assertTrue("Ranges have not been enabled for this triple store!", _tripleStore.isRangeIndexesSupportEnabled());

	_tripleStore.bulkLoad(DATA, RDFFormat.NTRIPLES);

	_repositoryConnection = _repository.getConnection();
	_repositoryConnection.add(new File(DATA), "http://nb-base-uri-not-actually-used", RDFFormat.NTRIPLES);
}
 
Example 3
Source File: TestTicket276.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void executeQuery(final SailRepository repo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException, RDFParseException, IOException,
		RDFHandlerException {
	try {
		repo.initialize();
		final RepositoryConnection conn = repo.getConnection();
		conn.setAutoCommit(false);
		try {
            final ValueFactory vf = conn.getValueFactory();
			addData(conn);
			conn.commit();

			final String query = "SELECT ?x { ?x ?a ?t . ?x ?lookup ?l }";
			final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL,
					query);
			q.setBinding(
					"a",
					vf.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
			q.setBinding("t", vf.createURI("os:class/Location"));
			q.setBinding("lookup", vf.createURI("os:prop/lookupName"));
			q.setBinding("l", vf.createLiteral("amsterdam"));
			final TupleQueryResult tqr = q.evaluate();
               while (tqr.hasNext()) {
                   final Set<String> bindingNames = tqr.next()
                           .getBindingNames();
                   if (log.isInfoEnabled())
                       log.info("bindingNames=" + bindingNames);
			}
			tqr.close();
		} finally {
			conn.close();
		}
	} finally {
		repo.shutDown();
	}
}
 
Example 4
Source File: LinkedDataServletTest.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
	TRIPLE_STORE = newTripleStore();
	SAIL = new CumulusRDFSail(TRIPLE_STORE);
	REPOSITORY = new SailRepository(SAIL);
	REPOSITORY.initialize();
}
 
Example 5
Source File: IntegrationTestSupertypeLayer.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Setup fixture for this test.
 */
@BeforeClass
public static void init() throws Exception {
	inMemoryRepository = new SailRepository(new MemoryStore());
	cumulusRepository = new SailRepository(new CumulusRDFSail(new TripleStore()));
	
	inMemoryRepository.initialize();
	cumulusRepository.initialize();
	
	localConnection = inMemoryRepository.getConnection();
	cumulusConnection = cumulusRepository.getConnection();
}
 
Example 6
Source File: TestTicket275.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void executeQuery(final SailRepository repo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException, RDFParseException, IOException {
	try {
		repo.initialize();
		final RepositoryConnection conn = repo.getConnection();
		conn.setAutoCommit(false);
		try {
			conn.add(getClass().getResourceAsStream("TestTicket275.ttl"), "",
					RDFFormat.TURTLE);
			conn.commit();

			final String query = "SELECT ?lookup WHERE { ?lookup <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <os:class/Lookup> . ?lookup <os:prop/lookup/majorType> ?majorType . OPTIONAL{?lookup <os:prop/lookup/minorType> ?minorType}. FILTER(STR(?majorType) = ?argMajorType). FILTER(!bound(?minorType))}";
			final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL,
					query);
			q.setBinding("argMajorType", conn.getValueFactory()
					.createLiteral("majoor"));
			final TupleQueryResult tqr = q.evaluate();
			while (tqr.hasNext()) {
			    final Set<String> bindingNames = tqr.next().getBindingNames();
			    if(log.isInfoEnabled())
			        log.info("bindingNames="+bindingNames);
			}
			tqr.close();
		} finally {
			conn.close();
		}
	} finally {
		repo.shutDown();
	}
}
 
Example 7
Source File: TestTicket1681.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void executeQuery(final SailRepository repo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException, RDFParseException, IOException {
	try {
		repo.initialize();
		final RepositoryConnection conn = repo.getConnection();
		conn.setAutoCommit(false);
		try {
			conn.add(getClass().getResourceAsStream("TestTicket1681.nt"), "",
					RDFFormat.TURTLE);
			conn.commit();

			final String query = "SELECT * WHERE { ?s <http://p>  ?o . FILTER (?o IN (<http://o2>, <http://o3>) ) }";
			final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL,
					query);
			final TupleQueryResult tqr = q.evaluate();
			int cnt = 0;
			while (tqr.hasNext()) {
			    final Set<String> bindingNames = tqr.next().getBindingNames();
			    cnt++;
			    if(log.isInfoEnabled())
			        log.info("bindingNames="+bindingNames);
			}
			tqr.close();
			assertEquals(1, cnt);
		} finally {
			conn.close();
		}
	} finally {
		repo.shutDown();
	}
}
 
Example 8
Source File: TestTicket355.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void executeQuery(final SailRepository repo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException, RDFParseException, IOException,
		RDFHandlerException {
	try {
		repo.initialize();
		final RepositoryConnection conn = repo.getConnection();
		conn.setAutoCommit(false);
		try {
			final ValueFactory vf = conn.getValueFactory();
			conn.add(vf.createURI("os:subject"), vf.createURI("os:prop"), vf.createLiteral("value"));
			conn.commit();

			String query = "SELECT ?subj WHERE { "
					+ "?subj <os:prop> ?val . "
					+ "FILTER(STR(?val) != ?arg)}";
			TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
			tq.setBinding("arg", vf.createLiteral("notValue"));
			TupleQueryResult tqr = tq.evaluate();
			assertTrue(tqr.hasNext());
			tqr.close();
		} finally {
			conn.close();
		}
	} finally {
		repo.shutDown();
	}
}
 
Example 9
Source File: SesameHTTPRepositoryTest.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Setup fixture for all tests.
 * 
 * @throws Exception never otherwise tests fail.
 */
@BeforeClass
public static void setUp() throws Exception {
	
	TRIPLE_STORE = newTripleStore();
	SAIL = new CumulusRDFSail(TRIPLE_STORE);
	REPOSITORY = new SailRepository(SAIL);
	REPOSITORY.initialize();

	RepositoryManager.getInstance().addRepository(REPO_ID, REPOSITORY, true);
}
 
Example 10
Source File: MergeEmptyListsTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
protected void init() {

			try {

				module.addConcept(SomePerson.class);

				// module.addBehaviour(PropertyChangeNotifierSupport.class,
				// Person.PERSON);

				// Register behaviours
				// module.addRole(PersonBehavior.class);

				// Prepare repository
				repository = new SailRepository(new MemoryStore());
				repository = new NotifyingRepositoryWrapper(repository);

				if (repository instanceof NotifyingRepository) {
					// NotifyingRepository notifyingRepository = null;
					//	                    
					// listener = new
					// RepositoryConnectionListenerImpl(visualRoot);
					//	                    
					// notifyingRepository = (NotifyingRepository)repository;
					// notifyingRepository.addRepositoryConnectionListener(listener);
				}

				// repository = new NotifyingRepositoryConnection(repository);

				// Prepare factory and manager
				repository.initialize();
				factory = new ObjectRepositoryFactory().createRepository(module, repository);
				factory.setQueryLanguage(QueryLanguage.SERQL);
				manager = factory.getConnection();

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
 
Example 11
Source File: TestTicket353.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void executeQuery(final SailRepository repo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException, RDFParseException, IOException,
		RDFHandlerException {
	try {
		repo.initialize();
		final RepositoryConnection conn = repo.getConnection();
		conn.setAutoCommit(false);
		try {
			final ValueFactory vf = conn.getValueFactory();
			conn.add(vf.createURI("os:subject"), vf.createURI("os:prop"), vf.createLiteral("value"));
			conn.commit();

			String query = 
				"SELECT ?b { {} union { ?a ?b ?c } }"
				;
			
			TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
			TupleQueryResult tqr = tq.evaluate();
			assertTrue(tqr.hasNext());
			
			while (tqr.hasNext()) {
				System.err.println(tqr.next());
			}
			
			tqr.close();
		} finally {
			conn.close();
		}
	} finally {
		repo.shutDown();
	}
}
 
Example 12
Source File: RDFSingleDataSet.java    From mustard with MIT License 5 votes vote down vote up
@Override
protected void initialize(){
	try {
		rdfRep = new SailRepository(new ForwardChainingRDFSInferencer(new MemoryStore()));
		rdfRep.initialize();
		
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 13
Source File: RecommendationServiceTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    SailRepository repository = new SailRepository(new MemoryStore());
    repository.initialize();

    anno4j = new Anno4j();

    anno4j.setRepository(repository);
    queryService = anno4j.createQueryService();
    queryService.addPrefix(ANNO4JREC.PREFIX, ANNO4JREC.NS);
}
 
Example 14
Source File: SimilarityStatementTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    SailRepository repository = new SailRepository(new MemoryStore());
    repository.initialize();

    anno4j = new Anno4j();

    anno4j.setRepository(repository);
    queryService = anno4j.createQueryService();
    queryService.addPrefix(ANNO4JREC.PREFIX, ANNO4JREC.NS);
}
 
Example 15
Source File: MergeTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testMergeBlankNodeFromOtherRepository() throws Exception {
	SailRepository repo = new SailRepository(new MemoryStore());
	repo.initialize();
	ObjectRepositoryFactory orf = new ObjectRepositoryFactory();
	ObjectRepository or = orf.createRepository(config, repo);
	ObjectConnection oc = or.getConnection();
	ValueFactory vf = oc.getValueFactory();
	Node n1 = oc.addDesignation(oc.getObject(vf.createBNode()), Node.class);
	Node n2 = oc.addDesignation(oc.getObject(vf.createBNode()), Node.class);
	n1.setSibling(n2);
	n2.setSibling(n1);
	Node m1 = (Node) con.getObject(con.addObject(n1));
	assertNotNull(m1.getSibling());
}
 
Example 16
Source File: RangeQueryOptimizationTest.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
	// Set up standard Sesame Repository for comparison
	EMBEDDED_REPOSITORY = new SailRepository(new MemoryStore());
	EMBEDDED_REPOSITORY.initialize();
	EMBEDDED_REPOSITORY_CONNECTION = EMBEDDED_REPOSITORY.getConnection();
	EMBEDDED_REPOSITORY_CONNECTION.add(DATAFILE, null, RDFFormat.N3);

	_tripleStore = new TripleStore();
	_sail = new CumulusRDFSail(_tripleStore);
	_repository = new SailRepository(_sail);
	_repository.initialize();

	CUMULUS_CONNECTION = _repository.getConnection();
}
 
Example 17
Source File: AbstractCRUDServletTest.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Prepares the execution of this test case.
 * 
 * @throws Exception hopefully never, otherwise the whole test case fails.
 */
@BeforeClass
public static void beforeAllTests() throws Exception {
	TRIPLE_STORE = newTripleStore();
	SAIL = new CumulusRDFSail(TRIPLE_STORE);
	REPOSITORY = new SailRepository(SAIL);
	REPOSITORY.initialize();
}
 
Example 18
Source File: AbstractRDFTestCase.java    From ldp4j with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpConnection() throws Exception {
	repository = new SailRepository(new MemoryStore());
	repository.initialize();
	connection = repository.getConnection();
}
 
Example 19
Source File: TestBigdataGraphEmbeddedRepository.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public BigdataSail getOrCreateRepository(String journalFile) {

		final java.util.Properties props = new java.util.Properties();
		SailRepository 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);// , Option.RDR);

		} else {

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

		}

		try {
			repo.initialize();
		} catch (RepositoryException e) {
			e.printStackTrace();
			testPrint(e.toString());
		}

		return (BigdataSail) repo.getSail();
	}
 
Example 20
Source File: TestTicket1682.java    From database with GNU General Public License v2.0 4 votes vote down vote up
private void executeQuery(final SailRepository repo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException, RDFParseException, IOException {
	try {
		repo.initialize();
		final RepositoryConnection conn = repo.getConnection();
		conn.setAutoCommit(false);
		try {
			conn.add(getClass().getResourceAsStream("TestTicket1682.nt"), "",
					RDFFormat.TURTLE);
			conn.commit();

			final String query = "select ?s with { " +
			        "   select ?s where {" +
                       "       ?s <http://p> ?o" +
                       "   } VALUES (?o) {" +
                       "       (\"a\") (\"b\")" +
                       "   }" +
                       "} AS %sub1 " +
                       "where {" +
                       "   INCLUDE %sub1" +
                       "}";
			final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL,
					query);
			final TupleQueryResult tqr = q.evaluate();
			int cnt = 0;
			while (tqr.hasNext()) {
			    final Set<String> bindingNames = tqr.next().getBindingNames();
			    cnt++;
			    if(log.isInfoEnabled())
			        log.info("bindingNames="+bindingNames);
			}
			tqr.close();
			assertEquals(2, cnt);
		} finally {
			conn.close();
		}
	} finally {
		repo.shutDown();
	}
}