当前位置: 首页>>代码示例>>Java>>正文


Java Literal类代码示例

本文整理汇总了Java中org.openrdf.model.Literal的典型用法代码示例。如果您正苦于以下问题:Java Literal类的具体用法?Java Literal怎么用?Java Literal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Literal类属于org.openrdf.model包,在下文中一共展示了Literal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toLiteral

import org.openrdf.model.Literal; //导入依赖的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

示例2: fromLiteral

import org.openrdf.model.Literal; //导入依赖的package包/类
/**
 * Create a blueprints property value from a datatyped literal.
 * <p>
 * Return a graph property from a datatyped literal using its
 * XSD datatype.
 * <p>
 * Supports: Float, Double, Integer, Long, Boolean, Short, Byte, and String.
 */
default Object fromLiteral(final Literal l) {
    
    final URI datatype = l.getDatatype();
    
    if (datatype == null) {
        return l.getLabel();
    } else if (datatype.equals(XSD.FLOAT)) {
        return l.floatValue();
    } else if (datatype.equals(XSD.DOUBLE)) {
        return l.doubleValue();
    } else if (datatype.equals(XSD.INT)) {
        return l.intValue();
    } else if (datatype.equals(XSD.LONG)) {
        return l.longValue();
    } else if (datatype.equals(XSD.BOOLEAN)) {
        return l.booleanValue();
    } else if (datatype.equals(XSD.SHORT)) {
        return l.shortValue();
    } else if (datatype.equals(XSD.BYTE)) {
        return l.byteValue();
    } else {
        return l.getLabel();
    }
    
}
 
开发者ID:blazegraph,项目名称:tinkerpop3,代码行数:34,代码来源:BlazeValueFactory.java

示例3: property

import org.openrdf.model.Literal; //导入依赖的package包/类
/**
 * Helper for {@link BlazeEdge#property(String, Object)} and 
 * {@link BlazeVertexProperty#property(String, Object)}.
 * 
 * @param element the BlazeEdge or BlazeVertexProperty
 * @param key the property key
 * @param val the property value
 * @return a BlazeProperty
 */
<V> BlazeProperty<V> property(final BlazeReifiedElement element, 
        final String key, final V val) {
    final BigdataValueFactory rdfvf = rdfValueFactory();
    final BigdataBNode s = element.rdfId();
    final URI p = rdfvf.asValue(vf.propertyURI(key));
    final Literal lit = rdfvf.asValue(vf.toLiteral(val));
    
    final RepositoryConnection cxn = cxn();
    Code.wrapThrow(() -> {
        final BigdataStatement stmt = rdfvf.createStatement(s, p, lit);
        if (!bulkLoad) {
            // remove (<<stmt>> <key> ?)
            cxn.remove(s, p, null);
        }
        // add (<<stmt>> <key> "val")
        cxn.add(stmt);
    });
    
    final BlazeProperty<V> prop = new BlazeProperty<V>(this, element, p, lit);
    return prop;
}
 
开发者ID:blazegraph,项目名称:tinkerpop3,代码行数:31,代码来源:BlazeGraph.java

示例4: vertexProperty

import org.openrdf.model.Literal; //导入依赖的package包/类
/**
 * Binding set to vertex property (for Vertex elements).
 */
private final <V> Function<BindingSet, VertexProperty<V>> 
vertexProperty(final BlazeVertex v) {
    return bs -> {

        log.debug(() -> bs);
        final Literal val = (Literal) bs.getValue("val");
        final BigdataBNode sid = (BigdataBNode) bs.getValue("vp");
        final BigdataStatement stmt = sid.getStatement();
        final URI key = stmt.getPredicate();
        final String vpId = vertexPropertyId(stmt);
        final BlazeProperty<V> prop = 
                new BlazeProperty<>(BlazeGraph.this, v, key, val);
        final BlazeVertexProperty<V> bvp = 
                new BlazeVertexProperty<>(prop, vpId, sid);
        return bvp;

    };
}
 
开发者ID:blazegraph,项目名称:tinkerpop3,代码行数:22,代码来源:BlazeGraph.java

示例5: cleanValue

import org.openrdf.model.Literal; //导入依赖的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

示例6: getDatatype

import org.openrdf.model.Literal; //导入依赖的package包/类
/**
 * Gets the datatype of the given val. If val is null, returns null. It
 * returns {@link XMLSchema#ANYURI} for a URI, {@link XMLSchema#ENTITY} for a
 * BNode, and {@link Literal#getDatatype()} if it's a literal. If it's not a
 * {@link Value}, then it is converted to a Value first, and reprocessed. If
 * we have a literal, but a null datatype, returns {@link XMLSchema#STRING}
 *
 * @param val
 * @return
 */
