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

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

Introduction

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

Prototype

IRI getDatatype();

Source Link

Document

The IRI identifying the datatype that determines how the lexical form maps to a literal value.

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 w  w.j a  v a2  s . c o  m*/

    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  av a  2s .co  m*/
 */
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;
}

From source file:org.semanticweb.owlapi.io.RDFLiteral.java

@Override
public boolean equals(@Nullable Object obj) {
    if (obj == this) {
        return true;
    }/*from  w  w  w .j ava2s.c o  m*/
    if (obj instanceof RDFLiteral) {
        RDFLiteral other = (RDFLiteral) obj;
        if (!lexicalValue.equals(other.lexicalValue)) {
            return false;
        }
        if (!lang.equals(other.lang)) {
            return false;
        }
        return datatype.equals(other.datatype);
    }
    if (obj instanceof Literal) {
        // Note: This also works on RDFLiteral
        // but is slightly more expensive as it must call the
        // getter methods when accessing obj.
        //
        // To ensure future compatibility, the Commons RDF getter
        // methods are also called on this rather than using the fields.
        Literal literal = (Literal) obj;
        if (!getLexicalForm().equals(((Literal) obj).getLexicalForm())) {
            return false;
        }
        if (!getLanguageTag().equals(literal.getLanguageTag())) {
            return false;
        }
        return getDatatype().equals(literal.getDatatype());
    }
    return false;
}

From source file:org.semanticweb.owlapi6.io.RDFLiteral.java

@Override
public boolean equals(@Nullable Object obj) {
    if (obj == this) {
        return true;
    }/*from w  w w.j  a v  a2  s.  co  m*/
    if (obj instanceof RDFLiteral) {
        RDFLiteral other = (RDFLiteral) obj;
        if (!lexicalValue.equals(other.lexicalValue)) {
            return false;
        }
        if (!lang.toLowerCase(Locale.ROOT).equals(other.lang.toLowerCase(Locale.ROOT))) {
            return false;
        }
        return datatype.equals(other.datatype);
    }
    if (obj instanceof Literal) {
        // Note: This also works on RDFLiteral
        // but is slightly more expensive as it must call the
        // getter methods when accessing obj.
        //
        // To ensure future compatibility, the Commons RDF getter
        // methods are also called on this rather than using the fields.
        Literal literal = (Literal) obj;
        if (!getLexicalForm().equals(((Literal) obj).getLexicalForm())) {
            return false;
        }
        Optional<String> thisTag = getLanguageTag();
        Optional<String> thatTag = literal.getLanguageTag();
        if (thisTag.isPresent() != thatTag.isPresent()) {
            return false;
        }
        if (thisTag.isPresent() && thatTag.isPresent() && !thisTag.get().toLowerCase(Locale.ROOT)
                .equalsIgnoreCase(thatTag.get().toLowerCase(Locale.ROOT))) {
            return false;
        }
        return getDatatype().equals(literal.getDatatype());
    }
    return false;
}