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


Java RepositoryConnection类代码示例

本文整理汇总了Java中org.openrdf.repository.RepositoryConnection的典型用法代码示例。如果您正苦于以下问题:Java RepositoryConnection类的具体用法?Java RepositoryConnection怎么用?Java RepositoryConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RepositoryConnection类属于org.openrdf.repository包,在下文中一共展示了RepositoryConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addToGraphstore

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
/**
 * Helper method for handleAdd.
 */
private void addToGraphstore(
		RepositoryConnection conn,
		InputStream in,
		String base,
		RDFFormat format,
		Resource dctx,
		boolean chunked) throws IOException, RDFParseException,
		RDFHandlerException, RepositoryException {
	if (chunked) {
		RDFParser parser = getRDFParser(format);
		parser.setRDFHandler(
				new ChunkedCommitHandler(conn, chunksize, dctx));
		parser.parse(in, base);
	} else {
		if (dctx != null) {
			conn.add(in, base, format, dctx);
		} else {
			conn.add(in, base, format);
		}
	}
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:25,代码来源:GraphStore.java

示例2: getDistinctObj

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
/**
 * Get total number of distinct objects for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static long getDistinctObj(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?o) AS ?objs) " + // 
			"WHERE " +
			"{" +
       		"?s <" + pred + "> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("objs").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
开发者ID:dice-group,项目名称:CostFed,代码行数:25,代码来源:SemagrowSummariesGenerator.java

示例3: getDistinctSbj

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
/**
 * Get total number of distinct objects for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static long getDistinctSbj(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?s) AS ?subjs) " + // 
			"WHERE " +
			"{" +
       		"?s <" + pred + "> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("subjs").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
开发者ID:dice-group,项目名称:CostFed,代码行数:25,代码来源:SemagrowSummariesGenerator.java

示例4: getObjectCount

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
/**
 * Get total number of distinct objects of a dataset
 * @return count
 */
public static long getObjectCount(String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?o) AS ?objts) " + // 
			"WHERE " +
			"{" +
       		"?s ?p ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("objts").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
开发者ID:dice-group,项目名称:CostFed,代码行数:23,代码来源:SemagrowSummariesGenerator.java

示例5: getTripleCount

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
/**
 * Get total number of triple for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static Long getTripleCount(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(?s) AS ?triples) " + // 
			"WHERE " +
			"{" +
       		"?s <"+pred+"> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("triples").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
开发者ID:dice-group,项目名称:CostFed,代码行数:25,代码来源:SemagrowSummariesGenerator.java

示例6: getPredicates

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
/**
 * Get Predicate List
 * @param endPointUrl SPARQL endPoint Url
 * @param graph Named graph
 * @return  predLst Predicates List
 */
private static List<String> getPredicates(String endPointUrl, String graph) throws Exception
{
	List<String>  predLst = new ArrayList<String>();
	String strQuery = getPredQuery(graph);
	SPARQLRepository repo = new SPARQLRepository(endPointUrl);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult res = query.evaluate();
		while (res.hasNext()) 
		{
			String pred = res.next().getValue("p").toString();
			predLst.add(pred);	  		
		}
	} finally {
		conn.close();
		repo.shutDown();
	}
	return predLst;
}
 
开发者ID:dice-group,项目名称:CostFed,代码行数:28,代码来源:SemagrowSummariesGenerator.java

示例7: tuplePattern

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
/**
 * Tuple pattern query - find all statements with the pattern, where null is
 * a wild card
 * 
 * @param s
 *            subject (null for wildcard)
 * @param p
 *            predicate (null for wildcard)
 * @param o
 *            object (null for wildcard)
 * @return serialized graph of results
 */
public List tuplePattern(URI s, URI p, Value o) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			RepositoryResult repres = con.getStatements(s, p, o, true, new Resource[0]);
			ArrayList reslist = new ArrayList();
			while (repres.hasNext()) {
				reslist.add(repres.next());
			}
			return reslist;
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dvcama,项目名称:resource-to-sparqlresult,代码行数:31,代码来源:SimpleGraph.java

示例8: runSPARQL

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
/**
 * Execute a CONSTRUCT/DESCRIBE SPARQL query against the graph
 * 
 * @param qs
 *            CONSTRUCT or DESCRIBE SPARQL query
 * @param format
 *            the serialization format for the returned graph
 * @return serialized graph of results
 */
public String runSPARQL(String qs, RDFFormat format) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			GraphQuery query = con.prepareGraphQuery(org.openrdf.query.QueryLanguage.SPARQL, qs);
			StringWriter stringout = new StringWriter();
			RDFWriter w = Rio.createWriter(format, stringout);
			query.evaluate(w);
			return stringout.toString();
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dvcama,项目名称:resource-to-sparqlresult,代码行数:27,代码来源:SimpleGraph.java

示例9: property

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
/**
 * Helper for {@link BlazeEdge#property(String, Object)} and 
 * {@link BlazeVertexProperty#property(String, Object)}.
 * 
 * @param element the BlazeEdge or BlazeVertexProperty
 * @param key the property key
 * @param val the property value
 * @return a BlazeProperty
 */
