本文整理了Java中org.eclipse.rdf4j.model.util.Literals
类的一些代码示例,展示了Literals
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Literals
类的具体详情如下:
包路径:org.eclipse.rdf4j.model.util.Literals
类名称:Literals
[英]Various utility methods related to Literal.
[中]与文字相关的各种实用程序方法。
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
private StringBuilder appendValue(StringBuilder sb, Literal lit) {
sb.append('"');
sb.append(lit.getLabel().replace("\"", "\\\""));
sb.append('"');
if (Literals.isLanguageLiteral(lit)) {
sb.append('@');
sb.append(lit.getLanguage().get());
}
else {
sb.append("^^<");
sb.append(lit.getDatatype().stringValue());
sb.append('>');
}
return sb;
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
/**
* Returns the result of {@link #getBooleanValue(Literal, boolean) getBooleanValue((Literal)value,
* fallback)} in case the supplied value is a literal, returns the fallback value otherwise.
*/
public static boolean getBooleanValue(Value v, boolean fallback) {
if (v instanceof Literal) {
return getBooleanValue((Literal)v, fallback);
}
else {
return fallback;
}
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
public Literal createLiteral(String label, String language) {
if (!Literals.isValidLanguageTag(language)) {
throw new IllegalArgumentException("Not a valid language tag: " + language);
}
return delegate.createLiteral(label, language);
}
代码示例来源:origin: apache/incubator-rya
/**
* Converts a {@link Literal} into a {@link RyaType} representation of the
* {@code literal}.
* @param literal the {@link Literal} to convert.
* @return the {@link RyaType} representation of the {@code literal}.
*/
public static RyaType convertLiteral(final Literal literal) {
if (literal == null) {
return null;
}
if (literal.getDatatype() != null) {
if (Literals.isLanguageLiteral(literal)) {
final String language = literal.getLanguage().get();
if (Literals.isValidLanguageTag(language)) {
return new RyaType(literal.getDatatype(), literal.stringValue(), language);
} else {
log.warn("Invalid language (" + LogUtils.clean(language) + ") found in Literal. Defaulting to: " + UNDETERMINED_LANGUAGE);
// Replace invalid language with "und"
return new RyaType(literal.getDatatype(), literal.stringValue(), UNDETERMINED_LANGUAGE);
}
}
return new RyaType(literal.getDatatype(), literal.stringValue());
}
return new RyaType(literal.stringValue());
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
RepositoryInfo repInfo = new RepositoryInfo();
String id = Literals.getLabel(bindingSet.getValue("id"), null);
String description = Literals.getLabel(bindingSet.getValue("title"), null);
boolean readable = Literals.getBooleanValue(bindingSet.getValue("readable"), false);
boolean writable = Literals.getBooleanValue(bindingSet.getValue("writable"), false);
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
/**
* Creates a typed {@link Literal} out of the supplied object, mapping the runtime type of the object to
* the appropriate XML Schema type. If no mapping is available, the method throws a
* {@link LiteralUtilException}. Recognized types are {@link Boolean}, {@link Byte}, {@link Double},
* {@link Float}, {@link Integer}, {@link Long}, {@link Short}, {@link XMLGregorianCalendar } , and
* {@link Date}.
*
* @param valueFactory
* @param object
* an object to be converted to a typed literal.
* @return a typed literal representation of the supplied object.
* @throws LiteralUtilException
* If the literal could not be created.
* @throws NullPointerException
* If the object was null.
*/
public static Literal createLiteralOrFail(ValueFactory valueFactory, Object object)
throws LiteralUtilException
{
return createLiteral(valueFactory, object, true);
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
/**
* Returns the result of {@link #getLabel(Literal, String) getLabel((Literal)v, fallback} in case the
* supplied value is a literal, returns the fallback value otherwise.
*/
public static String getLabel(Value v, String fallback) {
return v instanceof Literal ? getLabel((Literal)v, fallback) : fallback;
}
代码示例来源:origin: eclipse/rdf4j
RepositoryInfo repInfo = new RepositoryInfo();
String id = Literals.getLabel(bindingSet.getValue("id"), null);
String description = Literals.getLabel(bindingSet.getValue("title"), null);
boolean readable = Literals.getBooleanValue(bindingSet.getValue("readable"), false);
boolean writable = Literals.getBooleanValue(bindingSet.getValue("writable"), false);
代码示例来源:origin: eclipse/rdf4j
/**
* Creates a typed {@link Literal} out of the supplied object, mapping the runtime type of the object to
* the appropriate XML Schema type. If no mapping is available, the method throws a
* {@link LiteralUtilException}. Recognized types are {@link Boolean}, {@link Byte}, {@link Double},
* {@link Float}, {@link Integer}, {@link Long}, {@link Short}, {@link XMLGregorianCalendar } , and
* {@link Date}.
*
* @param valueFactory
* @param object
* an object to be converted to a typed literal.
* @return a typed literal representation of the supplied object.
* @throws LiteralUtilException
* If the literal could not be created.
* @throws NullPointerException
* If the object was null.
*/
public static Literal createLiteralOrFail(ValueFactory valueFactory, Object object)
throws LiteralUtilException
{
return createLiteral(valueFactory, object, true);
}
代码示例来源:origin: eclipse/rdf4j
/**
* Returns the result of {@link #getLabel(Literal, String) getLabel((Literal)v, fallback} in case the
* supplied value is a literal, returns the fallback value otherwise.
*/
public static String getLabel(Value v, String fallback) {
return v instanceof Literal ? getLabel((Literal)v, fallback) : fallback;
}
代码示例来源:origin: eclipse/rdf4j
private StringBuilder appendValue(StringBuilder sb, Literal lit) {
sb.append('"');
sb.append(lit.getLabel().replace("\"", "\\\""));
sb.append('"');
if (Literals.isLanguageLiteral(lit)) {
sb.append('@');
sb.append(lit.getLanguage().get());
}
else {
sb.append("^^<");
sb.append(lit.getDatatype().stringValue());
sb.append('>');
}
return sb;
}
代码示例来源:origin: eclipse/rdf4j
@Override
public Literal createLiteral(String label, String language) {
if (!Literals.isValidLanguageTag(language)) {
throw new IllegalArgumentException("Not a valid language tag: " + language);
}
return delegate.createLiteral(label, language);
}
代码示例来源:origin: eclipse/rdf4j
/**
* Returns the result of {@link #getBooleanValue(Literal, boolean) getBooleanValue((Literal)value,
* fallback)} in case the supplied value is a literal, returns the fallback value otherwise.
*/
public static boolean getBooleanValue(Value v, boolean fallback) {
if (v instanceof Literal) {
return getBooleanValue((Literal)v, fallback);
}
else {
return fallback;
}
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
/**
* Creates a typed {@link Literal} out of the supplied object, mapping the runtime type of the object to
* the appropriate XML Schema type. If no mapping is available, the method returns a literal with the
* string representation of the supplied object as the value, and {@link XMLSchema#STRING} as the
* datatype. Recognized types are {@link Boolean}, {@link Byte}, {@link Double}, {@link Float},
* {@link Integer}, {@link Long}, {@link Short}, {@link XMLGregorianCalendar } , and {@link Date}.
*
* @param valueFactory
* @param object
* an object to be converted to a typed literal.
* @return a typed literal representation of the supplied object.
* @throws NullPointerException
* If the object was null.
*/
public static Literal createLiteral(ValueFactory valueFactory, Object object) {
try {
return createLiteral(valueFactory, object, false);
}
catch (LiteralUtilException e) {
// This should not happen by design
throw new IllegalStateException(e);
}
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-repository-sparql
private StringBuilder appendValue(StringBuilder sb, Literal lit) {
sb.append('"');
sb.append(lit.getLabel().replace("\"", "\\\""));
sb.append('"');
if (Literals.isLanguageLiteral(lit)) {
sb.append('@');
sb.append(lit.getLanguage().get());
}
else {
sb.append("^^<");
sb.append(lit.getDatatype().stringValue());
sb.append('>');
}
return sb;
}
代码示例来源:origin: apache/incubator-rya
/**
* Validates the language based on the data type.
* <p>
* This will do one of the following:
* <ul>
* <li>Return the original {@code language} if the {@code dataType} is
* {@link RDF#LANGSTRING} and it's of a VALID format.</li>
* <li>Returns {@link UNDETERMINED_LANGUAGE} if the {@code dataType} is
* {@link RDF#LANGSTRING} and it's of an INVALID format.</li>
* <li>Return {@code null} if the dataType is NOT {@link RDF#LANGSTRING}.</li>
* </ul>
* @param language the language to validate.
* @param dataType the {@link IRI} data type to validate against.
* @return the validated language.
*/
public static String validateLanguage(final String language, final IRI dataType) {
String result = null;
if (RDF.LANGSTRING.equals(dataType)) {
if (language != null && Literals.isValidLanguageTag(language)) {
result = language;
} else {
result = UNDETERMINED_LANGUAGE;
}
}
return result;
}
}
代码示例来源:origin: eclipse/rdf4j
@Override
public boolean isWritable() throws RepositoryException {
if (!isInitialized()) {
throw new IllegalStateException("HTTPRepository not initialized.");
}
boolean isWritable = false;
try (RDF4JProtocolSession client = createHTTPClient()) {
final String repositoryURL = client.getRepositoryURL();
try (TupleQueryResult repositoryList = client.getRepositoryList()) {
while (repositoryList.hasNext()) {
final BindingSet bindingSet = repositoryList.next();
final Value uri = bindingSet.getValue("uri");
if (uri != null && uri.stringValue().equals(repositoryURL)) {
isWritable = Literals.getBooleanValue(bindingSet.getValue("writable"), false);
break;
}
}
}
}
catch (QueryEvaluationException e) {
throw new RepositoryException(e);
}
catch (IOException e) {
throw new RepositoryException(e);
}
return isWritable;
}
代码示例来源:origin: eclipse/rdf4j
/**
* Creates a typed {@link Literal} out of the supplied object, mapping the runtime type of the object to
* the appropriate XML Schema type. If no mapping is available, the method returns a literal with the
* string representation of the supplied object as the value, and {@link XMLSchema#STRING} as the
* datatype. Recognized types are {@link Boolean}, {@link Byte}, {@link Double}, {@link Float},
* {@link Integer}, {@link Long}, {@link Short}, {@link XMLGregorianCalendar } , and {@link Date}.
*
* @param valueFactory
* @param object
* an object to be converted to a typed literal.
* @return a typed literal representation of the supplied object.
* @throws NullPointerException
* If the object was null.
*/
public static Literal createLiteral(ValueFactory valueFactory, Object object) {
try {
return createLiteral(valueFactory, object, false);
}
catch (LiteralUtilException e) {
// This should not happen by design
throw new IllegalStateException(e);
}
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-queryalgebra-evaluation
/**
* Checks whether the supplied literal is a "simple literal". A "simple literal" is a literal with no
* language tag and the datatype {@link XMLSchema#STRING}.
*
* @see <a href="http://www.w3.org/TR/sparql11-query/#simple_literal">SPARQL Simple Literal
* Documentation</a>
*/
public static boolean isSimpleLiteral(Literal l) {
return !Literals.isLanguageLiteral(l) && l.getDatatype().equals(XMLSchema.STRING);
}
代码示例来源:origin: apache/incubator-rya
@Override
public RyaType deserialize(final byte[] bytes) throws RyaTypeResolverException {
if (!deserializable(bytes)) {
throw new RyaTypeResolverException("Bytes not deserializable");
}
final RyaType rt = newInstance();
rt.setDataType(getRyaDataType());
String data = new String(bytes, 0, bytes.length - 2, StandardCharsets.UTF_8);
if (RDF.LANGSTRING.equals(rt.getDataType())) {
final int langDelimiterPos = data.lastIndexOf(LiteralLanguageUtils.LANGUAGE_DELIMITER);
final String parsedData = data.substring(0, langDelimiterPos);
final String language = data.substring(langDelimiterPos + 1, data.length());
if (language != null && Literals.isValidLanguageTag(language)) {
rt.setLanguage(language);
} else {
rt.setLanguage(LiteralLanguageUtils.UNDETERMINED_LANGUAGE);
}
data = parsedData;
}
rt.setData(deserializeData(data));
return rt;
}
内容来源于网络,如有侵权,请联系作者删除!