Java源码示例:org.openrdf.repository.http.HTTPRepository
示例1
public CustomSesameDataset(String sesameServer, String repositoryID) {
currentRepository = new HTTPRepository(sesameServer, repositoryID);
try {
currentRepository.initialize();
} catch (RepositoryException e) {
e.printStackTrace();
}
}
示例2
public QueryResultTable sparqlSelect(String endpointURL, String sparqlQuery) {
HTTPRepository endpoint = new HTTPRepository(endpointURL, "");
try {
endpoint.initialize();
RepositoryConnection connection = endpoint.getConnection();
return new RepositoryQueryResultTable(sparqlQuery, connection);
} catch(RepositoryException e) {
throw new ModelRuntimeException(e);
}
}
示例3
public static void _main(String[] args) throws Exception {
String sesameURL, repoID;
if (args != null && args.length == 2) {
sesameURL = args[0];
repoID = args[1];
} else {
sesameURL = DemoSesameServer.sesameURL;
repoID = DemoSesameServer.repoID;
}
Repository repo = new HTTPRepository(sesameURL, repoID);
repo.initialize();
RepositoryConnection cxn = repo.getConnection();
cxn.setAutoCommit(false);
try { // load some statements built up programmatically
URI mike = new URIImpl(BD.NAMESPACE + "Mike");
URI bryan = new URIImpl(BD.NAMESPACE + "Bryan");
URI loves = new URIImpl(BD.NAMESPACE + "loves");
URI rdf = new URIImpl(BD.NAMESPACE + "RDF");
Graph graph = new GraphImpl();
graph.add(mike, loves, rdf);
graph.add(bryan, loves, rdf);
cxn.add(graph);
cxn.commit();
} finally {
cxn.close();
}
{ // show the entire contents of the repository
SparqlBuilder sparql = new SparqlBuilder();
sparql.addTriplePattern("?s", "?p", "?o");
GraphQuery query = cxn.prepareGraphQuery(
QueryLanguage.SPARQL, sparql.toString());
GraphQueryResult result = query.evaluate();
while (result.hasNext()) {
Statement stmt = result.next();
System.err.println(stmt);
}
}
}