當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。