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


Java ValueFactory類代碼示例

本文整理匯總了Java中org.openrdf.model.ValueFactory的典型用法代碼示例。如果您正苦於以下問題:Java ValueFactory類的具體用法?Java ValueFactory怎麽用?Java ValueFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ValueFactory類屬於org.openrdf.model包,在下文中一共展示了ValueFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Literal

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
/**
 * Literal factory
 * 
 * @param s
 *            the literal value
 * @param typeuri
 *            uri representing the type (generally xsd)
 * @return
 */
public org.openrdf.model.Literal Literal(String s, URI typeuri) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			ValueFactory vf = con.getValueFactory();
			if (typeuri == null) {
				return vf.createLiteral(s);
			} else {
				return vf.createLiteral(s, typeuri);
			}
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:28,代碼來源:SimpleGraph.java

示例2: toLiteral

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
/**
 * Create a datatyped literal from a blueprints property value.
 * <p>
 * Supports: Float, Double, Integer, Long, Boolean, Short, Byte, and String.
 */
default Literal toLiteral(final Object value) {

    final ValueFactory vf = Defaults.VF;
    
    if (value instanceof Float) {
        return vf.createLiteral((Float) value);
    } else if (value instanceof Double) {
        return vf.createLiteral((Double) value);
    } else if (value instanceof Integer) {
        return vf.createLiteral((Integer) value);
    } else if (value instanceof Long) {
        return vf.createLiteral((Long) value);
    } else if (value instanceof Boolean) {
        return vf.createLiteral((Boolean) value);
    } else if (value instanceof Short) {
        return vf.createLiteral((Short) value);
    } else if (value instanceof Byte) {
        return vf.createLiteral((Byte) value);
    } else if (value instanceof String) { 
        return vf.createLiteral((String) value);
    } else {
        throw new IllegalArgumentException(String.format("not supported: %s", value));
    }
    
}
 
開發者ID:blazegraph,項目名稱:tinkerpop3,代碼行數:31,代碼來源:BlazeValueFactory.java

示例3: getCreateStatements

import org.openrdf.model.ValueFactory; //導入依賴的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

