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; }
private void loadOntology(Repository repository, URL url) throws RepositoryException, IOException, RDFParseException { String filename = url.toString(); RDFFormat format = formatForFileName(filename); RepositoryConnection conn = repository.getConnection(); ValueFactory vf = repository.getValueFactory(); try { String uri = url.toExternalForm(); conn.add(url, uri, format, vf.createURI(uri)); } finally { conn.close(); } }
private void initializeTripleStore() throws RepositoryException { /** Initialize an in-memory sesame triple store **/ myRepository = new SailRepository(new MemoryStore()); myRepository.initialize(); con = myRepository.getConnection(); f = myRepository.getValueFactory(); }
Model model = ...; // your model // create and initialize a temporary in-memory store Repository rep = new SailRepository(new MemoryStore()); rep.initialize(); try (RepositoryConnection conn = rep.getConnection()) { // load the model into the repository conn.add(model); // execute the query String query = "ASK WHERE { :s (:p1|:p2|:p3)+ :o . }"; boolean pathExists = conn.prepareBooleanQuery(query).evaluate(); }
private RDFTranslator(Repository repository, OWLOntologyManager manager, OWLOntology ontology) throws RepositoryException { super(manager, ontology, false); rdfFactory = repository.getValueFactory(); axiomResource = rdfFactory.createURI(OwlTripleStoreImpl.NS + "/" + UUID.randomUUID().toString().replace('-', '_')); connection = repository.getConnection(); }
public void testOpenWorldEq() throws Exception { final Sail sail = new MemoryStore(); final Repository repo = new SailRepository(sail); repo.initialize(); final RepositoryConnection cxn = repo.getConnection(); final URI mike = vf.createURI(BD.NAMESPACE + "mike"); final URI age = vf.createURI(BD.NAMESPACE + "age"); final Literal mikeAge = vf.createLiteral(34); cxn.add(vf.createStatement(mike, RDF.TYPE, RDFS.RESOURCE)); cxn.add(vf.createStatement(mike, age, mikeAge)); cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); while (result.hasNext()) { final BindingSet tmp = result.next(); if(log.isInfoEnabled()) log.info(tmp.toString()); cxn.close(); repo.shutDown();
@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); }
public interface Factory { SPARQLSyntaxTest createSPARQLSyntaxTest(String testURI, String testName, String testAction, boolean positiveTest); }
protected static String getManifestName(Repository manifestRep, RepositoryConnection con, String manifestFileURL) throws QueryEvaluationException, RepositoryException, MalformedQueryException { // Try to extract suite name from manifest file TupleQuery manifestNameQuery = con.prepareTupleQuery(QueryLanguage.SERQL, "SELECT ManifestName FROM {ManifestURL} rdfs:label {ManifestName}"); manifestNameQuery.setBinding("ManifestURL", manifestRep.getValueFactory().createURI(manifestFileURL)); TupleQueryResult manifestNames = manifestNameQuery.evaluate(); try { if (manifestNames.hasNext()) { return manifestNames.next().getValue("ManifestName").stringValue(); } } finally { manifestNames.close(); } // Derive name from manifest URL int lastSlashIdx = manifestFileURL.lastIndexOf('/'); int secLastSlashIdx = manifestFileURL.lastIndexOf('/', lastSlashIdx - 1); return manifestFileURL.substring(secLastSlashIdx + 1, lastSlashIdx); } }
@Test public void testEmptyCommit() throws Exception { assertThat(testCon.isEmpty(), is(equalTo(true))); assertThat(testCon2.isEmpty(), is(equalTo(true))); testCon.begin(); testCon.add(vf.createBNode(), vf.createURI(URN_PRED), vf.createBNode()); assertThat(testCon.isEmpty(), is(equalTo(false))); assertThat(testCon2.isEmpty(), is(equalTo(true))); testCon.commit(); testCon2.close(); testCon2 = testRepository.getConnection(); assertThat(testCon.isEmpty(), is(equalTo(false))); assertThat(testCon2.isEmpty(), is(equalTo(false))); }
private static void runDemo() throws Exception { Sail storage = new MemoryStore(); storage.initialize(); Sail linkedData = new LinkedDataSail(storage); ripple.initialize(); Repository repo = new SailRepository(ripple); RepositoryConnection rc = repo.getConnection(); "}"; TupleQueryResult r = rc.prepareTupleQuery(QueryLanguage.SPARQL, query2).evaluate(); while (r.hasNext()) { System.out.println("result: " + r.next()); rc.close(); repo.shutDown(); ripple.shutDown(); linkedData.shutDown();
protected Repository createRepository() throws RepositoryException { Repository repository = new SailRepository(new MemoryStore()); repository.initialize(); return repository; }
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(); } } }
public Set<String> getShardSurnames() throws RepositoryException, MalformedQueryException, QueryEvaluationException{ RepositoryConnection con = repository.getConnection(); String contribQuery = "" + " Select distinct s" + " from" + " {c} <"+RelConstants.RL_IS_PERSON+"> {p}" + " ," + " {c} <"+RelConstants.RL_SURNAME+"> {s}" + " where" + " p!=<http://yadda.icm.edu.pl/person#zbl#->" + ""; TupleQuery query = con.prepareTupleQuery(QueryLanguage.SERQL, contribQuery); TupleQueryResult res = query.evaluate(); HashSet<String> hs = new HashSet<String>(); while(res.hasNext()){ hs.add(res.next().getValue("s").stringValue()); } con.close(); con = null; return hs; }
/** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { logger.debug("setting up test"); this.rep = newRepository(); rep.initialize(); f = rep.getValueFactory(); conn = rep.getConnection(); conn.clear(); // clear existing data from repo bob = f.createURI(EX_NS, "bob"); alice = f.createURI(EX_NS, "alice"); mary = f.createURI(EX_NS, "mary"); logger.debug("test setup complete."); }
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; }
protected static String getManifestName(Repository manifestRep, RepositoryConnection con, String manifestFileURL) throws QueryEvaluationException, RepositoryException, MalformedQueryException { // Try to extract suite name from manifest file TupleQuery manifestNameQuery = con.prepareTupleQuery(QueryLanguage.SERQL, "SELECT ManifestName FROM {ManifestURL} rdfs:label {ManifestName}"); manifestNameQuery.setBinding("ManifestURL", manifestRep.getValueFactory().createIRI(manifestFileURL)); TupleQueryResult manifestNames = manifestNameQuery.evaluate(); try { if (manifestNames.hasNext()) { return manifestNames.next().getValue("ManifestName").stringValue(); } } finally { manifestNames.close(); } // Derive name from manifest URL int lastSlashIdx = manifestFileURL.lastIndexOf('/'); int secLastSlashIdx = manifestFileURL.lastIndexOf('/', lastSlashIdx - 1); return manifestFileURL.substring(secLastSlashIdx + 1, lastSlashIdx); } }