本文整理汇总了Java中org.eclipse.rdf4j.model.Literal类的典型用法代码示例。如果您正苦于以下问题:Java Literal类的具体用法?Java Literal怎么用?Java Literal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Literal类属于org.eclipse.rdf4j.model包,在下文中一共展示了Literal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: size
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
/**
* Returns number of triples in the entire triple store.
*
* @return long
* @throws RepositoryException
*/
@Override
public long size() throws RepositoryException{
try {
MarkLogicTupleQuery tupleQuery = prepareTupleQuery(COUNT_EVERYTHING);
tupleQuery.setIncludeInferred(false);
tupleQuery.setRulesets((SPARQLRuleset)null);
tupleQuery.setConstrainingQueryDefinition((QueryDefinition)null);
TupleQueryResult qRes = tupleQuery.evaluate();
// just one answer
BindingSet result = qRes.next();
qRes.close();
return ((Literal) result.getBinding("ct").getValue()).longValue();
} catch (QueryEvaluationException | MalformedQueryException e) {
throw new RepositoryException(e);
}
}
示例2: determineValue
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
private Optional<Object> determineValue(Model model, Resource resource) {
Set<Value> objects = model.filter(resource, predicate, null).objects();
if (objects.size() > 1)
throw new RuntimeException("more than 1 object for the predicate [" + predicate + "] for a logical source");
if (objects.isEmpty())
return Optional.empty();
Value object = objects.iterator().next();
if (object instanceof Literal)
return Optional.of(object.stringValue());
// map 'object' to some complex type
// TODO quite nasty to create the transformer here
ComplexValueTransformer transformer = new ComplexValueTransformer(
new TypeFromTripleTypeDecider(mapper),
mappingCache,
mapper,
o -> o
);
Object value = transformer.transform(model, object);
return Optional.of(value);
}
示例3: mapGraphValue_ReturnsStringValue_ForLdPath
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
@Test
public void mapGraphValue_ReturnsStringValue_ForLdPath() {
// Arrange
property.setVendorExtensions(ImmutableMap.of(OpenApiSpecificationExtensions.LDPATH, "ld-path"));
Literal literal = VALUE_FACTORY.createLiteral("foo", XMLSchema.STRING);
when(ldPathExecutorMock.ldPathQuery(subjectMock, "ld-path")).thenReturn(
ImmutableList.of(literal));
// Act
String result = mapper.mapGraphValue(property, entityContextMock,
ValueContext.builder().value(subjectMock).build(), mapperAdapter);
// Assert
assertThat(result, is("foo"));
}
示例4: mapGraphValue_ReturnsNull_ForLdPathMultipleResultsAndRequiredProperty
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
@Test
public void mapGraphValue_ReturnsNull_ForLdPathMultipleResultsAndRequiredProperty() {
// Assert
expectedException.expect(SchemaMapperRuntimeException.class);
expectedException.expectMessage(
"LDPath query 'ld-path' yielded multiple results (2) for a property, "
+ "which requires a single result.");
// Arrange
property.setVendorExtensions(nullableMapOf(OpenApiSpecificationExtensions.LDPATH, "ld-path"));
property.setRequired(true);
Literal foo = VALUE_FACTORY.createLiteral("foo", XMLSchema.STRING);
Literal bar = VALUE_FACTORY.createLiteral("bar", XMLSchema.STRING);
when(ldPathExecutorMock.ldPathQuery(subjectMock, "ld-path")).thenReturn(
ImmutableList.of(foo, bar));
// Act
mapper.mapGraphValue(property, entityContextMock,
ValueContext.builder().value(subjectMock).build(), mapperAdapter);
}
示例5: setUp
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
@Before
public void setUp() {
titelSubject = iri("ex", "titel");
labelPredicate = iri("ex", "label");
Literal hoofdstukObject = repository.getValueFactory().createLiteral("Hoofdstuk");
addStatement(repository.getValueFactory().createStatement(titelSubject, labelPredicate,
hoofdstukObject));
nummerPredicate = iri("ex", "nummer");
Literal threeObject = repository.getValueFactory().createLiteral("3");
addStatement(
repository.getValueFactory().createStatement(titelSubject, nummerPredicate, threeObject));
naamPredicate = iri("ex", "naam");
Literal beleidskaderObject = repository.getValueFactory().createLiteral("Beleidskader");
addStatement(repository.getValueFactory().createStatement(titelSubject, naamPredicate,
beleidskaderObject));
unknownPredicate = iri("ex", "unknown");
}
示例6: serializeValue
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
private Object serializeValue(Value value) {
if (!(value instanceof Literal)) {
return value.stringValue();
}
Literal literalValue = (Literal) value;
if (LiteralDataTypes.BOOLEAN_DATA_TYPES.contains(literalValue.getDatatype())) {
return literalValue.booleanValue();
}
if (LiteralDataTypes.INTEGER_DATA_TYPES.contains(literalValue.getDatatype())) {
return literalValue.integerValue();
}
if (LiteralDataTypes.DECIMAL_DATA_TYPES.contains(literalValue.getDatatype())) {
return literalValue.decimalValue();
}
return literalValue.stringValue();
}
示例7: create
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
@Override
public Backend create(Model backendModel, IRI identifier) {
Literal endpoint =
Models.objectLiteral(backendModel.filter(identifier, ELMO.ENDPOINT, null)).orElseThrow(
() -> new ConfigurationException(String.format(
"No <%s> statement has been found for backend <%s>.", ELMO.ENDPOINT, identifier)));
if (!XMLSchema.ANYURI.equals(endpoint.getDatatype())) {
throw new ConfigurationException(
String.format("Object <%s> for backend <%s> must be of datatype <%s>.", ELMO.ENDPOINT,
identifier, XMLSchema.ANYURI));
}
SPARQLRepository repository = new SPARQLRepository(endpoint.stringValue());
repository.initialize();
return new SparqlBackend.Builder(identifier, repository, informationProductFactory).build();
}
示例8: create_ThrowsException_WithInvalidDataType
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
@Test
public void create_ThrowsException_WithInvalidDataType() {
// Arrange
Literal endpointAsString =
SimpleValueFactory.getInstance().createLiteral(DBEERPEDIA.ENDPOINT.stringValue());
Model backendModel =
new ModelBuilder().add(DBEERPEDIA.BACKEND, ELMO.ENDPOINT, endpointAsString).build();
// Assert
thrown.expect(ConfigurationException.class);
thrown.expectMessage(String.format("Object <%s> for backend <%s> must be of datatype <%s>.",
ELMO.ENDPOINT, DBEERPEDIA.BACKEND, XMLSchema.ANYURI));
// Act
backendFactory.create(backendModel, DBEERPEDIA.BACKEND);
}
示例9: getVertexByValue
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
private Vertex getVertexByValue(final Value value, final Schema.VertexLabel vertexLabel) {
Iterator<Vertex> hits = traversal.V()
.has(T.label, vertexLabel.name()).has(Schema.VertexProperties.VALUE, value.stringValue());
while (hits.hasNext()) {
Vertex next = hits.next();
// literals, additionally, may differ in datatype or language
if (vertexLabel.equals(Schema.VertexLabel.Literal)
&& !datatypeAndLanguageEquals((Literal) value, next)) {
continue;
}
return next;
}
return null;
}
示例10: testGetStatementsMalformedTypedLiteral
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
@Test
public void testGetStatementsMalformedTypedLiteral() throws Exception {
testAdminCon.getParserConfig().addNonFatalError(BasicParserSettings.VERIFY_DATATYPE_VALUES);
Literal invalidIntegerLiteral = vf.createLiteral("four", XMLSchema.INTEGER);
try {
testAdminCon.add(micah, homeTel, invalidIntegerLiteral, dirgraph);
RepositoryResult<Statement> statements = testAdminCon.getStatements(micah, homeTel, null, true);
assertNotNull(statements);
assertTrue(statements.hasNext());
Statement st = statements.next();
assertTrue(st.getObject() instanceof Literal);
assertTrue(st.getObject().equals(invalidIntegerLiteral));
} catch (RepositoryException e) {
// shouldn't happen
fail(e.getMessage());
}
}
示例11: appendLiteral
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
/**
* Append the literal to the stringbuilder.
*
* @param sb
* @param lit
* @return
*/
protected static StringBuilder appendLiteral(StringBuilder sb, Literal lit) {
sb.append('"');
sb.append(lit.getLabel().replace("\"", "\\\""));
sb.append('"');
if (lit.getLanguage().isPresent()) {
sb.append('@');
sb.append(lit.getLanguage().get());
}
if (lit.getDatatype() != null) {
if (!lit.getDatatype().toString().equals("http://www.w3.org/2001/XMLSchema#string")) {
sb.append("^^<");
sb.append(lit.getDatatype().stringValue());
sb.append('>');
}
}
return sb;
}
示例12: appendLiteral
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
protected static StringBuilder appendLiteral(StringBuilder sb, Literal lit) {
sb.append('\'');
sb.append(lit.getLabel().replace("\"", "\\\""));
sb.append('\'');
if (lit.getLanguage() != null && lit.getLanguage().isPresent()) {
sb.append('@');
sb.append(lit.getLanguage());
}
if (lit.getDatatype() != null) {
sb.append("^^<");
sb.append(lit.getDatatype().stringValue());
sb.append('>');
}
return sb;
}
示例13: createSystemAgent
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
/**
* Instantiate an {@link ORMapAgent} to represent a System agent, and use the {@link RMapService} to create the
* agent. Verifies the agent was created using {@link RMapService#isAgentId(URI)}
*
* @param rmapService used to create the agent in the underlying triplestore
* @throws RMapException
* @throws RMapDefectiveArgumentException
* @throws URISyntaxException
*/
public static RMapAgent createSystemAgent(RMapService rmapService) throws RMapException, RMapDefectiveArgumentException, URISyntaxException {
IRI AGENT_IRI = ORAdapter.getValueFactory().createIRI(TestConstants.SYSAGENT_ID);
IRI ID_PROVIDER_IRI = ORAdapter.getValueFactory().createIRI(TestConstants.SYSAGENT_ID_PROVIDER);
IRI AUTH_ID_IRI = ORAdapter.getValueFactory().createIRI(TestConstants.SYSAGENT_AUTH_ID);
Literal NAME = ORAdapter.getValueFactory().createLiteral(TestConstants.SYSAGENT_NAME);
RMapAgent sysagent = new ORMapAgent(AGENT_IRI, ID_PROVIDER_IRI, AUTH_ID_IRI, NAME);
RequestEventDetails requestEventDetails = new RequestEventDetails(new URI(TestConstants.SYSAGENT_ID), new URI(TestConstants.SYSAGENT_KEY));
//create new test agent
URI agentId = sysagent.getId().getIri();
if (!rmapService.isAgentId(agentId)) {
rmapService.createAgent(sysagent, requestEventDetails);
}
// Check the agent was created
assertTrue(rmapService.isAgentId(agentId));
return sysagent;
}
示例14: createSystemAgent
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
/**
* Create generic sysagent and RequestAgent for general use using TestConstants.
* @throws RMapException
* @throws RMapDefectiveArgumentException
* @throws URISyntaxException
*/
protected void createSystemAgent() throws RMapException, RMapDefectiveArgumentException, URISyntaxException{
if (sysagent == null) {
IRI AGENT_IRI = ORAdapter.getValueFactory().createIRI(TestConstants.SYSAGENT_ID);
IRI ID_PROVIDER_IRI = ORAdapter.getValueFactory().createIRI(TestConstants.SYSAGENT_ID_PROVIDER);
IRI AUTH_ID_IRI = ORAdapter.getValueFactory().createIRI(TestConstants.SYSAGENT_AUTH_ID);
Literal NAME = ORAdapter.getValueFactory().createLiteral(TestConstants.SYSAGENT_NAME);
sysagent = new ORMapAgent(AGENT_IRI, ID_PROVIDER_IRI, AUTH_ID_IRI, NAME);
if (requestEventDetails==null){
requestEventDetails = new RequestEventDetails(new URI(TestConstants.SYSAGENT_ID),new URI(TestConstants.SYSAGENT_KEY));
}
//create new test agent
URI agentId=sysagent.getId().getIri();
if (!rmapService.isAgentId(agentId)) {
rmapService.createAgent(sysagent,requestEventDetails);
}
// Check the agent was created
assertTrue(rmapService.isAgentId(agentId));
}
}
示例15: rMapLiteral2Rdf4jLiteral
import org.eclipse.rdf4j.model.Literal; //导入依赖的package包/类
/**
* Converts an RMapLiteral to an org.eclipse.rdf4j.model.Literal. Null returns null
*
* @param rLiteral the RMapLiteral to be converted
* @return the equivalent RDF4J literal
* @throws IllegalArgumentException if the RMapLiterals could not convert to a valid Open RDF Literal
*/
public static Literal rMapLiteral2Rdf4jLiteral(RMapLiteral rLiteral) {
if (rLiteral == null) {
return null;
}
Literal literal = null;
String litString = rLiteral.getStringValue();
if (rLiteral.getDatatype() != null){ //has a datatype associated with the literal
IRI datatype = rMapIri2Rdf4jIri(rLiteral.getDatatype());
literal = getValueFactory().createLiteral(litString,datatype);
}
else if (rLiteral.getLanguage() != null){ //has a language associated with the literal
literal = getValueFactory().createLiteral(litString,rLiteral.getLanguage());
}
else {//just a string value - no type or language
literal = getValueFactory().createLiteral(litString);
}
return literal;
}