本文整理汇总了Java中org.openrdf.model.Statement类的典型用法代码示例。如果您正苦于以下问题:Java Statement类的具体用法?Java Statement怎么用?Java Statement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Statement类属于org.openrdf.model包,在下文中一共展示了Statement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleStatement
import org.openrdf.model.Statement; //导入依赖的package包/类
/**
* Handles a statement.
*
* The statements will be added up until chunk size is reached.
* After a chunk of statements is added the transaction will be committed
* and new transaction will be started.
* @param stmnt
* @throws RDFHandlerException
*/
@Override
public void handleStatement(Statement stmnt) throws RDFHandlerException {
try {
// check if triple should be added to a specific graph
if (dctx != null) {
conn.add(stmnt, dctx);
} else {
conn.add(stmnt);
}
// check if chunk size is reached and transaction should be
// committed
count++;
if (count >= size) {
count = 0;
conn.commit();
conn.begin();
}
} catch (RepositoryException ex) {
throw new RDFHandlerException(ex);
}
}
示例2: _project
import org.openrdf.model.Statement; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* Logs the query at INFO and logs the optimized AST at TRACE.
*/
@Override
protected Stream<Statement> _project(
final String queryStr, final String extQueryId) {
logQuery(queryStr);
return Code.wrapThrow(() -> {
final BigdataSailGraphQuery query = (BigdataSailGraphQuery)
cxn().prepareGraphQuery(QueryLanguage.SPARQL, queryStr);
setMaxQueryTime(query);
final UUID queryId = setupQuery(query.getASTContainer(),
QueryType.CONSTRUCT, extQueryId);
sparqlLog.trace(() -> "optimized AST:\n"+query.optimize());
/*
* Result is closed automatically by GraphStreamer.
*/
final GraphQueryResult result = query.evaluate();
final Optional<Runnable> onClose =
Optional.of(() -> finalizeQuery(queryId));
return new GraphStreamer<>(result, onClose).stream();
});
}
示例3: getDbInfo
import org.openrdf.model.Statement; //导入依赖的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;
}
示例4: getId
import org.openrdf.model.Statement; //导入依赖的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;
}
示例5: getUser
import org.openrdf.model.Statement; //导入依赖的package包/类
private static User getUser( Resource id, RepositoryConnection rc )
throws RepositoryException {
LinkedHashModel model = new LinkedHashModel( Iterations.asList(
rc.getStatements( id, null, null, false ) ) );
org.openrdf.model.Model namer = model.filter( id, FOAF.ACCOUNT, null );
RemoteUserImpl user = new RemoteUserImpl( namer.objectString() );
model.removeAll( namer );
for ( Statement stmt : model ) {
URI pred = stmt.getPredicate();
String val = stmt.getObject().stringValue();
for ( Map.Entry<UserProperty, URI> en : PROPMAP.entrySet() ) {
if ( en.getValue().equals( pred ) ) {
user.setProperty( en.getKey(), val );
}
}
}
return user;
}
示例6: getId
import org.openrdf.model.Statement; //导入依赖的package包/类
private static Resource getId( User t, RepositoryConnection rc )
throws RepositoryException {
List<Statement> stmts = Iterations.asList( rc.getStatements( null, RDF.TYPE,
FOAF.PERSON, false ) );
Resource idToRemove = null;
for ( Statement s : stmts ) {
Resource sbj = s.getSubject();
List<Statement> individuals
= Iterations.asList( rc.getStatements( sbj, FOAF.ACCOUNT, null, false ) );
for ( Statement ind : individuals ) {
if ( ind.getObject().stringValue().equals( t.getUsername() ) ) {
idToRemove = sbj;
}
}
}
return idToRemove;
}
示例7: getCreateStatements
import org.openrdf.model.Statement; //导入依赖的package包/类
private static Collection<Statement> getCreateStatements( Resource id, User t,
ValueFactory vf ) {
List<Statement> stmts = new ArrayList<>();
stmts.add( new StatementImpl( id, RDF.TYPE, FOAF.PERSON ) );
stmts.add( new StatementImpl( id, FOAF.ACCOUNT, vf.createLiteral( t.getUsername() ) ) );
for ( Map.Entry<UserProperty, URI> en : PROPMAP.entrySet() ) {
UserProperty prop = en.getKey();
String str = t.getProperty( prop );
if ( !str.trim().isEmpty() ) {
stmts.add( new StatementImpl( id, en.getValue(), vf.createLiteral( str ) ) );
}
}
return stmts;
}
示例8: getCopier
import org.openrdf.model.Statement; //导入依赖的package包/类
private static RepositoryCopier getCopier( RepositoryConnection conn,
Map<URI, URI> fromto, URI schema, URI data ) {
final UriBuilder owlb = UriBuilder.getBuilder( schema );
final UriBuilder datab = UriBuilder.getBuilder( data );
return new RepositoryCopier( conn ) {
@Override
public void handleStatement( Statement stmt ) throws RDFHandlerException {
URI sub = URI.class.cast( stmt.getSubject() );
URI pred = stmt.getPredicate();
Value obj = stmt.getObject();
sub = upgrade( sub, fromto, owlb, datab );
pred = upgrade( pred, fromto, owlb, datab );
if ( obj instanceof URI ) {
obj = upgrade( URI.class.cast( obj ), fromto, owlb, datab );
}
super.handleStatement( new StatementImpl( sub, pred, obj ) );
}
};
}
示例9: handleStatement
import org.openrdf.model.Statement; //导入依赖的package包/类
@Override
public void handleStatement( Statement stmt ) throws RDFHandlerException {
try {
// RPB: need to rebox these statements because BigData blows up if
// you try to copy one statement to another repository
conn.add( EngineLoader.cleanStatement( stmt, conn.getValueFactory() ) );
adds++;
totalAdds++;
if ( adds >= commitlimit ) {
log.debug( "committed " + totalAdds + " statements..." );
conn.commit();
conn.begin();
adds = 0;
}
}
catch ( Exception e ) {
try {
conn.rollback();
}
catch ( Exception ex ) {
throw new RDFHandlerException( ex );
}
throw new RDFHandlerException( e );
}
}
示例10: ttlToStdout
import org.openrdf.model.Statement; //导入依赖的package包/类
public static void ttlToStdout( Model model ) {
TurtleWriter tw = new TurtleWriter( System.out );
try {
tw.startRDF();
for ( Map.Entry<String, String> en : DEFAULTNAMESPACES.entrySet() ) {
tw.handleNamespace( en.getKey(), en.getValue() );
}
for ( Statement s : model ) {
tw.handleStatement( s );
}
tw.endRDF();
}
catch ( Exception e ) {
log.error( e, e );
}
}
示例11: compareOwls
import org.openrdf.model.Statement; //导入依赖的package包/类
/**
* Run a couple heuristics comparing the OWL statements and the expected
* output file
*
* @param owls the owl statements from the load
* @param filename an RDF file containing the expected results of the load
*
* @throws Exception
*/
private void compareOwls( Collection<Statement> owls, File filename,
UriBuilder bldr ) throws Exception {
Model expected = getExpectedGraph( filename );
Model test = new LinkedHashModel( owls );
compare( "category concept", expected, test, bldr.getConceptUri( "Category" ), null, null );
compare( "product concept", expected, test, bldr.getConceptUri( "Product" ), null, null );
compare( "category relation", expected, test, bldr.getRelationUri( "Category" ), null, null );
compare( "contains relation", expected, test, bldr.getConceptUri( "Contains" ), null, null );
URI contains = bldr.getRelationUri( "Contains" );
UriBuilder bldr2 = UriBuilder.getBuilder( contains );
compare( "contains relation description",
expected, test, bldr2.add( "Description" ).build(), null, null );
compare( "contains relation extraprop",
expected, test, bldr2.add( "extraprop" ).build(), null, null );
}
示例12: compareData
import org.openrdf.model.Statement; //导入依赖的package包/类
private void compareData( RepositoryConnection testRc, Model expected,
UriBuilder owl, UriBuilder base ) throws Exception {
List<Statement> stmts
= Iterations.asList( testRc.getStatements( null, null, null, false ) );
Model test = new LinkedHashModel( stmts );
assertEquals( "dataset size", expected.size(), test.size() );
compare( "category concept", expected, test, null, RDF.TYPE,
owl.getConceptUri( "Category" ) );
compare( "beverages concept", expected, test,
base.getConceptUri().add( "Category" ).add( "Beverages" ).build(),
null, null );
compare( "dairy products", expected, test,
null, RDFS.LABEL, new LiteralImpl( "Dairy Products" ) );
compare( "chai-beverages link", expected, test,
null, RDFS.LABEL, new LiteralImpl( "Chai Category Beverages" ) );
URI bev
= base.getRelationUri().add( "Category" ).add( "Chai_x_Beverages" ).build();
compare( "chai-beverages category", expected, test,
bev, RDFS.SUBPROPERTYOF, owl.getRelationUri( "Category" ) );
}
示例13: testUpdateDate2
import org.openrdf.model.Statement; //导入依赖的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 );
}
示例14: getValueAt
import org.openrdf.model.Statement; //导入依赖的package包/类
/**
* Gets the cell value at a particular row and column index.
*
* @param r Row index.
* @param c Column index.
*
* @return Object Cell value.
*/
@Override
public Object getValueAt( int r, int c ) {
Statement row = rows.get( r );
switch ( c ) {
case 0: {
return row.getPredicate();
}
case 1: {
return RDFDatatypeTools.getDatatype( row.getObject() );
}
case 2: {
return row.getObject();
}
default:
return null;
}
}
示例15: deleteStatements
import org.openrdf.model.Statement; //导入依赖的package包/类
public static void deleteStatements( IEngine engine, Collection<Statement> statements ) {
ProgressTask pt = new ProgressTask( "Deleting Statements from the Knowledge Base",
new Runnable() {
@Override
public void run() {
try {
ModificationExecutor mea = new ModificationExecutorAdapter() {
@Override
public void exec( RepositoryConnection conn ) throws RepositoryException {
conn.begin();
conn.remove( statements );
}
};
engine.execute( mea );
engine.commit();
}
catch ( RepositoryException re ) {
log.error( "RepositoryException trying to delete Statements: " + re, re );
}
}
} );
OperationsProgress.getInstance( PlayPane.UIPROGRESS ).add( pt );
}