示例4: handleTuple

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
@Override
public void handleTuple( BindingSet set, ValueFactory fac ) {
	URI pred = fac.createURI( set.getValue( "p" ).stringValue() );
	Value val = set.getValue( "o" );

	// for baseuri, we need the subject, not the object
	// and also, we use the VOID_DS as the key elsewhere in the code
	if ( RDF.TYPE.equals( pred ) ) {
		pred = SEMTOOL.Database;
		val = set.getValue( "db" );
	}
	else if ( pred.getNamespace().equals( DC.NAMESPACE ) ) {
		// silently handle the old DC namespace (ignore our DC-specific URIs)
		if ( !( MetadataConstants.DCT_CREATED.equals( pred )
				|| MetadataConstants.DCT_MODIFIED.equals( pred ) ) ) {
			pred = fac.createURI( DCTERMS.NAMESPACE, pred.getLocalName() );
		}
	}

	result.put( pred, val );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:22,代碼來源:MetadataQuery.java

示例5: clear

import org.openrdf.model.ValueFactory; //導入依賴的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

示例6: cleanValue

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
/**
 * "Cleans" a value for BigData
 *
 * @param v the value that needs cleaning
 * @param vf the value factory to make the new Value from
 * @return a value that won't make BigData bomb
 */
public static Value cleanValue( Value v, ValueFactory vf ) {
	Value newv;
	if ( v instanceof URI ) {
		newv = vf.createURI( v.stringValue() );
	}
	else if ( v instanceof BNode ) {
		newv = vf.createBNode( v.stringValue() );
	}
	else {
		Literal oldv = Literal.class.cast( v );
		if ( null != oldv.getLanguage() ) {
			newv = vf.createLiteral( oldv.stringValue(), oldv.getLanguage() );
		}
		else {
			newv = vf.createLiteral( oldv.stringValue(), oldv.getDatatype() );
		}
	}

	return newv;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:28,代碼來源:EngineLoader.java

示例7: rebuildConceptProps

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
private Model rebuildConceptProps( List<URI> concepts ) {
	String cimplosion = Utility.implode( concepts );

	// now see what properties are on concepts and edges
	String query = "SELECT DISTINCT ?type ?prop WHERE {\n"
			+ "  ?s ?prop ?propval . FILTER ( isLiteral( ?propval ) )\n"
			+ "  ?s a|rdfs:subClassOf+ ?type .\n"
			+ "  FILTER ( ?prop != rdfs:label ) .\n"
			+ "} VALUES ?type { " + cimplosion + " }";

	ModelQueryAdapter mqa = new ModelQueryAdapter( query ) {

		@Override
		public void handleTuple( BindingSet set, ValueFactory fac ) {
			URI type = URI.class.cast( set.getValue( "type" ) );
			URI prop = URI.class.cast( set.getValue( "prop" ) );
			result.add( type, prop, Constants.ANYNODE );
		}
	};

	return engine.queryNoEx( mqa );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:23,代碼來源:SemtoolStructureManagerImpl.java

示例8: doUpdate

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
public static final void doUpdate( UpdateExecutor query,
		RepositoryConnection rc, boolean dobindings ) throws RepositoryException,
		MalformedQueryException, UpdateExecutionException {

	String sparql = processNamespaces( dobindings ? query.getSparql()
			: query.bindAndGetSparql(), query.getNamespaces() );

	ValueFactory vfac = new ValueFactoryImpl();
	Update upd = rc.prepareUpdate( QueryLanguage.SPARQL, sparql );

	if ( dobindings ) {
		upd.setIncludeInferred( query.usesInferred() );
		query.setBindings( upd, vfac );
	}

	upd.execute();
	query.done();
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:19,代碼來源:AbstractSesameEngine.java

示例9: getModel

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
public static Model getModel( InsightManager im, User user ) {
	Model statements = new LinkedHashModel();
	int idx = 0;

	RDFParser parser = new TurtleParser();
	StatementCollector coll = new StatementCollector();
	parser.setRDFHandler( coll );
	try ( InputStream is = IEngine.class.getResourceAsStream( "/models/sempers.ttl" ) ) {
		parser.parse( is, SEMPERS.BASE_URI );
	}
	catch ( Exception e ) {
		log.warn( "could not include sempers.ttl ontology in statements", e );
	}

	statements.addAll( coll.getStatements() );

	ValueFactory vf = new ValueFactoryImpl();
	for ( Perspective p : im.getPerspectives() ) {
		statements.addAll( getStatements( p, user ) );
		statements.add( new StatementImpl( p.getId(), OLO.index,
				vf.createLiteral( idx++ ) ) );
	}

	return statements;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:26,代碼來源:InsightManagerImpl.java

示例10: getPerspectiveStatements

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
protected static Model getPerspectiveStatements( Perspective p,
		ValueFactory vf, UriBuilder urib, User user ) {

	Model statements = new LinkedHashModel();
	URI pid = p.getId();
	Date now = new Date();

	statements.add( new StatementImpl( pid, RDF.TYPE, SEMPERS.Perspective ) );
	statements.add( new StatementImpl( pid, RDFS.LABEL,
			vf.createLiteral( p.getLabel() ) ) );
	if ( null != p.getDescription() ) {
		statements.add( new StatementImpl( pid, DCTERMS.DESCRIPTION,
				vf.createLiteral( p.getDescription() ) ) );
	}

	statements.add( new StatementImpl( pid, DCTERMS.CREATED,
			vf.createLiteral( now ) ) );
	statements.add( new StatementImpl( pid, DCTERMS.MODIFIED,
			vf.createLiteral( now ) ) );
	statements.add( new StatementImpl( pid, DCTERMS.CREATOR,
			vf.createLiteral( getAuthorInfo( user ) ) ) );

	return statements;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:25,代碼來源:InsightManagerImpl.java

示例11: getParameterStatements

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
protected static Model getParameterStatements( Parameter parameter,
		URI predicateUri, URI queryUri, ValueFactory vf, UriBuilder urib,
		User user ) {

	Model statements = new LinkedHashModel();

	URI pid = parameter.getId();

	statements.add( new StatementImpl( pid, RDFS.LABEL,
			vf.createLiteral( parameter.getLabel() ) ) );

	statements.add( new StatementImpl( pid, SPL.predicate, predicateUri ) );
	statements.add( new StatementImpl( pid, SP.query, queryUri ) );

	statements.add( new StatementImpl( predicateUri, RDFS.LABEL,
			vf.createLiteral( parameter.getLabel() ) ) );
	statements.add( new StatementImpl( queryUri, SP.text,
			vf.createLiteral( parameter.getDefaultQuery() ) ) );

	return statements;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:22,代碼來源:InsightManagerImpl.java

示例12: convertToValueArray

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
public Value[] convertToValueArray( ValueFactory vf ) {
	int arrsize = propcache.size() + ( isRel() ? 2 : 1 );

	Value vals[] = new Value[arrsize];

	vals[0] = vf.createLiteral( getSubject() );
	int i = 0;
	if ( isRel() ) {
		vals[1] = vf.createLiteral( getObject() );
		i = 1;
	}

	for ( String prop : propcache.keySet() ) {
		vals[++i] = ( containsKey( prop ) ? get( prop ) : null );
	}

	return vals;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:19,代碼來源:LoadingSheetData.java

示例13: hasProperty

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
public boolean hasProperty( URI needle, Map<String, String> namespaces ) {
	ValueFactory vf = new ValueFactoryImpl();
	for ( String head : keySet() ) {
		if ( head.contains( ":" ) ) {
			int idx = head.indexOf( ":" );
			String headns = head.substring( 0, idx );
			String localname = head.substring( idx + 1 );

			if ( namespaces.containsKey( headns ) ) {
				URI uri = vf.createURI( namespaces.get( headns ), localname );
				if ( uri.equals( needle ) ) {
					return true;
				}
			}
		}
	}

	return false;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:20,代碼來源:LoadingSheetData.java

示例14: createObject

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
private Value createObject( String object, Map<String, String> jcrMap ) {
	ValueFactory vf = new ValueFactoryImpl();

	// need to do the class vs. object magic
	if ( object.contains( "+" ) ) {
		StringBuilder strBuilder = new StringBuilder();
		String[] objList = object.split( "\\+" );
		for ( String objList1 : objList ) {
			strBuilder.append( jcrMap.get( objList1 ) );
		}
		return vf.createLiteral( strBuilder.toString() );
	}

	Object o = jcrMap.get( object );
	if ( null == o ) {
		return null;
	}

	String val = o.toString();
	// see if we have a special datatype to worry about
	if ( datatypes.containsKey( object ) ) {
		return vf.createLiteral( val, datatypes.get( object ) );
	}
	return vf.createLiteral( val );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:26,代碼來源:CSVReader.java

示例15: testAddProperty_String

import org.openrdf.model.ValueFactory; //導入依賴的package包/類
@Test
public void testAddProperty_String() {
	LoadingSheetData lsd = LoadingSheetData.nodesheet( "tabname", "sbj" );
	lsd.addProperty( "xx" );
	lsd.addProperty( "yy" );
	Map<String, Value> props = new HashMap<>();
	ValueFactory vf = new ValueFactoryImpl();
	props.put( "xx", vf.createLiteral( "testval" ) );
	LoadingNodeAndPropertyValues naps = lsd.add( "instance", props );

	Value expected[] = { vf.createLiteral( "instance" ),
		vf.createLiteral( "testval" ), null };

	Value[] vals = naps.convertToValueArray( vf );
	assertArrayEquals( expected, vals );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:17,代碼來源:LoadingSheetDataTest.java


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