本文整理汇总了Java中org.openrdf.model.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于org.openrdf.model包,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addToGraphstore
import org.openrdf.model.Resource; //导入依赖的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);
}
}
}
示例2: tuplePattern
import org.openrdf.model.Resource; //导入依赖的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;
}
示例3: remove
import org.openrdf.model.Resource; //导入依赖的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;
}
}
}
示例4: update
import org.openrdf.model.Resource; //导入依赖的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;
}
}
}
示例5: getDbInfo
import org.openrdf.model.Resource; //导入依赖的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;
}
示例6: getId
import org.openrdf.model.Resource; //导入依赖的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;
}
示例7: update
import org.openrdf.model.Resource; //导入依赖的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 );
}
}
}
示例8: setAccesses
import org.openrdf.model.Resource; //导入依赖的package包/类
/**
* Sets the access level from the given map. To remove access from a DB, user
* {@link DbAccess#NONE}.
*
* @param user
* @param access a mapping of URIs (either {@link DbInfo#getDataUrl()} or
* {@link DbInfo#getInsightsUrl()}) and the access given
*/
public void setAccesses( User user, Map<URI, DbAccess> access ) {
RepositoryConnection rc = store.getConnection();
try {
rc.begin();
Resource id = getId( user, rc );
addAccesses( id, access, rc );
rc.commit();
}
catch ( RepositoryException e ) {
log.error( e, e );
try {
rc.rollback();
}
catch ( Exception x ) {
log.warn( x, x );
}
}
}
示例9: getUser
import org.openrdf.model.Resource; //导入依赖的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;
}
示例10: getId
import org.openrdf.model.Resource; //导入依赖的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;
}
示例11: getCreateStatements
import org.openrdf.model.Resource; //导入依赖的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;
}
示例12: clear
import org.openrdf.model.Resource; //导入依赖的package包/类
public static void clear( IEngine engine ) throws RepositoryException {
try {
final Map<URI, Value> metas = engine.query( new MetadataQuery() );
metas.remove( SEMTOOL.Database );
engine.execute( new ModificationExecutorAdapter( true ) {
@Override
public void exec( RepositoryConnection conn ) throws RepositoryException {
conn.remove( (Resource) null, null, null );
ValueFactory vf = conn.getValueFactory();
// re-add the metadata
for ( Map.Entry<URI, Value> en : metas.entrySet() ) {
conn.add( engine.getBaseUri(),
URI.class.cast( EngineLoader.cleanValue( en.getKey(), vf ) ),
EngineLoader.cleanValue( en.getValue(), vf ) );
}
}
} );
}
catch ( MalformedQueryException | QueryEvaluationException e ) {
log.error( e, e );
}
}
示例13: sortUrisByLabel
import org.openrdf.model.Resource; //导入依赖的package包/类
/**
* A convenience for {@link #getInstanceLabels(java.util.Collection,
* gov.va.semoss.rdf.engine.api.IEngine) }, but returns a sorted map with
* consistent iteration pattern
*
* @param <X>
* @param urilabels a mapping of URIs to their labels. Say, the results of {@link #getInstanceLabels(java.util.Collection,
* gov.va.semoss.rdf.engine.api.IEngine) }
*
* @return the results
*/
public static <X extends Resource> Map<X, String> sortUrisByLabel( Map<X, String> urilabels ) {
List<ResourceLabelPair> pairs = new ArrayList<>();
for ( Map.Entry<X, String> p : urilabels.entrySet() ) {
Resource r = p.getKey();
pairs.add( new ResourceLabelPair( r, p.getValue() ) );
}
Collections.sort( pairs );
LinkedHashMap<Resource, String> ret = new LinkedHashMap<>();
for ( ResourceLabelPair ulp : pairs ) {
ret.put( ulp.r, ulp.l );
}
return (Map<X, String>) ret;
}
示例14: testImportRDF
import org.openrdf.model.Resource; //导入依赖的package包/类
@Test
public void testImportRDF() throws Exception {
engine.setBuilders( UriBuilder.getBuilder( DATAURI ),
UriBuilder.getBuilder( SCHEMAURI ) );
ImportData errors = new ImportData();
EngineLoader el = new EngineLoader();
el.loadToEngine( Arrays.asList( TICKET584_EXP ), engine, true, errors );
// cleanup
engine.getRawConnection().remove( (Resource) null, RDF.TYPE, SEMTOOL.Database );
el.release();
if ( log.isTraceEnabled() ) {
File tmpdir = FileUtils.getTempDirectory();
try ( Writer w = new BufferedWriter( new FileWriter( new File( tmpdir,
"import-rdf.nt" ) ) ) ) {
engine.getRawConnection().export( new NTriplesWriter( w ) );
}
}
compareData( engine.getRawConnection(), getExpectedGraph( TICKET584_EXP ),
engine.getSchemaBuilder(), engine.getDataBuilder() );
}
示例15: testGetLabels
import org.openrdf.model.Resource; //导入依赖的package包/类
@Test
public void testGetLabels() throws Exception {
InMemorySesameEngine eng = InMemorySesameEngine.open();
eng.getRawConnection().begin();
eng.getRawConnection().add( new StatementImpl( RDFS.ISDEFINEDBY,
RDFS.LABEL, new LiteralImpl( "my label" ) ) );
eng.getRawConnection().add( new StatementImpl( RDFS.MEMBER,
RDFS.LABEL, new LiteralImpl( "my label 2" ) ) );
eng.getRawConnection().commit();
String label = Utility.getInstanceLabel( RDFS.ISDEFINEDBY, eng );
assertEquals( "my label", label );
Map<Resource, String> labels = Utility.getInstanceLabels( null, eng );
assertTrue( labels.isEmpty() );
labels = Utility.getInstanceLabels( Arrays.asList(
RDFS.MEMBER, RDFS.DOMAIN ), eng );
assertEquals( "domain", labels.get( RDFS.DOMAIN ) );
assertEquals( "my label 2", labels.get( RDFS.MEMBER ) );
labels = Utility.getInstanceLabels( Arrays.asList( RDFS.ISDEFINEDBY,
RDFS.LITERAL ), null );
assertEquals( 2, labels.size() );
}