<V> BlazeProperty<V> property(final BlazeReifiedElement element, 
        final String key, final V val) {
    final BigdataValueFactory rdfvf = rdfValueFactory();
    final BigdataBNode s = element.rdfId();
    final URI p = rdfvf.asValue(vf.propertyURI(key));
    final Literal lit = rdfvf.asValue(vf.toLiteral(val));
    
    final RepositoryConnection cxn = cxn();
    Code.wrapThrow(() -> {
        final BigdataStatement stmt = rdfvf.createStatement(s, p, lit);
        if (!bulkLoad) {
            // remove (<<stmt>> <key> ?)
            cxn.remove(s, p, null);
        }
        // add (<<stmt>> <key> "val")
        cxn.add(stmt);
    });
    
    final BlazeProperty<V> prop = new BlazeProperty<V>(this, element, p, lit);
    return prop;
}
 
开发者ID:blazegraph,项目名称:tinkerpop3,代码行数:31,代码来源:BlazeGraph.java

示例10: create

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
@Override
public DbInfo create( DbInfo t ) throws Exception {
	RepositoryConnection rc = store.getConnection();
	UriBuilder urib = UriBuilder.getBuilder( WEBDS.NAMESPACE + "dbinfo" );
	URI uri = urib.uniqueUri();
	rc.begin();
	try{
		rc.add( getCreateStatements( uri, t, rc.getValueFactory() ) );
		rc.commit();
	}
	catch( RepositoryException re ){
		rc.rollback();
		throw re;
	}
	return t;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:17,代码来源:DbInfoMapper.java

示例11: remove

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
@Override
public void remove( DbInfo t ) throws Exception {
	RepositoryConnection rc = store.getConnection();

	Resource idToRemove = getId( t, rc );
	if ( null != idToRemove ) {
		try{
			rc.begin();
			rc.remove( idToRemove, null, null );
			rc.commit();
		}
		catch( RepositoryException re ){
			rc.rollback();
			throw re;
		}
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:18,代码来源:DbInfoMapper.java

示例12: update

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
@Override
public void update( DbInfo data ) throws Exception {
	RepositoryConnection rc = store.getConnection();
	Resource id = getId( data, rc );
	if ( null != id ) {
		try{
			rc.begin();
			rc.remove( id, null, null );
			rc.add( getCreateStatements( id, data, rc.getValueFactory() ) );
			rc.commit();
		}
		catch( RepositoryException re ){
			rc.rollback();
			throw re;
		}
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:18,代码来源:DbInfoMapper.java

示例13: getDbInfo

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
public static DbInfo getDbInfo( Resource id, RepositoryConnection rc )
		throws RepositoryException {

	DbInfo dbi = new DbInfo();
	for ( Statement stmt : Iterations.asList( rc.getStatements( id, null, null, false ) ) ) {
		URI pred = stmt.getPredicate();
		String val = stmt.getObject().stringValue();
		if ( DATA_PREDICATE.equals( pred ) ) {
			dbi.setDataUrl( val );
		}
		else if ( INSIGHTS_PREDICATE.equals( pred ) ) {
			dbi.setInsightsUrl( val );
		}
		else if ( RDFS.LABEL.equals( pred ) ) {
			dbi.setName( val );
		}
	}

	return dbi;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:21,代码来源:DbInfoMapper.java

示例14: getId

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
public static Resource getId( DbInfo t, RepositoryConnection rc )
		throws RepositoryException {
	List<Statement> stmts = Iterations.asList( rc.getStatements( null, RDF.TYPE,
			WEBDS.DBINFO, false ) );
	Resource idToRemove = null;
	for ( Statement s : stmts ) {
		Resource sbj = s.getSubject();
		List<Statement> individuals
				= Iterations.asList( rc.getStatements( sbj, RDFS.LABEL, null, false ) );
		for ( Statement ind : individuals ) {
			if ( ind.getObject().stringValue().equals( t.getName() ) ) {
				idToRemove = sbj;
			}
		}
	}

	return idToRemove;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:19,代码来源:DbInfoMapper.java

示例15: update

import org.openrdf.repository.RepositoryConnection; //导入依赖的package包/类
@Override
public void update( User user ) throws Exception {
	RepositoryConnection rc = store.getConnection();
	try {
		Map<URI, DbAccess> accesses = getAccesses( user );

		Resource id = getId( user, rc );
		if ( null != id ) {
			rc.begin();
			rc.remove( id, null, null );
			rc.add( getCreateStatements( id, user, rc.getValueFactory() ) );

			addAccesses( id, accesses, rc );
			rc.commit();
		}
	}
	catch ( RepositoryException e ) {
		log.error( e, e );
		try {
			rc.rollback();
		}
		catch ( Exception x ) {
			log.warn( x, x );
		}
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:27,代码来源:UserMapper.java


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