org.openrdf.model.util.Literals类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.openrdf.model.util.Literals类的一些代码示例,展示了Literals类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Literals类的具体详情如下:
包路径:org.openrdf.model.util.Literals
类名称:Literals

Literals介绍

[英]Various utility methods related to Literal.
[中]与文字相关的各种实用程序方法。

代码示例

代码示例来源:origin: org.openrdf.sesame/sesame-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());
  }
  else {
    sb.append("^^<");
    sb.append(lit.getDatatype().stringValue());
    sb.append('>');
  }
  return sb;
}

代码示例来源:origin: org.openrdf.sesame/sesame-model

/**
 * 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.
 * @since 2.7.0
 */
public static Literal createLiteralOrFail(ValueFactory valueFactory, Object object)
  throws LiteralUtilException
{
  return createLiteral(valueFactory, object, true);
}

代码示例来源:origin: org.openrdf.sesame/sesame-model

/**
 * 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.openrdf.sesame/sesame-queryalgebra-evaluation

IRI leftDatatype = leftLit.getDatatype();
IRI rightDatatype = rightLit.getDatatype();
boolean leftLangLit = Literals.isLanguageLiteral(leftLit);
boolean rightLangLit = Literals.isLanguageLiteral(rightLit);
  compareResult = leftLit.getLabel().compareTo(rightLit.getLabel());

代码示例来源:origin: org.openrdf.sesame/sesame-sail-rdbms

protected long hashLiteralType(MessageDigest digest, Value value) {
  if (value instanceof Literal) {
    Literal lit = (Literal)value;
    if (Literals.isLanguageLiteral(lit)) {
      return hash(digest, lit.getLanguage());
    }
    else {
      return hash(digest, lit.getDatatype().stringValue());
    }
  }
  return 0;
}

代码示例来源:origin: org.openrdf.sesame/sesame-queryalgebra-evaluation

IRI datatype = literal.getDatatype();
  return valueFactory.createLiteral(literal.getLabel(), XMLSchema.STRING);
else if (!Literals.isLanguageLiteral(literal)) {
  if (datatype.equals(XMLSchema.STRING)) {
    return literal;
    if (XMLDatatypeUtil.isValidValue(literal.getLabel(), datatype)) {
      String normalizedValue = XMLDatatypeUtil.normalize(literal.getLabel(), datatype);
      return valueFactory.createLiteral(normalizedValue, XMLSchema.STRING);

代码示例来源:origin: org.openrdf.sesame/sesame-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: org.openrdf.sesame/sesame-queryalgebra-evaluation

/**
 * Checks whether the supplied two literal arguments are 'argument
 * compatible' according to the SPARQL definition.
 * 
 * @param arg1
 *        the first argument
 * @param arg2
 *        the second argument
 * @return true iff the two supplied arguments are argument compatible, false
 *         otherwise
 * @since 2.7.0
 * @see <a
 *      href="http://www.w3.org/TR/sparql11-query/#func-arg-compatibility">SPARQL
 *      Argument Compatibility Rules</a>
 */
public static boolean compatibleArguments(Literal arg1, Literal arg2) {
  boolean arg1Language = Literals.isLanguageLiteral(arg1);
  boolean arg2Language = Literals.isLanguageLiteral(arg2);
  boolean arg1Simple = isSimpleLiteral(arg1);
  boolean arg2Simple = isSimpleLiteral(arg2);
  // 1. The arguments are literals typed as xsd:string
  // 2. The arguments are language literals with identical language tags
  // 3. The first argument is a language literal and the second
  // argument is a literal typed as xsd:string
  boolean compatible =
  (arg1Simple && arg2Simple)
      || (arg1Language && arg2Language && arg1.getLanguage().equals(arg2.getLanguage()))
      || (arg1Language && arg2Simple);
  return compatible;
}

代码示例来源:origin: org.openrdf.sesame/sesame-model

/**
 * Returns the label of the literal.
 */
@Override
public String toString() {
  StringBuilder sb = new StringBuilder(label.length() * 2);
  sb.append('"');
  sb.append(label);
  sb.append('"');
  if (Literals.isLanguageLiteral(this)) {
    sb.append('@');
    sb.append(language);
  }
  else {
    sb.append("^^<");
    sb.append(datatype.toString());
    sb.append(">");
  }
  return sb.toString();
}

代码示例来源:origin: org.openrdf.sesame/sesame-model

