Java源码示例:org.eclipse.rdf4j.sail.Sail
示例1
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
if (!(config instanceof FedXSailConfig)) {
throw new SailConfigException("FedXSail config expected, was " + config.getClass().getCanonicalName());
}
FedXSailConfig fedXSailConfig = (FedXSailConfig)config;
String fedxConfig = fedXSailConfig.getFedxConfig();
if (fedxConfig==null)
throw new SailConfigException("FedX Sail Configuration must not be null");
try {
return FedXFactory.initializeFederation(fedxConfig, new DefaultEndpointListProvider(Collections.<String>emptyList())).getSail();
} catch (FedXException e) {
throw new SailConfigException(e);
}
}
示例2
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
MemoryStore memoryStore = new MemoryStore();
if (config instanceof MemoryStoreConfig) {
MemoryStoreConfig memConfig = (MemoryStoreConfig) config;
memoryStore.setPersist(memConfig.getPersist());
memoryStore.setSyncDelay(memConfig.getSyncDelay());
if (memConfig.getIterationCacheSyncThreshold() > 0) {
memoryStore.setIterationCacheSyncThreshold(memConfig.getIterationCacheSyncThreshold());
}
EvaluationStrategyFactory evalStratFactory = memConfig.getEvaluationStrategyFactory();
if (evalStratFactory != null) {
memoryStore.setEvaluationStrategyFactory(evalStratFactory);
}
}
return memoryStore;
}
示例3
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
CustomGraphQueryInferencer sail = new CustomGraphQueryInferencer();
if (config instanceof CustomGraphQueryInferencerConfig) {
CustomGraphQueryInferencerConfig customConfig = (CustomGraphQueryInferencerConfig) config;
try {
sail.setFields(customConfig.getQueryLanguage(), customConfig.getRuleQuery(),
customConfig.getMatcherQuery());
} catch (RDF4JException e) {
throw new SailConfigException("Problem occured parsing rule or matcher query text.", e);
}
}
return sail;
}
示例4
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
LuceneSpinSail sail = new LuceneSpinSail();
Properties params = sail.getParameters();
// set up parameters
params.setProperty(LuceneSail.INDEX_CLASS_KEY, LuceneSail.DEFAULT_INDEX_CLASS);
if (config instanceof AbstractLuceneSailConfig) {
AbstractLuceneSailConfig luceneConfig = (AbstractLuceneSailConfig) config;
log.debug("Lucene indexDir: {}", luceneConfig.getIndexDir());
params.setProperty(LuceneSail.LUCENE_DIR_KEY, luceneConfig.getIndexDir());
for (String key : luceneConfig.getParameterNames()) {
params.setProperty(key, luceneConfig.getParameter(key));
}
}
return sail;
}
示例5
@Override
public Sail getSail(SailImplConfig sailImplConfig) throws SailConfigException {
if (!SAIL_TYPE.equals(sailImplConfig.getType())) {
throw new SailConfigException("Invalid Sail type: " + sailImplConfig.getType());
}
if (sailImplConfig instanceof ElasticsearchStoreConfig) {
ElasticsearchStoreConfig config = (ElasticsearchStoreConfig) sailImplConfig;
config.assertRequiredValuesPresent();
ElasticsearchStore elasticsearchStore = new ElasticsearchStore(config.getHostname(), config.getPort(),
config.getClusterName(), config.getIndex());
EvaluationStrategyFactory evalStratFactory = config.getEvaluationStrategyFactory();
if (evalStratFactory != null) {
elasticsearchStore.setEvaluationStrategyFactory(evalStratFactory);
}
return elasticsearchStore;
}
return null;
}
示例6
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
LuceneSail luceneSail = new LuceneSail();
luceneSail.setParameter(LuceneSail.INDEX_CLASS_KEY, LuceneIndex.class.getName());
if (config instanceof AbstractLuceneSailConfig) {
AbstractLuceneSailConfig luceneConfig = (AbstractLuceneSailConfig) config;
luceneSail.setParameter(LuceneSail.LUCENE_DIR_KEY, luceneConfig.getIndexDir());
for (String key : luceneConfig.getParameterNames()) {
luceneSail.setParameter(key, luceneConfig.getParameter(key));
}
}
return luceneSail;
}
示例7
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
LuceneSail luceneSail = new LuceneSail();
luceneSail.setParameter(LuceneSail.INDEX_CLASS_KEY, ElasticsearchIndex.class.getName());
if (config instanceof AbstractLuceneSailConfig) {
AbstractLuceneSailConfig luceneConfig = (AbstractLuceneSailConfig) config;
luceneSail.setParameter(LuceneSail.LUCENE_DIR_KEY, luceneConfig.getIndexDir());
for (String key : luceneConfig.getParameterNames()) {
luceneSail.setParameter(key, luceneConfig.getParameter(key));
}
}
return luceneSail;
}
示例8
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
LuceneSail luceneSail = new LuceneSail();
luceneSail.setParameter(LuceneSail.INDEX_CLASS_KEY, SolrIndex.class.getName());
if (config instanceof AbstractLuceneSailConfig) {
AbstractLuceneSailConfig luceneConfig = (AbstractLuceneSailConfig) config;
luceneSail.setParameter(LuceneSail.LUCENE_DIR_KEY, luceneConfig.getIndexDir());
for (String key : luceneConfig.getParameterNames()) {
luceneSail.setParameter(key, luceneConfig.getParameter(key));
}
}
return luceneSail;
}
示例9
@Test(expected = IllegalArgumentException.class)
public void near_negativeDistance() throws Exception {
final Sail sail = GeoRyaSailFactory.getInstance(conf);
final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
try {
populateRya(conn);
//Only captial
final String query =
"PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ "SELECT * \n" //
+ "WHERE { \n"
+ " <urn:geo> geo:asWKT ?point .\n"
+ " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, -100))"
+ "}";
final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
while(rez.hasNext()) {
rez.next();
}
} finally {
conn.close();
sail.shutDown();
}
}
示例10
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
assert config instanceof FederationConfig;
FederationConfig cfg = (FederationConfig) config;
Federation sail = new Federation();
for (RepositoryImplConfig member : cfg.getMembers()) {
RepositoryFactory factory = RepositoryRegistry.getInstance()
.get(member.getType())
.orElseThrow(() -> new SailConfigException("Unsupported repository type: " + config.getType()));
try {
sail.addMember(factory.getRepository(member));
} catch (RepositoryConfigException e) {
throw new SailConfigException(e);
}
}
sail.setLocalPropertySpace(cfg.getLocalPropertySpace());
sail.setDistinct(cfg.isDistinct());
sail.setReadOnly(cfg.isReadOnly());
return sail;
}
示例11
private static Repository createRepository(Properties properties) throws ModelRuntimeException {
// find out if we need reasoning
String reasoningProperty = properties == null ? null : properties.getProperty(REASONING);
boolean reasoning = Reasoning.rdfs.toString().equalsIgnoreCase(reasoningProperty);
// create a Sail stack
Sail sail = new MemoryStore();
if(reasoning) {
sail = new ForwardChainingRDFSInferencer((MemoryStore)sail);
}
// create a Repository
Repository repository = new SailRepository(sail);
try {
repository.initialize();
} catch(RepositoryException e) {
throw new ModelRuntimeException(e);
}
return repository;
}
示例12
@Test
public void testGetSail() throws Exception {
HBaseSailConfig hbsc = new HBaseSailConfig();
hbsc.setCreate(false);
hbsc.setPush(false);
hbsc.setSplitBits(3);
hbsc.setEvaluationTimeout(480);
hbsc.setTablespace("testtable");
hbsc.setElasticIndexURL("http://whatever/index");
Sail sail = new HBaseSailFactory().getSail(hbsc);
assertTrue(sail instanceof HBaseSail);
HBaseSail hbs = (HBaseSail)sail;
assertFalse(hbs.create);
assertFalse(hbs.pushStrategy);
assertEquals(3, hbs.splitBits);
assertEquals("testtable", hbs.tableName);
assertEquals(480, hbs.evaluationTimeout);
assertEquals("http://whatever/index", hbs.elasticIndexURL);
}
示例13
@Override
protected Sail makeSail(final Map<String, String> taskConfig) throws ConnectException {
requireNonNull(taskConfig);
// Parse the configuration object.
final AccumuloRyaSinkConfig config = new AccumuloRyaSinkConfig(taskConfig);
// Move the configuration into a Rya Configuration object.
final AccumuloRdfConfiguration ryaConfig = new AccumuloRdfConfiguration();
ryaConfig.setTablePrefix( config.getRyaInstanceName() );
ryaConfig.setAccumuloZookeepers( config.getZookeepers() );
ryaConfig.setAccumuloInstance( config.getClusterName() );
ryaConfig.setAccumuloUser( config.getUsername() );
ryaConfig.setAccumuloPassword( config.getPassword() );
ryaConfig.setFlush(false);
// Create the Sail object.
try {
return RyaSailFactory.getInstance(ryaConfig);
} catch (SailException | AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) {
throw new ConnectException("Could not connect to the Rya Instance named " + config.getRyaInstanceName(), e);
}
}
示例14
@Test(expected = QueryEvaluationException.class)
public void tooManyArgumentsTest() throws Exception {
final Sail sail = GeoRyaSailFactory.getInstance(conf);
final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
try {
populateRya(conn);
// Only captial
final String query =
"PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ "SELECT * \n" //
+ "WHERE { \n" + " <urn:geo> geo:asWKT ?point .\n"
+ " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 100, 1000, 10))"
+ "}";
conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
} finally {
conn.close();
sail.shutDown();
}
}
示例15
@Test
public void ensureInEntityStore_Test() throws Exception {
final Sail sail = RyaSailFactory.getInstance(conf);
final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
conn.begin();
try(MongoEntityIndexer indexer = new MongoEntityIndexer()) {
indexer.setConf(conf);
indexer.init();
setupTypes(indexer);
addStatements(conn);
final EntityStorage entities = indexer.getEntityStorage();
final RyaIRI subject = new RyaIRI("urn:alice");
final Optional<Entity> alice = entities.get(subject);
assertTrue(alice.isPresent());
} finally {
conn.close();
}
}
示例16
@Test(expected = MalformedQueryException.class)
public void near_invalidDistance() throws Exception {
final Sail sail = GeoRyaSailFactory.getInstance(conf);
final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
try {
populateRya(conn);
//Only captial
final String query =
"PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n"
+ "SELECT * \n" //
+ "WHERE { \n"
+ " <urn:geo> geo:asWKT ?point .\n"
+ " FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, distance))"
+ "}";
conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
} finally {
conn.close();
sail.shutDown();
}
}
示例17
private Sail connectToRya(final String ryaInstanceName) throws RyaClientException {
try {
final MongoDBRdfConfiguration ryaConf = connectionDetails.build(ryaInstanceName);
return RyaSailFactory.getInstance(ryaConf);
} catch (SailException | AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) {
throw new RyaClientException("Could not connect to the Rya instance named '" + ryaInstanceName + "'.", e);
}
}
示例18
@Override
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {
if (config instanceof ConfigurableSailRepositoryConfig) {
ConfigurableSailRepositoryConfig sailRepConfig = (ConfigurableSailRepositoryConfig) config;
try {
Sail sail = createSailStack(sailRepConfig.getSailImplConfig());
return new ConfigurableSailRepository(sail, true);
} catch (SailConfigException e) {
throw new RepositoryConfigException(e.getMessage(), e);
}
}
throw new RepositoryConfigException("Invalid configuration class: " + config.getClass());
}
示例19
private Sail createSailStack(SailImplConfig config) throws RepositoryConfigException, SailConfigException {
Sail sail = createSail(config);
if (config instanceof DelegatingSailImplConfig) {
SailImplConfig delegateConfig = ((DelegatingSailImplConfig) config).getDelegate();
if (delegateConfig != null) {
addDelegate(delegateConfig, sail);
}
}
return sail;
}
示例20
private void addDelegate(SailImplConfig config, Sail sail) throws RepositoryConfigException, SailConfigException {
Sail delegateSail = createSailStack(config);
try {
((StackableSail) sail).setBaseSail(delegateSail);
} catch (ClassCastException e) {
throw new RepositoryConfigException(
"Delegate configured but " + sail.getClass() + " is not a StackableSail");
}
}
示例21
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
NativeStore nativeStore = new NativeStore();
if (config instanceof NativeStoreConfig) {
NativeStoreConfig nativeConfig = (NativeStoreConfig) config;
nativeStore.setTripleIndexes(nativeConfig.getTripleIndexes());
nativeStore.setForceSync(nativeConfig.getForceSync());
if (nativeConfig.getValueCacheSize() >= 0) {
nativeStore.setValueCacheSize(nativeConfig.getValueCacheSize());
}
if (nativeConfig.getValueIDCacheSize() >= 0) {
nativeStore.setValueIDCacheSize(nativeConfig.getValueIDCacheSize());
}
if (nativeConfig.getNamespaceCacheSize() >= 0) {
nativeStore.setNamespaceCacheSize(nativeConfig.getNamespaceCacheSize());
}
if (nativeConfig.getNamespaceIDCacheSize() >= 0) {
nativeStore.setNamespaceIDCacheSize(nativeConfig.getNamespaceIDCacheSize());
}
if (nativeConfig.getIterationCacheSyncThreshold() > 0) {
nativeStore.setIterationCacheSyncThreshold(nativeConfig.getIterationCacheSyncThreshold());
}
EvaluationStrategyFactory evalStratFactory = nativeConfig.getEvaluationStrategyFactory();
if (evalStratFactory != null) {
nativeStore.setEvaluationStrategyFactory(evalStratFactory);
}
}
return nativeStore;
}
示例22
@Override
protected Sail createSail() throws SailException {
MemoryStore sail;
try {
sail = new MemoryStore(tempDir.newFolder("memory-store"));
} catch (IOException e) {
throw new AssertionError(e);
}
sail.setSyncDelay(100);
return sail;
}
示例23
public static SailRepository getAccumuloNonPcjRepo(final String tablePrefix,
final String instance) throws AccumuloException,
AccumuloSecurityException, RyaDAOException, RepositoryException, InferenceEngineException,
NumberFormatException, UnknownHostException, SailException {
final AccumuloRdfConfiguration nonPcjConf = new AccumuloRdfConfiguration();
populateAccumuloConfig(instance, tablePrefix, nonPcjConf);
final Sail nonPcjSail = RyaSailFactory.getInstance(nonPcjConf);
final SailRepository nonPcjRepo = new SailRepository(nonPcjSail);
return nonPcjRepo;
}
示例24
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
return new DedupingInferencer();
}
示例25
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
return new DirectTypeHierarchyInferencer();
}
示例26
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
return new SchemaCachingRDFSInferencer();
}
示例27
@Override
protected Sail createSail() {
try {
NotifyingSail sailStack = new NativeStore(tempDir.newFolder("nativestore"), "spoc,posc");
sailStack = new SchemaCachingRDFSInferencer(sailStack);
return sailStack;
} catch (IOException e) {
throw new AssertionError(e);
}
}
示例28
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
SpinSail spinSail = new SpinSail();
if (config instanceof SpinSailConfig) {
spinSail.setAxiomClosureNeeded(((SpinSailConfig) config).isAxiomClosureNeeded());
spinSail.setValidateConstraints(((SpinSailConfig) config).isValidateConstraints());
}
return spinSail;
}
示例29
@Override
public void setBaseSail(Sail baseSail) {
super.setBaseSail(baseSail);
if (baseSail instanceof ForwardChainingRDFSInferencer) {
this.setAxiomClosureNeeded(false);
}
}
示例30
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
ShaclSail sail = new ShaclSail();
if (config instanceof ShaclSailConfig) {
ShaclSailConfig shaclSailConfig = (ShaclSailConfig) config;
if (shaclSailConfig.isValidationEnabled()) {
sail.enableValidation();
} else {
sail.disableValidation();
}
sail.setCacheSelectNodes(shaclSailConfig.isCacheSelectNodes());
sail.setUndefinedTargetValidatesAllSubjects(shaclSailConfig.isUndefinedTargetValidatesAllSubjects());
sail.setIgnoreNoShapesLoadedException(shaclSailConfig.isIgnoreNoShapesLoadedException());
sail.setLogValidationPlans(shaclSailConfig.isLogValidationPlans());
sail.setLogValidationViolations(shaclSailConfig.isLogValidationViolations());
sail.setParallelValidation(shaclSailConfig.isParallelValidation());
sail.setGlobalLogValidationExecution(shaclSailConfig.isGlobalLogValidationExecution());
sail.setPerformanceLogging(shaclSailConfig.isPerformanceLogging());
sail.setSerializableValidation(shaclSailConfig.isSerializableValidation());
sail.setRdfsSubClassReasoning(shaclSailConfig.isRdfsSubClassReasoning());
}
return sail;
}