當前位置: 首頁>>代碼示例>>Java>>正文


Java Resource類代碼示例

本文整理匯總了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);
		}
	}
}
 
開發者ID:lszeremeta,項目名稱:neo4j-sparql-extension-yars,代碼行數:25,代碼來源:GraphStore.java

示例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;
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:31,代碼來源:SimpleGraph.java

示例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;
		}
	}
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:18,代碼來源:DbInfoMapper.java

示例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;
		}
	}
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:18,代碼來源:DbInfoMapper.java

示例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;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:21,代碼來源:DbInfoMapper.java

示例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;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:19,代碼來源:DbInfoMapper.java

示例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 );
		}
	}
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:27,代碼來源:UserMapper.java

示例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 );
		}
	}
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:28,代碼來源:UserMapper.java

示例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;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:23,代碼來源:UserMapper.java

示例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;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:19,代碼來源:UserMapper.java

示例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;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:18,代碼來源:UserMapper.java

示例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 );
	}
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:26,代碼來源:EngineUtil2.java

示例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;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:29,代碼來源:Utility.java

示例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() );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:26,代碼來源:EngineLoaderTest.java

示例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() );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:26,代碼來源:UtilityTest.java


注:本文中的org.openrdf.model.Resource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。