public interface Factory { SPARQLSyntaxTest createSPARQLSyntaxTest(String testURI, String testName, String testAction, boolean positiveTest); }
@Test public void testAddStatement() throws Exception { testCon.add(bob, name, nameBob); assertTrue(NEWLY_ADDED, testCon.hasStatement(bob, name, nameBob, false)); Statement statement = vf.createStatement(alice, name, nameAlice); testCon.add(statement); assertTrue(NEWLY_ADDED, testCon.hasStatement(statement, false)); assertTrue(NEWLY_ADDED, testCon.hasStatement(alice, name, nameAlice, false)); Repository tempRep = new SailRepository(new MemoryStore()); tempRep.initialize(); RepositoryConnection con = tempRep.getConnection(); con.add(testCon.getStatements(null, null, null, false)); assertTrue("Temp Repository should contain newly added statement", con.hasStatement(bob, name, nameBob, false)); con.close(); tempRep.shutDown(); }
public static ModelRepository create(Model model) throws RepositoryException { Sail sail = new MemoryStore(); Repository repo = new SailRepository(sail); repo.initialize(); RepositoryConnection conn = repo.getConnection(); conn.begin(); conn.add(model); conn.commit(); conn.close(); return new ModelRepository(sail); }
RepositoryConnection conn = rep.getConnection(); try { conn.begin(); // start a transaction conn.add(f.createURI("http://example.org/", "Turin"),RDF.PREDICATE,f.createURI("http://example.org/", "Timon")); conn.add(f.createURI("http://example.org/", "Turin"),RDF.PREDICATE,f.createURI("http://example.org/", "Timon")); conn.add(f.createURI("http://example.org/", "Timon"),RDF.PREDICATE, f.createURI("http://example.org/", "eddy")); conn.add(f.createURI("http://example.org/", "Pumba"),RDF.PREDICATE, f.createURI("http://example.org/", "Timon")); conn.commit(); } finally { conn.close(); }
String queryString = "SELECT ..."; RepositoryConnection conn = repo.getConnection(); try { TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); TupleQueryResult result = tq.evaluate(); } finally { conn.close(); }
@Test public void testSES1991NOWEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?d WHERE {?s ?p ?o . BIND(NOW() as ?d) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); Literal d1 = (Literal)result.next().getValue("d"); Literal d2 = (Literal)result.next().getValue("d"); assertNotNull(d1); assertEquals(d1, d2); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
public void insertPersons(RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException { TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, "select distinct ?x \n" + " where { \n" + " ?x <http://yadda.icm.edu.pl/yadda#has-surname> ?z \n" + "}"); TupleQueryResult res = query.evaluate(); try { while (res.hasNext()) { String x = res.next().getValue("x").stringValue(); checkSingleContributor(conn, x); } } finally { res.close(); } }
@Test public void testInComparison1() throws Exception { loadTestData("/testdata-query/dataset-ses1913.trig"); StringBuilder query = new StringBuilder(); query.append(" PREFIX : <http://example.org/>\n"); query.append(" SELECT ?y WHERE { :a :p ?y. FILTER(?y in (:c, :d, 1/0 , 1)) } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); TupleQueryResult result = tq.evaluate(); assertNotNull(result); assertTrue(result.hasNext()); BindingSet bs = result.next(); Value y = bs.getValue("y"); assertNotNull(y); assertTrue(y instanceof Literal); assertEquals(f.createLiteral("1", XMLSchema.INTEGER), y); }
public TestSuite createTestSuite() throws Exception { // Create test suite TestSuite suite = new TestSuite(this.getClass().getName()); // Add the manifest for W3C test cases to a repository and query it Repository w3cRepository = new SailRepository(new MemoryStore()); w3cRepository.initialize(); RepositoryConnection w3cCon = w3cRepository.getConnection(); InputStream inputStream = this.getClass().getResourceAsStream(TEST_W3C_MANIFEST_URL); w3cCon.add(inputStream, TEST_W3C_MANIFEST_URI_BASE, RDFFormat.TURTLE); parsePositiveNTriplesSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeNTriplesSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TEST_W3C_TEST_URI_BASE, w3cCon); w3cCon.close(); w3cRepository.shutDown(); return suite; }
@Test public void testQueryBaseURI() throws Exception { testCon.add(vf.createURI(URN_TEST_S1), vf.createURI(URN_TEST_P1), vf.createURI(URN_TEST_O1)); TupleQueryResult rs = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * { <> ?p ?o }", URN_TEST_S1).evaluate(); try { assertThat(rs.hasNext(), is(equalTo(true))); } finally { rs.close(); } }
private void addDummyData(final Sail sail) throws Exception { Repository repo = new SailRepository(sail); RepositoryConnection rc = repo.getConnection(); try { rc.begin(); rc.add(RippleSail.class.getResource("rippleSailTest.trig"), "", RDFFormat.TRIG); rc.commit(); } finally { rc.rollback(); rc.close(); } } }
private void doInsert(final RepositoryConnection conn, final int loop, final int index) throws RepositoryException { final ValueFactory vf = conn.getValueFactory(); final URI c = vf.createURI("context:loop:" + loop + ":item:" + index); final URI s = vf.createURI("subject:loop:" + loop + ":item:" + index); for (int x = 0; x < NUM_STATEMENTS_PER_INSERT; ++x) { final URI p = vf.createURI("predicate:" + x); final Literal o = vf.createLiteral("SomeValue"); conn.add(s, p, o, c); } }
private void setupNamespaces() throws IOException, RDFParseException, RepositoryException { testCon.setNamespace(EXAMPLE, EXAMPLE_NS); testCon.setNamespace(RDF_PREFIX, "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); testCon.setNamespace(RDFS_PREFIX, RDFS_NS); // Translated from earlier RDF document. Is this line even necessary? testCon.add(vf.createURI(EXAMPLE_NS, "Main"), vf.createURI(RDFS_NS, "label"), vf.createLiteral("Main Node")); }
private void populate(int n) throws RepositoryException { ValueFactory vf = con.getValueFactory(); for (int i = 0; i < n; i++) { con.add(vf.createURI("urn:test:root"), vf.createURI("urn:test:hasChild"), vf.createURI("urn:test:node" + i)); } con.add(vf.createURI("urn:test:root"), vf.createURI("urn:test:hasChild"), vf.createURI("urn:test:node-end")); }
public static SailRepository exportRepoToNativeStore(Repository rep, String dirPath) throws RepositoryException, FileNotFoundException, RDFHandlerException{ File f = new File(dirPath); if(f.exists()) f.delete(); f.mkdirs(); NativeStore nativeStore = new NativeStore(f); SailRepository nativeRepo = new SailRepository(nativeStore); nativeRepo.initialize(); RepositoryResult<Statement> rr = rep.getConnection().getStatements((Resource)null, null, null, false, (Resource)null); nativeRepo.getConnection().add(rr.asList(), (Resource)null); return nativeRepo; }
@Test public void testInferredStatementCount() throws Exception { assertThat(testCon.isEmpty(), is(equalTo(true))); int inferred = getTotalStatementCount(testCon); URI root = vf.createURI("urn:root"); testCon.add(root, RDF.TYPE, RDF.LIST); testCon.remove(root, RDF.TYPE, RDF.LIST); assertThat(testCon.isEmpty(), is(equalTo(true))); assertThat(getTotalStatementCount(testCon), is(equalTo(inferred))); }
private void addLogicalSource(KR2RMLMapping mapping, Worksheet worksheet, Resource mappingRes, URI trMapUri) throws RepositoryException { // Add the Logical table information BNode logTableBNode = f.createBNode(); con.add(logTableBNode, repoURIs.get(Uris.RR_TABLENAME_URI), f.createLiteral(worksheet.getTitle())); con.add(logTableBNode, RDF.TYPE, repoURIs.get(Uris.RR_LOGICAL_TABLE_CLASS_URI)); con.add(logTableBNode, repoURIs.get(Uris.KM_IS_PART_OF_MAPPING_URI), mappingRes); con.add(mappingRes, repoURIs.get(Uris.KM_HAS_LOGICAL_TABLE_URI), logTableBNode); con.add(trMapUri, repoURIs.get(Uris.RR_LOGICAL_TABLE_URI), logTableBNode); }
@Override public Object execute(Object repository, Map<String, Object> operationParam) { String relationName = (String) operationParam.get("relationName"); Repository repo = (Repository) repository; try { repo.getConnection().remove((Resource)null, repo.getConnection().getValueFactory().createURI(relationName), (Resource)null,(Resource)null); } catch (Exception e) { return e; } return null; }