public static URI getDatatype( Object val ) {
	if ( null == val ) {
		return null;
	}

	if ( val instanceof URI ) {
		return XMLSchema.ANYURI;
	}
	else if ( val instanceof Literal ) {
		Literal l = Literal.class.cast( val );
		return ( null == l.getDatatype() ? XMLSchema.STRING : l.getDatatype() );
	}
	else if ( val instanceof BNode ) {
		return XMLSchema.ENTITY;
	}

	Class<?> theClass = val.getClass();
	return REVTYPELOOKUP.getOrDefault( theClass, XMLSchema.STRING );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:30,代码来源:RDFDatatypeTools.java

示例7: testUpdateDate2

import org.openrdf.model.Literal; //导入依赖的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 );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:27,代码来源:InMemorySesameEngineTest.java

示例8: getDoubleIfPossibleFrom

import org.openrdf.model.Literal; //导入依赖的package包/类
public static double getDoubleIfPossibleFrom( Object propertyValue ) {
	if ( propertyValue == null ) {
		return -1;
	}

	String stringval;

	if ( propertyValue instanceof URI ) {
		stringval = URI.class.cast( propertyValue ).getLocalName();
	}
	else if ( propertyValue instanceof Literal ) {
		stringval = Literal.class.cast( propertyValue ).getLabel();
	}
	else {
		stringval = propertyValue.toString();
	}

	try {
		return Double.parseDouble( stringval );
	}
	catch ( NumberFormatException e ) {
		return -1;
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:25,代码来源:NodeEdgeNumberedPropertyUtility.java

示例9: create

import org.openrdf.model.Literal; //导入依赖的package包/类
@Override
public void create( List<Value[]> newdata, List<String> headers, IEngine engine ) {
	setHeaders( headers );
	convertUrisToLabels( newdata, engine );

	Map<String, List<Object>> data = new HashMap<>();
	for ( Value[] elemValues : newdata ) {
		List<Object> values = new ArrayList<>();
		for ( int j = 1; j < elemValues.length; j++ ) {
			Literal v = Literal.class.cast( elemValues[j] );
			double dbl = v.doubleValue();
			values.add( dbl );
		}
		data.put( elemValues[0].stringValue(), values );
	}

	Map<String, Object> columnChartHash = new HashMap<>();
	columnChartHash.put( "xAxis",
			headers.subList( 1, headers.size() ).toArray( new String[0] ) );
	columnChartHash.put( "type", "column" );
	columnChartHash.put( "title", getTitle() );
	columnChartHash.put( "dataSeries", data );

	addDataHash( columnChartHash );
	createView();
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:27,代码来源:ColumnChartPlaySheet.java

示例10: implode

import org.openrdf.model.Literal; //导入依赖的package包/类
private static String implode( Collection<Value> vals ) {
	StringBuilder sb = new StringBuilder();
	for ( Value v : vals ) {
		if ( sb.length() > 0 ) {
			sb.append( " | " );
		}

		if ( v instanceof Literal ) {
			Literal l = Literal.class.cast( v );
			String str = l.getLabel();
			if ( str.contains( "|" ) ) {
				sb.append( "\"" ).append( str ).append( "\"" );
			}
			else {
				sb.append( str );
			}
		}
		else {
			sb.append( v.stringValue() );
		}
	}

	return sb.toString();
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:25,代码来源:ConstraintPanel.java

示例11: populateRows

import org.openrdf.model.Literal; //导入依赖的package包/类
public final void populateRows() {
	rows = new ArrayList<>();
	URI datatypeURI;
	for ( GraphElement vertex : pickedVertices ) {
		for ( Map.Entry<URI, Value> entry : vertex.getValues().entrySet() ) {
			// don't edit the SUBJECT field (it's just an ID for the vertex)
			if( !RDF.SUBJECT.equals( entry.getKey()) ){
				if ( entry.getValue() instanceof Literal ) {
					Literal literal = (Literal) entry.getValue();
					if ( literal.getDatatype() == null ) {
						datatypeURI = XMLSchema.STRING;
					}
					else {
						datatypeURI = literal.getDatatype();
					}
					rows.add( new PropertyEditorRow( vertex, entry.getKey(), datatypeURI,
							entry.getValue() ) );
				}
				else if ( entry.getValue() instanceof URI ) {
					rows.add( new PropertyEditorRow( vertex, entry.getKey(), XMLSchema.ANYURI,
							entry.getValue() ) );
				}
			}
		}
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:27,代码来源:PropertyEditorTableModel.java

示例12: getValuePairRenderer

import org.openrdf.model.Literal; //导入依赖的package包/类
public static LabeledPairRenderer<Value> getValuePairRenderer( IEngine eng ) {
	return new LabeledPairRenderer<Value>() {
		@Override
		protected String getLabelForCacheMiss( Value val ) {
			if ( null == val ) {
				return "";
			}

			String ret;
			if ( val instanceof URI ) {
				URI uri = URI.class.cast( val );
				ret = ( null == eng ? uri.getLocalName()
						: Utility.getInstanceLabel( Resource.class.cast( val ), eng ) );
				cache( val, ret );
			}
			else if ( val instanceof Literal ) {
				ret = Literal.class.cast( val ).getLabel();
			}
			else {
				ret = val.stringValue();
			}
			return ret;
		}
	};
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:26,代码来源:LabeledPairRenderer.java

示例13: hash

import org.openrdf.model.Literal; //导入依赖的package包/类
private URI hash(final Resource subject, final URI predicate, final Value object) {
    final List<String> list = Lists.newArrayList();
    for (final Value value : new Value[] { subject, predicate, object }) {
        if (value instanceof URI) {
            list.add("\u0001");
            list.add(value.stringValue());
        } else if (value instanceof BNode) {
            list.add("\u0002");
            list.add(((BNode) value).getID());
        } else if (value instanceof Literal) {
            final Literal l = (Literal) value;
            list.add("\u0003");
            list.add(l.getLabel());
            if (l.getDatatype() != null) {
                list.add(l.getDatatype().stringValue());
            } else if (l.getLanguage() != null) {
                list.add(l.getLanguage());
            }
        }
    }
    final String id = Hash.murmur3(list.toArray(new String[list.size()])).toString();
    return FACTORY.createURI("fact:" + id);
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:24,代码来源:RDFGenerator.java

示例14: createRepresentation

import org.openrdf.model.Literal; //导入依赖的package包/类
public Set<Statement> createRepresentation(QuantityValue value) {
	Set<Statement> ret = new HashSet<Statement>();

	if (value == null)
		return Collections.unmodifiableSet(ret);

	URI valueId = value.getId();

	Literal literal = _literal(value.getNumericValue());

	ret.add(_statement(valueId, RDF.TYPE, QUDTSchema.QuantityValue));
	ret.add(_statement(valueId, RDF.TYPE, value.getType()));
	ret.add(_statement(valueId, DUL.hasRegionDataValue, literal));
	ret.add(_statement(valueId, QUDTSchema.numericValue, literal));

	Unit unit = value.getUnit();

	if (unit != null) {
		ret.add(_statement(valueId, QUDTSchema.unit, unit.getId()));
		ret.addAll(createRepresentation(unit));
	}

	return Collections.unmodifiableSet(ret);
}
 
开发者ID:markusstocker,项目名称:emrooz,代码行数:25,代码来源:RDFEntityRepresenter.java

示例15: activate

import org.openrdf.model.Literal; //导入依赖的package包/类
@Override
public void activate(final Collection<SesamePosLengthMatch> matches) throws RepositoryException {
	final RepositoryConnection con = driver.getConnection();
	final ValueFactory vf = driver.getValueFactory();

	final URI lengthProperty = vf.createURI(BASE_PREFIX + LENGTH);

	for (final SesamePosLengthMatch match : matches) {
		final Resource segment = match.getSegment();
		final Value length = match.getLength();

		final RepositoryResult<Statement> statementsToRemove = con.getStatements(segment, lengthProperty, length, true);
		while (statementsToRemove.hasNext()) {
			final Statement oldStatement = statementsToRemove.next();
			con.remove(oldStatement);
		}

		final Integer lengthInteger = new Integer(length.stringValue());
		final Integer newLengthInteger = -lengthInteger + 1;
		final Literal newLength = vf.createLiteral(newLengthInteger);
		final Statement newStatement = vf.createStatement(segment, lengthProperty, newLength);
		con.add(newStatement);
	}
}
 
开发者ID:FTSRG,项目名称:trainbenchmark,代码行数:25,代码来源:SesameTransformationRepairPosLength.java


注:本文中的org.openrdf.model.Literal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。