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

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

Introduction

In this page you can find the example usage for org.apache.commons.rdf.api RDFTerm 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 triple() throws Exception {
    BlankNodeOrIRI subject = factory.createBlankNode();
    IRI predicate = factory.createIRI("http://example.com/says");
    RDFTerm object = factory.createLiteral("Hello");
    Triple triple = factory.createTriple(subject, predicate, object);

    BlankNodeOrIRI subj = triple.getSubject();
    System.out.println(subj.ntriplesString());

    IRI pred = triple.getPredicate();/*from   w  ww  .j a  v  a2  s.c o m*/
    System.out.println(pred.getIRIString());

    RDFTerm obj = triple.getObject();
    System.out.println(obj.ntriplesString());

    if (subj instanceof IRI) {
        String s = ((IRI) subj).getIRIString();
        System.out.println(s);
    }
    // ..
    if (obj instanceof Literal) {
        IRI type = ((Literal) obj).getDatatype();
        System.out.println(type);
    }

    System.out.println(triple.equals(factory.createTriple(subj, pred, obj)));
}