Example usage for org.apache.commons.rdf.api Literal getLexicalForm

List of usage examples for org.apache.commons.rdf.api Literal getLexicalForm

Introduction

In this page you can find the example usage for org.apache.commons.rdf.api Literal getLexicalForm.

Prototype

String getLexicalForm();

Source Link

Document

The lexical form of this literal, represented by a <a href="http://www.unicode.org/versions/latest/">Unicode string</a>.

Usage

From source file:example.UserGuideTest.java

@Test
public void literal() throws Exception {
    Literal literal = factory.createLiteral("Hello world!");
    System.out.println(literal.ntriplesString());

    String lexical = literal.getLexicalForm();
    System.out.println(lexical);/*from  w ww  .  jav a2s  . c  om*/

    IRI datatype = literal.getDatatype();
    System.out.println(datatype.ntriplesString());

    IRI xsdDouble = factory.createIRI("http://www.w3.org/2001/XMLSchema#double");
    Literal literalDouble = factory.createLiteral("13.37", xsdDouble);
    System.out.println(literalDouble.ntriplesString());

    Literal literalDouble2 = factory.createLiteral("13.37", Types.XSD_DOUBLE);

    System.out.println(literal.getDatatype().equals(Types.XSD_STRING));

    Literal inSpanish = factory.createLiteral("Hola, Mundo!", "es");
    System.out.println(inSpanish.ntriplesString());
    System.out.println(inSpanish.getLexicalForm());
    System.out.println(inSpanish.getDatatype().ntriplesString());

    Optional<String> tag = inSpanish.getLanguageTag();
    if (tag.isPresent()) {
        System.out.println(tag.get());
    }

    System.out.println(literal.getLanguageTag().isPresent());
    System.out.println(literalDouble.getLanguageTag().isPresent());
}

From source file:org.apache.jena.commonsrdf.impl.JCR_Literal.java

@Override
public boolean equals(Object other) {
    if (other == this)
        return true;
    if (other == null)
        return false;
    if (!(other instanceof Literal))
        return false;
    Literal literal = (Literal) other;
    return getLexicalForm().equals(literal.getLexicalForm())
            && getLanguageTag().equals(literal.getLanguageTag()) && getDatatype().equals(literal.getDatatype());
}

From source file:org.apache.jena.commonsrdf.JenaCommonsRDF.java

/** Convert a CommonsRDF RDFTerm to a Jena Node.
 * If the RDFTerm was from Jena originally, return that original object else
 * create a copy using Jena objects. /*from  w  w  w.j  a v  a2  s.c om*/
 */
public static Node toJena(RDFTerm term) {
    if (term instanceof JenaNode)
        return ((JenaNode) term).getNode();

    if (term instanceof IRI)
        return NodeFactory.createURI(((IRI) term).getIRIString());

    if (term instanceof Literal) {
        Literal lit = (Literal) term;
        RDFDatatype dt = NodeFactory.getType(lit.getDatatype().getIRIString());
        String lang = lit.getLanguageTag().orElse("");
        return NodeFactory.createLiteral(lit.getLexicalForm(), lang, dt);
    }

    if (term instanceof BlankNode) {
        String id = ((BlankNode) term).uniqueReference();
        return NodeFactory.createBlankNode(id);
    }
    conversionError("Not a concrete RDF Term: " + term);
    return null;
}