org.openrdf.model.util.Literals.isLanguageLiteral()方法的使用及代码示例

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

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

Literals.isLanguageLiteral介绍

[英]Helper method to determine whether a literal is a language literal, and not a typed literal.
[中]Helper方法来确定文本是否为语言文本,而不是类型化文本。

代码示例

代码示例来源: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-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-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-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-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-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.openrdf.sesame/sesame-queryrender

/**
 * Return the query string rendering of the {@link Value}
 * 
 * @param theValue
 *        the value to render
 * @return the value rendered in its query string representation
 * @since 2.8.0
 */
public static String toSeRQL(Value theValue) {
  StringBuilder aBuffer = new StringBuilder();
  if (theValue instanceof IRI) {
    IRI aURI = (IRI)theValue;
    aBuffer.append("<").append(aURI.toString()).append(">");
  }
  else if (theValue instanceof BNode) {
    aBuffer.append("_:").append(((BNode)theValue).getID());
  }
  else if (theValue instanceof Literal) {
    Literal aLit = (Literal)theValue;
    aBuffer.append("\"").append(escape(aLit.getLabel())).append("\"");
    if (Literals.isLanguageLiteral(aLit)) {
      aBuffer.append("@").append(aLit.getLanguage());
    }
    else {
      aBuffer.append("^^<").append(aLit.getDatatype().toString()).append(">");
    }
  }
  return aBuffer.toString();
}

代码示例来源: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: 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-queryrender

if (Literals.isLanguageLiteral(aLit)) {
  builder.append("@").append(aLit.getLanguage());

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

Literal lit = (Literal)value;
if (Literals.isLanguageLiteral(lit)) {
  jg.writeObjectField("xml:lang", lit.getLanguage().orElse(null));

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

private void writeLiteral(Literal literal)
  throws IOException
{
  String label = literal.getLabel();
  IRI datatype = literal.getDatatype();
  if (Literals.isLanguageLiteral(literal)) {
    out.writeByte(LANG_LITERAL_VALUE);
    writeString(label);
    writeString(literal.getLanguage().get());
  }
  else {
    out.writeByte(DATATYPE_LITERAL_VALUE);
    writeString(label);
    writeString(datatype.toString());
  }
}

代码示例来源:origin: io.konig/konig-yaml

if (Literals.isLanguageLiteral(literal)) {

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

appendable.append("\"");
if (Literals.isLanguageLiteral(lit)) {

代码示例来源: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-queryresultio-text

if (Literals.isLanguageLiteral(lit)) {

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

protected void serialize(Literal literal, XMLWriter xmlWriter)
  throws IOException
{
  if (literal != null) {
    if (Literals.isLanguageLiteral(literal)) {
      xmlWriter.setAttribute(TransactionXMLConstants.LANG_ATT, literal.getLanguage().get());
    }
    else {
      xmlWriter.setAttribute(TransactionXMLConstants.DATATYPE_ATT, literal.getDatatype().toString());
    }
    String label = literal.getLabel();
    boolean valid = true;
    int i = 0;
    while (valid && i < label.length()) {
      char c = label.charAt(i++);
      valid = XMLUtil.isValidCharacterDataChar(c);
    }
    if (!valid) {
      xmlWriter.setAttribute(TransactionXMLConstants.ENCODING_ATT, "base64");
      label = javax.xml.bind.DatatypeConverter.printBase64Binary(label.getBytes("UTF-8"));
    }
    xmlWriter.textElement(TransactionXMLConstants.LITERAL_TAG, label);
  }
  else {
    serializeNull(xmlWriter);
  }
}

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

/**
 * Writes out the XML-representation for the supplied value.
 */
private void writeValue(Value value)
  throws IOException, RDFHandlerException
{
  if (value instanceof IRI) {
    IRI uri = (IRI)value;
    xmlWriter.textElement(URI_TAG, uri.toString());
  }
  else if (value instanceof BNode) {
    BNode bNode = (BNode)value;
    xmlWriter.textElement(BNODE_TAG, bNode.getID());
  }
  else if (value instanceof Literal) {
    Literal literal = (Literal)value;
    IRI datatype = literal.getDatatype();
    if (Literals.isLanguageLiteral(literal)) {
      xmlWriter.setAttribute(LANGUAGE_ATT, literal.getLanguage().get());
      xmlWriter.textElement(PLAIN_LITERAL_TAG, literal.getLabel());
    }
    else {
      xmlWriter.setAttribute(DATATYPE_ATT, datatype.toString());
      xmlWriter.textElement(TYPED_LITERAL_TAG, literal.getLabel());
    }
  }
  else {
    throw new RDFHandlerException("Unknown value type: " + value.getClass());
  }
}

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

if (Literals.isLanguageLiteral(lit)) {

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

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

相关文章