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

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

Introduction

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

Prototype

String ntriplesString();

Source Link

Document

Return the term serialised as specified by the RDF-1.1 N-Triples Canonical form.

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 va  2  s  .  co 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:example.UserGuideTest.java

@Test
public void creating() throws Exception {
    BlankNode aliceBlankNode = factory.createBlankNode();
    IRI nameIri = factory.createIRI("http://example.com/name");
    Literal aliceLiteral = factory.createLiteral("Alice");
    Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);

    System.out.println(aliceBlankNode.ntriplesString());
    System.out.println(nameIri.ntriplesString());
    System.out.println(aliceLiteral.ntriplesString());

}