当前位置: 首页>>代码示例>>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;未经允许,请勿转载。