当前位置: 首页>>代码示例>>Java>>正文


Java MemoryStore类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:bridgedb,项目名称:BridgeDb,代码行数:21,代码来源:BridgeDBRdfHandler.java

示例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);
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:25,代码来源:SPARQLInferenceTest.java

示例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 );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:18,代码来源:RepositoryCopierTest.java

示例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 );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:27,代码来源:InMemorySesameEngineTest.java

示例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();
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:19,代码来源:InterfaceTypeSpecTest.java

示例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;
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:25,代码来源:ProxyCompileTool.java

示例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();
}
 
开发者ID:markusstocker,项目名称:emrooz,代码行数:27,代码来源:QuerySensorObservationsExample.java

示例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();
}
 
开发者ID:markusstocker,项目名称:emrooz,代码行数:19,代码来源:SensorSpecificationExample.java

示例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);
	}
}
 
开发者ID:markusstocker,项目名称:emrooz,代码行数:18,代码来源:SesameQueryHandler.java

示例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();
}
 
开发者ID:markusstocker,项目名称:emrooz,代码行数:25,代码来源:SesameKnowledgeStoreTest.java

示例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();
}
 
开发者ID:markusstocker,项目名称:emrooz,代码行数:27,代码来源:SesameKnowledgeStoreTest.java

示例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;
    }
}
 
开发者ID:isl,项目名称:LifeWatch_Greece,代码行数:34,代码来源:Utils.java

示例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);
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:22,代码来源:RangeQueriesTest.java

示例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();
	}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:20,代码来源:R2RMLAlignmentFileSaver.java

示例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;
}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:27,代码来源:Homework.java


注:本文中的org.openrdf.sail.memory.MemoryStore类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。