while (iter.hasNext()) {
  Object o = iter.next();
  Value v = o instanceof Value ? (Value)o : Literals.createLiteralOrFail(vf, o);
  Statements.consume(vf, current, RDF.FIRST, v, consumer, contexts);
  if (iter.hasNext()) {

代码示例来源:origin: org.openrdf.sesame/sesame-rio-rdfjson

final Literal l = (Literal)object;
if (Literals.isLanguageLiteral(l)) {
  jg.writeObjectField(RDFJSONUtility.LANG, l.getLanguage().orElse(null));
  jg.writeObjectField(RDFJSONUtility.DATATYPE, l.getDatatype().stringValue());

代码示例来源:origin: org.openrdf.sesame/sesame-queryalgebra-evaluation

/**
 * Checks whether the supplied literal is a "string literal". A "string
 * literal" is either a simple literal, a plain literal with language tag, or
 * a literal with datatype xsd:string.
 * 
 * @see <a href="http://www.w3.org/TR/sparql11-query/#func-string">SPARQL
 *      Functions on Strings Documentation</a>
 */
public static boolean isStringLiteral(Literal l) {
  IRI datatype = l.getDatatype();
  return Literals.isLanguageLiteral(l) || datatype.equals(XMLSchema.STRING);
}

代码示例来源:origin: org.openrdf.sesame/sesame-sail-rdbms

String language = literal.getLanguage();
URI datatype = literal.getDatatype();
if (Literals.isLanguageLiteral(literal)) {
  table.insertLanguage(id, label, language);

代码示例来源:origin: org.openrdf.sesame/sesame-repository-sparql

private static StringBuilder appendValue(StringBuilder sb, Literal lit) {
    sb.append('"');
    sb.append(SPARQLUtil.encodeString(lit.getLabel()));
    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.openrdf.sesame/sesame-http-protocol

if (Literals.isLanguageLiteral(literal)) {
  xmlWriter.setAttribute(TransactionXMLConstants.LANGUAGE_ATT, literal.getLanguage().get());
      literal.getDatatype().stringValue());

代码示例来源:origin: org.openrdf.sesame/sesame-model

/**
 * 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.
 * @since 2.7.0
 */
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.openrdf.sesame/sesame-queryalgebra-evaluation

/**
   * Append the literal to the stringbuilder: "myLiteral"^^<dataType>
   * 
   * @param sb
   * @param lit
   * @return the StringBuilder, for convenience
   */
  protected static StringBuilder appendLiteral(StringBuilder sb, Literal lit) {
    sb.append('"');
    sb.append(lit.getLabel().replace("\"", "\\\""));
    sb.append('"');

    if (Literals.isLanguageLiteral(lit)) {
      sb.append('@');
      sb.append(lit.getLanguage());
    }
    else {
      sb.append("^^<");
      sb.append(lit.getDatatype().stringValue());
      sb.append('>');
    }
    return sb;
  }
}

代码示例来源:origin: org.apache.marmotta/marmotta-core

URI ctx = valueFactory.createURI(uri);
if (StringUtils.isNotBlank(label)) {
  conn.add(ctx, RDFS.LABEL, Literals.createLiteral(valueFactory, label), ctx);

代码示例来源:origin: org.openrdf.sesame/sesame-sail-federation

private void writeLiteral(StringBuilder builder, Literal lit) {
  String label = lit.getLabel();
  if (label.indexOf('\n') > 0 || label.indexOf('\r') > 0 || label.indexOf('\t') > 0) {
    // Write label as long string
    builder.append("\"\"\"");
    builder.append(TurtleUtil.encodeLongString(label));
    builder.append("\"\"\"");
  }
  else {
    // Write label as normal string
    builder.append("\"");
    builder.append(TurtleUtil.encodeString(label));
    builder.append("\"");
  }
  IRI datatype = lit.getDatatype();
  if (Literals.isLanguageLiteral(lit)) {
    // Append the literal's language
    builder.append("@");
    builder.append(lit.getLanguage().get());
  }
  else {
    // Append the literal's data type (possibly written as an
    // abbreviated URI)
    builder.append("^^");
    writeURI(builder, datatype);
  }
}

代码示例来源:origin: apache/marmotta

URI ctx = valueFactory.createURI(uri);
if (StringUtils.isNotBlank(label)) {
  conn.add(ctx, RDFS.LABEL, Literals.createLiteral(valueFactory, label), ctx);

相关文章