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

AGCreateURI.java

package com.franz.ag.examples;

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

public class AGCreateURI {

    /**
     * Demonstrates some basics of creating URIs.
     * 
     * @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("createuri", AGPaths.TRIPLE_STORES);
        
        // Create a few URIs from strings 
        URI subject = ts.createURI("http://example.org/Dog");  
        URI predicate = ts.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");  
        URI object = ts.createURI("http://www.w3.org/2002/07/owl#Class");
        
        AGUtils.showURI(subject);
        AGUtils.showURI(predicate);
        AGUtils.showURI(object);

        // Add a triple to the store (and add each URI to the store)
        ts.addStatement(subject, predicate, object);
        
        // You can also create a URI and add it to the store directly
        URI u = (URI)ts.addURI("http://www.w3.org/2002/07/owl#Class");
        AGUtils.showURI(u);
        
        // Or use the more generic addPart method (using N-Triples format)
        URI v = (URI)ts.addPart("<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>");
        AGUtils.showURI(v);

        // 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 ]