franz inc logo  
  download learning center franz inc search franz inc resources franz inc          

allegrograph
racer
tbc
services
support
  Learning Center
  Documentation
  Updates
     Info
  FAQ
about

RSS Feeds

AllegroServe at opensource.franz.com

AGCreateLiteral.java

package com.franz.ag.examples;

import com.franz.ag.*;
import org.openrdf.model.Literal;
import org.openrdf.model.URI;

public class AGCreateLiteral {

    /**
     * Demonstrates some basics of creating Literals.
     * 
     * @param args unused
     * @throws AllegroGraphException 
     */
    public static void main(String[] args) throws AllegroGraphException {
        // Connect to server, which must already be running.
        AllegroGraphConnection ags = new AllegroGraphConnection();
        try {
            ags.enable();
        } catch (Exception e) {
            throw new AllegroGraphException("Server connection problem", e);
        }
        // Create a fresh triple-store for this example.
        AllegroGraph ts = ags.renew("createliteral", AGPaths.TRIPLE_STORES);
        
        // Create a few Literals from various types 
        Literal lit1 = ts.createLiteral("Fido");
        Literal lit2 = ts.createLiteral(true);
        Literal lit3 = ts.createLiteral(123);
        Literal lit4 = ts.createLiteral(123.0);
        Literal lit5 = ts.createLiteral((long)123);
        Literal lit6 = ts.createLiteral((double)123);
        
        AGUtils.showLiteral(lit1);
        AGUtils.showLiteral(lit2);
        AGUtils.showLiteral(lit3);
        AGUtils.showLiteral(lit4);
        AGUtils.showLiteral(lit5);
        AGUtils.showLiteral(lit6);

        // Create a few URIs from strings 
        URI subject = ts.createURI("http://example.org/fido");  
        URI predicate = ts.createURI("http://example.org/name");

        // Add a triple to the store (also adds URIs and a Literal)
        ts.addStatement(subject, predicate, lit1);
        
        // You can also create Literals and add them to the store directly
        Literal cat = ts.addLiteral("chat","fr"); // language is french
        AGUtils.showLiteral(cat);
        URI dt = ts.createURI("http://www.w3.org/2001/XMLSchema#int");
        Literal lit7 = ts.addLiteral("123", dt); // datatype is int
        AGUtils.showLiteral(lit7);
        
        // Close the store and disconnect from the server.
        ts.closeTripleStore();
        ags.disable();
    }
}

Up | Next

 

© 2008 Franz Inc - Privacy Statement
[ Consulting Services | Franz | TopQuadrant | Racer Systems ]