本文整理汇总了Java中org.openrdf.repository.Repository类的典型用法代码示例。如果您正苦于以下问题:Java Repository类的具体用法?Java Repository怎么用?Java Repository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Repository类属于org.openrdf.repository包,在下文中一共展示了Repository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.openrdf.repository.Repository; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws IOException, RepositoryException, RDFParseException {
int port;
try (final ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
}
server = CommunityServerBuilder.server()
.onPort(port)
.withThirdPartyJaxRsPackage("de.unikiel.inf.comsys.neo4j", "/rdf")
.build();
server.start();
GraphDatabaseService db = server.getDatabase().getGraph();
Repository rep = RepositoryRegistry.getInstance(db).getRepository();
conn = rep.getConnection();
InputStream testdata = RDFServerExtensionTest.class.getResourceAsStream("/sp2b.n3");
conn.add(testdata, "http://example.com/", RDFFormat.N3);
}
示例2: setUp
import org.openrdf.repository.Repository; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Repository fromrepo = new SailRepository( new MemoryStore() );
Repository torepo = new SailRepository( new MemoryStore() );
fromrepo.initialize();
torepo.initialize();
from = fromrepo.getConnection();
to = torepo.getConnection();
from.add( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "test" ) ) );
from.add( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "test2" ) ) );
from.setNamespace( OWL.PREFIX, OWL.NAMESPACE );
}
示例3: testUpdateDate2
import org.openrdf.repository.Repository; //导入依赖的package包/类
@Test
public void testUpdateDate2() throws Exception {
Repository repo = new SailRepository( new MemoryStore() );
repo.initialize();
RepositoryConnection rc = repo.getConnection();
URI base = Utility.getUniqueUri();
Date now = new Date();
rc.add( new StatementImpl( base, MetadataConstants.DCT_MODIFIED,
rc.getValueFactory().createLiteral( now ) ) );
AbstractSesameEngine.updateLastModifiedDate( rc, null );
List<Statement> stmts = Iterations.asList( eng.getRawConnection().
getStatements( eng.getBaseUri(), MetadataConstants.DCT_MODIFIED,
null, false ) );
Literal val = Literal.class.cast( stmts.get( 0 ).getObject() );
Date upd = getDate( val.calendarValue() );
rc.close();
repo.shutDown();
// the 100 is to remove the ms, which aren't always the same because
// they're not stored in the RDF
assertEquals( now.getTime(), upd.getTime(), 100 );
}
示例4: extractAllStatements
import org.openrdf.repository.Repository; //导入依赖的package包/类
@Override
public LinkedList<Statement> extractAllStatements(Repository repo, int nrTriples) {
RepositoryConnection con = repo.getConnection();
RepositoryResult<Statement> triples = con.getStatements(null, null,
null, false);
LinkedList<Statement> statements = new LinkedList<Statement>();
try {
System.out.println("triples to extract: "+nrTriples);
if(nrTriples == -1)
Iterations.addAll(triples, statements);
else {
int count = 0;
while(triples.hasNext() && count < nrTriples){
statements.add(triples.next());
count++;
}
}
} finally {
triples.close();
con.close();
}
return statements;
}
示例5: getDeleteDataResult
import org.openrdf.repository.Repository; //导入依赖的package包/类
/**
* Delete data from the graph.
*
* @param repository the Repository object
* @param request the HttpServletRequest object
* @param response the HttpServletResponse object
* @return the EmptySuccessView if successes
* @throws ClientHTTPException throws when there are errors in getting the name of the Graph
* @throws ServerHTTPException throws when errors happens update the data
*/
private ModelAndView getDeleteDataResult(final Repository repository,
final HttpServletRequest request, final HttpServletResponse response)
throws ClientHTTPException, ServerHTTPException {
ProtocolUtil.logRequestParameters(request);
ValueFactory vf = repository.getValueFactory();
URI graph = getGraphName(request, vf);
try {
RepositoryConnection repositoryCon = repository.getConnection();
synchronized (repositoryCon) {
repositoryCon.clear(graph);
}
repositoryCon.close();
return new ModelAndView(EmptySuccessView.getInstance());
} catch (RepositoryException e) {
throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
}
}
示例6: getRepository
import org.openrdf.repository.Repository; //导入依赖的package包/类
@Override
/**
* instantiate and return repository
*
*/
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {
MarkLogicRepository repo = null;
MarkLogicRepositoryConfig cfg = (MarkLogicRepositoryConfig) config;
if (cfg.getHost() != null && cfg.getPort() != 0) {
// init with MarkLogicRepositoryConfig
repo = new MarkLogicRepository(cfg.getHost(),cfg.getPort(),cfg.getUser(),cfg.getPassword(),cfg.getAuth());
} else if (cfg.getHost() == null) {
// init with queryEndpoint as connection string
try {
repo = new MarkLogicRepository(new URL(cfg.getQueryEndpointUrl()));
} catch (MalformedURLException e) {
logger.debug(e.getMessage());
throw new RepositoryConfigException(e.getMessage());
}
}else{
throw new RepositoryConfigException("Invalid configuration class: " + config.getClass());
}
return repo;
}
示例7: testGetRepository
import org.openrdf.repository.Repository; //导入依赖的package包/类
@Test
public void testGetRepository() throws Exception {
MarkLogicRepositoryConfig config = new MarkLogicRepositoryConfig();
config.setHost(host);
config.setPort(port);
config.setUser(adminUser);
config.setPassword(adminPassword);
config.setAuth("DIGEST");
RepositoryFactory factory = new MarkLogicRepositoryFactory();
Assert.assertEquals("marklogic:MarkLogicRepository", factory.getRepositoryType());
Repository repo = factory.getRepository(config);
repo.initialize();
Assert.assertTrue(repo.getConnection() instanceof MarkLogicRepositoryConnection);
Repository otherrepo = factory.getRepository(config);
otherrepo.initialize();
RepositoryConnection oconn = otherrepo.getConnection();
Assert.assertTrue(oconn instanceof MarkLogicRepositoryConnection);
}
示例8: removeIndirectTriples
import org.openrdf.repository.Repository; //导入依赖的package包/类
/**Takes as input a set of triples and some important URIs and removes from the
* first set those triples that have one of the given URIS as their subject.
* If we imagine the given set of triples as a graph, this method will practically
* return a subgraph containing only the direct neighbours of the given URIs.
*
* @param nTriples a set of triples in NTriples format
* @param urisToKeep the URIs that will be used for determining which triples to keep (those appearing in subject, or object field)
* @return a subgraph in the form of triples in NTriples format, containing only the direct neighbours of the given URIs. */
public static String removeIndirectTriples(String nTriples, List<String> urisToKeep){
String triplesContext="http://triplesContext";
String subTriplesContext="http://subgraphTriplesContext";
Repository repository=new SailRepository(new ForwardChainingRDFSInferencer(new MemoryStore()));
try{
repository.initialize();
RepositoryConnection repoConn=repository.getConnection();
repoConn.add(new StringReader(nTriples), triplesContext, RDFFormat.NTRIPLES, repository.getValueFactory().createURI(triplesContext));
RepositoryResult<Statement> results=repoConn.getStatements(null, null, null, false, repository.getValueFactory().createURI(triplesContext));
while(results.hasNext()){
Statement result=results.next();
if(urisToKeep.contains(result.getSubject().stringValue()) || urisToKeep.contains(result.getObject().stringValue())){
repoConn.add(result, repository.getValueFactory().createURI(subTriplesContext));
}
}
ByteArrayOutputStream out=new ByteArrayOutputStream();
RDFWriter writer=Rio.createWriter(RDFFormat.NTRIPLES, out);
repoConn.export(writer, repository.getValueFactory().createURI(subTriplesContext));
repoConn.close();
return new String(out.toByteArray(),"UTF-8");
}catch(RepositoryException | IOException | RDFParseException | RDFHandlerException ex) {
logger.error("Cannot parse ntriples file - Return the original NTriples file",ex);
return nTriples;
}
}
示例9: getUpdateNamespaceResult
import org.openrdf.repository.Repository; //导入依赖的package包/类
/**
* update the namespace.
*
* @param repository the Repository object
* @param request the HttpServletRequest object
* @param prefix the prefix
* @return EmptySuccessView object if success
* @throws IOException throws if there is error reading the namespace from the HttpServletRequest
* @throws ClientHTTPException throws if No namespace name found in request body
* @throws ServerHTTPException throws when there is error about the repository
*/
private ModelAndView getUpdateNamespaceResult(final Repository repository, final HttpServletRequest request, final String prefix)
throws IOException, ClientHTTPException, ServerHTTPException {
String namespace = IOUtil.readString(request.getReader());
namespace = namespace.trim();
if (namespace.length() == 0) {
throw new ClientHTTPException(SC_BAD_REQUEST, "No namespace name found in request body");
}
try {
RepositoryConnection repositoryCon = repository.getConnection();
synchronized (repositoryCon) {
repositoryCon.setNamespace(prefix, namespace);
}
repositoryCon.close();
} catch (RepositoryException e) {
throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
}
return new ModelAndView(EmptySuccessView.getInstance());
}
示例10: unserializeArray
import org.openrdf.repository.Repository; //导入依赖的package包/类
/**
* Unserializes an array object from the graph.
*
* @param objectToUnserialize The object in which there is an array field
* @param objectRootURI The URI of the object in which there is an array field
* @param repo The repository containing the RDF graph
* @param field The field that is the array
* @param predicateName The name of the predicate for the array items
* @throws IllegalAccessException If the field cannot be set
*/
private <T> void unserializeArray( final T objectToUnserialize,
final String objectRootURI, final Repository repo, final Field field,
final URIImpl predicateName ) throws IllegalAccessException
{
final Class<?> componentType = field.getType().getComponentType();
// Go get all the array objects
@SuppressWarnings( "unchecked" )
final T[] seq = (T[])this
.extractCollectionObjects( objectRootURI, repo,
componentType, field.getName(),
objectRootURI, predicateName
.stringValue() );
// Set the field up
field.setAccessible( true );
field.set( objectToUnserialize, seq );
}
示例11: setRepository
import org.openrdf.repository.Repository; //导入依赖的package包/类
/**
* Configures the Repository (Connector for local/remote SPARQL repository) to use in Anno4j.
*
* @param repository Repository to use in Anno4j.
* @param conceptJars URLs of JAR-files that are scanned for concepts.
* @param behaviourJars URLs of JAR-files that are scanned for behaviours.
* @throws RepositoryException
* @throws RepositoryConfigException
*/
public void setRepository(Repository repository, Set<URL> conceptJars, Set<URL> behaviourJars) throws RepositoryException, RepositoryConfigException {
this.repository = repository;
// update alibaba wrapper
ObjectRepositoryFactory factory = new ObjectRepositoryFactory();
ObjectRepositoryConfig config = factory.getConfig();
for(URL conceptJar : conceptJars) {
config.addConceptJar(conceptJar);
}
for(URL behaviourJar : behaviourJars) {
config.addBehaviourJar(behaviourJar);
}
if(partialClasses != null) {
for(Class<?> clazz : this.partialClasses){
if (!clazz.getSimpleName().endsWith("AbstractClass")) {
config.addBehaviour(clazz);
}
}
}
this.objectRepository = new ObjectRepositoryFactory().createRepository(config, repository);
this.objectRepository.setIdGenerator(idGenerator);
}
示例12: main
import org.openrdf.repository.Repository; //导入依赖的package包/类
public static void main(String[] args) {
String sparql = sparql1(); // Fully specified query
// String sparql = sparql2(); // Minimally specified query
// String sparql = sparql3(); // Observations with value and unit
EntityFactory f = EntityFactory.getInstance("http://example.org#");
Repository r = new SailRepository(new MemoryStore());
KnowledgeStore ks = new SesameKnowledgeStore(r);
ks.addSensor(f.createSensor("thermometer", "temperature", "air", 1.0));
ks.addSensor(f.createSensor("hygrometer", "humidity", "air", 1.0));
Emrooz emrooz = new Emrooz(ks, new CassandraDataStore());
ResultSet<BindingSet> results = emrooz.evaluate(
QueryType.SENSOR_OBSERVATION, sparql);
while (results.hasNext()) {
System.out.println(results.next());
}
results.close();
emrooz.close();
}
示例13: main
import org.openrdf.repository.Repository; //导入依赖的package包/类
public static void main(String[] args) {
// For non-volatile stores check
// http://rdf4j.org/sesame/2.8/docs/programming.docbook?view#section-repository-api
// Example: new SailRepository(new MemoryStore(new File("/tmp/ks")))
Repository r = new SailRepository(new MemoryStore());
KnowledgeStore ks = new SesameKnowledgeStore(r);
// Loads this KB, which may contain sensor specifications
ks.load(new File("src/examples/resources/kb.rdf"));
// Load sensor specifications programmatically
ks.addSensor(sensor1());
ks.addSensor(sensor2());
ks.addSensor(sensor3());
ks.addSensor(sensor4());
ks.close();
}
示例14: main
import org.openrdf.repository.Repository; //导入依赖的package包/类
public static void main(String[] args) {
EntityFactory f = EntityFactory.getInstance("http://example.org#");
// Repository r = new SailRepository(new MemoryStore());
Repository r = new SailRepository(new NativeStore(new File("/tmp/ks")));
KnowledgeStore ks = new SesameKnowledgeStore(r);
ks.addSensor(f.createSensor("thermometer", "temperature", "air", 1.0));
ks.addSensor(f.createSensor("hygrometer", "humidity", "air", 1.0));
Emrooz emrooz = new Emrooz(ks, new CassandraDataStore());
emrooz.add(f.createSensorObservation("thermometer", "temperature",
"air", 7.6, "2015-04-21T01:00:00.000+03:00"));
emrooz.add(f.createSensorObservation("hygrometer", "humidity", "air",
76.0, "2015-04-21T01:00:00.000+03:00"));
emrooz.add(f.createSensorObservation("thermometer", "temperature",
"air", 7.4, f.createUnit(QUDTUnit.DegreeCelsius),
"2015-04-21T01:30:00.000+03:00"));
emrooz.add(f.createSensorObservation("hygrometer", "humidity", "air",
84.0, QUDTUnit.RelativeHumidity,
"2015-04-21T01:30:00.000+03:00"));
emrooz.close();
}
示例15: SesameKnowledgeStore
import org.openrdf.repository.Repository; //导入依赖的package包/类
public SesameKnowledgeStore(Repository repository) {
if (repository == null)
throw new RuntimeException("[repository = null]");
this.repository = repository;
try {
this.repository.initialize();
this.connection = this.repository.getConnection();
} catch (RepositoryException e) {
if (log.isLoggable(Level.SEVERE))
log.severe(e.getMessage());
}
this.vf = connection.getValueFactory();
this.representer = new RDFEntityRepresenter();
loadProperties();
loadFeatures();
loadSensors();
loadDatasets();
}