本文整理匯總了Java中org.openrdf.sail.memory.MemoryStore類的典型用法代碼示例。如果您正苦於以下問題:Java MemoryStore類的具體用法?Java MemoryStore怎麽用?Java MemoryStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MemoryStore類屬於org.openrdf.sail.memory包,在下文中一共展示了MemoryStore類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeRdfToFile
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
public static void writeRdfToFile(File file, SortedSet<DataSource> dataSources) throws BridgeDBException{
Reporter.println("Writing DataSource RDF to " + file.getAbsolutePath());
Repository repository = null;
RepositoryConnection repositoryConnection = null;
try {
repository = new SailRepository(new MemoryStore());
repository.initialize();
repositoryConnection = repository.getConnection();
for (DataSource dataSource: dataSources){
writeDataSource(repositoryConnection, dataSource);
}
OrganismRdf.addAll(repositoryConnection);
UriPattern.addAll(repositoryConnection);
writeRDF(repositoryConnection, file);
} catch (Exception ex) {
throw new BridgeDBException ("Error writing RDF to file:" + ex.getMessage(), ex);
} finally {
shutDown(repository, repositoryConnection);
}
}
示例2: before
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
@Before
public void before()
throws RepositoryException, IOException, RDFParseException,
MalformedQueryException, QueryResultParseException,
QueryResultHandlerException {
repo = new SailRepository(new MemoryStore());
repo.initialize();
conn = repo.getConnection();
vf = conn.getValueFactory();
conn.add(getResource(data), "file://", RDFFormat.TURTLE);
SPARQLResultsXMLParserFactory factory =
new SPARQLResultsXMLParserFactory();
parser = factory.getParser();
parser.setValueFactory(vf);
List<Rule> rules;
rules = Rules.fromOntology(getResource(data));
QueryRewriter rewriter = new QueryRewriter(conn, rules);
query = (TupleQuery) rewriter.rewrite(QueryLanguage.SPARQL, queryString);
nonInfQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
System.out.println("== QUERY (" + this.name + ") ==");
System.out.println(nonInfQuery);
System.out.println("== REWRITTEN QUERY (" + this.name + ") ==");
System.out.println(query);
}
示例3: setUp
import org.openrdf.sail.memory.MemoryStore; //導入依賴的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 );
}
示例4: testUpdateDate2
import org.openrdf.sail.memory.MemoryStore; //導入依賴的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 );
}
示例5: setUp
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
generationConfig = new OntGenerationConfig();
List<String> identifierLangPreference = Arrays.asList("en", "de", OntGenerationConfig.UNTYPED_LITERAL);
List<String> javaDocLangPreference = Arrays.asList("de", "en", OntGenerationConfig.UNTYPED_LITERAL);
generationConfig.setIdentifierLanguagePreference(identifierLangPreference);
generationConfig.setJavaDocLanguagePreference(javaDocLangPreference);
// Prevent persisting of schema information from other tests (would be rooted to ex:Vehicle):
Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), new IDGeneratorAnno4jURN(), null, false);
modelBuilder = new OWLJavaFileGenerator(anno4j);
// Create a RDFS model builder instance:
VehicleOntologyLoader.addVehicleOntology(modelBuilder);
// Build the ontology model:
modelBuilder.build();
}
示例6: getAnno4jWithClassLoader
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
/**
* Creates an Anno4j instance that can use the concepts contained in the given JAR file.
* @param ontologyJar A JAR file containing concepts.
* @param classLoader The class loader to use.
* @param persistSchemaAnnotations Whether schema annotations should be scanned.
* @return Returns an Anno4j instance.
* @throws Exception Thrown on error.
*/
private static Anno4j getAnno4jWithClassLoader(File ontologyJar, ClassLoader classLoader, boolean persistSchemaAnnotations) throws Exception {
Set<URL> clazzes = new HashSet<>();
clazzes.addAll(ClasspathHelper.forManifest(ontologyJar.toURI().toURL()));
Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), new IDGeneratorAnno4jURN(), null, persistSchemaAnnotations, clazzes);
// Register concepts found in JAR:
RoleMapper mapper = anno4j.getObjectRepository().getConnection().getObjectFactory().getResolver().getRoleMapper();
for (final String className : getClassNamesInJar(ontologyJar)) {
Class<?> clazz = classLoader.loadClass(className);
if(clazz.getAnnotation(Iri.class) != null) {
mapper.addConcept(clazz);
}
}
return anno4j;
}
示例7: main
import org.openrdf.sail.memory.MemoryStore; //導入依賴的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();
}
示例8: main
import org.openrdf.sail.memory.MemoryStore; //導入依賴的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();
}
示例9: SesameQueryHandler
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
public SesameQueryHandler(QueryHandler<Statement> other, ParsedQuery query) {
if (other == null)
throw new RuntimeException("[other = null]");
if (query == null)
throw new RuntimeException("[query = null]");
this.other = other;
this.query = query;
try {
this.repo = new SailRepository(new MemoryStore());
this.repo.initialize();
this.conn = repo.getConnection();
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
示例10: testGetSensors
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
@Test
@FileParameters("src/test/resources/SesameKnowledgeStoreTest-testGetSensors.csv")
public void testGetSensors(
String kb,
@ConvertParam(value = ParamsConverterTest.StringToStatementsConverter.class) Set<Statement> statements,
String assertType) throws RepositoryException, RDFParseException,
IOException {
SesameKnowledgeStore ks = new SesameKnowledgeStore(new SailRepository(new MemoryStore()));
ks.load(new File(kb));
RDFEntityRepresenter er = new RDFEntityRepresenter();
Set<Sensor> e = er.createSensors(statements);
Set<Sensor> a = ks.getSensors();
if (assertType.equals("assertEquals")) {
assertTrue(CollectionUtils.isEqualCollection(e, a));
return;
}
assertFalse(CollectionUtils.isEqualCollection(e, a));
ks.close();
}
示例11: testAddSensor
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
@Test
@FileParameters("src/test/resources/SesameKnowledgeStoreTest-testAddSensor.csv")
public void testAddSensor(
@ConvertParam(value = ParamsConverterTest.StringToURIConverter.class) URI sensorId,
@ConvertParam(value = ParamsConverterTest.StringToURIConverter.class) URI propertyId,
@ConvertParam(value = ParamsConverterTest.StringToURIConverter.class) URI featureId,
@ConvertParam(value = ParamsConverterTest.StringToStatementsConverter.class) Set<Statement> statements,
String assertType) throws RepositoryException, RDFParseException,
IOException {
SesameKnowledgeStore ks = new SesameKnowledgeStore(new SailRepository(new MemoryStore()));
ks.addSensor(new Sensor(sensorId, new Property(propertyId, new FeatureOfInterest(featureId))));
RDFEntityRepresenter er = new RDFEntityRepresenter();
Set<Sensor> e = er.createSensors(statements);
Set<Sensor> a = ks.getSensors();
if (assertType.equals("assertEquals")) {
assertTrue(CollectionUtils.isEqualCollection(e, a));
return;
}
assertFalse(CollectionUtils.isEqualCollection(e, a));
ks.close();
}
示例12: removeIndirectTriples
import org.openrdf.sail.memory.MemoryStore; //導入依賴的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;
}
}
示例13: setUp
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
/**
* Setup fixture for this test case.
*
* @throws Exception never, otherwise the test fails.
*/
@BeforeClass
public static void setUp() throws Exception {
_repository = new SailRepository(new MemoryStore());
_repository.initialize();
_tripleStore = newTripleStore();
_tripleStore.enableRangeIndexesSupport();
_tripleStore.open();
assertTrue("Ranges have not been enabled for this triple store!", _tripleStore.isRangeIndexesSupportEnabled());
_tripleStore.bulkLoad(DATA, RDFFormat.NTRIPLES);
_repositoryConnection = _repository.getConnection();
_repositoryConnection.add(new File(DATA), "http://nb-base-uri-not-actually-used", RDFFormat.NTRIPLES);
}
示例14: loadHistory
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
@Override
public JSONArray loadHistory(String filename) throws Exception {
File file = new File(filename);
// String encoding = EncodingDetector.detect(file);
// String contents = EncodingDetector.getString(file, encoding);
SailRepository myRepository = new SailRepository(new MemoryStore());
myRepository.initialize();
SailRepositoryConnection con = myRepository.getConnection();
con.add(file, "", RDFFormat.TURTLE);
RepositoryResult<Statement> result = con.getStatements(null, new URIImpl("http://isi.edu/integration/karma/dev#hasWorksheetHistory"), null, false);
if(result.hasNext()) {
Statement stmt = result.next();
String history = stmt.getObject().stringValue();
return new JSONArray(history);
}
return new JSONArray();
}
示例15: question7
import org.openrdf.sail.memory.MemoryStore; //導入依賴的package包/類
public static Map<String, Repository> question7(Repository rep) {
RepositoryConnection conn = null;
RepositoryConnection fc_conn = null;
SailRepository fc_rep = new SailRepository(
new ForwardChainingRDFSInferencer(new MemoryStore()));
try {
conn = rep.getConnection();
fc_rep.initialize();
fc_conn = fc_rep.getConnection();
RepositoryResult<Statement> statements = conn.getStatements(null,
null, null, true);
fc_conn.add(statements);
conn.clear();
conn.add(fc_conn.getStatements(null, null, null, true));
} catch (RepositoryException e) {
e.printStackTrace();
} finally {
closeRepositoryConnection(fc_conn);
closeRepositoryConnection(conn);
}
question4(fc_rep, "8");
Map<String, Repository> map = new HashMap<String, Repository>();
map.put("fc_rep", fc_rep);
map.put("rep", rep);
return map;
}