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

AGNamespaces.java

package com.franz.ag.examples;

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

public class AGNamespaces {

    /**
     * Demonstrates basic use of namespaces in triples
     * 
     * @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 fresh triple-store for this example.
        AllegroGraph ts = ags.renew("namespaces", AGPaths.TRIPLE_STORES);
        
        // Add a triple without using namespaces
        ts.addStatement("<http://example.org/c>",
                "<http://example.org/p>", 
                "<http://example.org/d>");

        // Register your namespaces
        // Note that rdf, owl, and some others come pre-registered
        ts.registerNamespace("ex","http://example.org/");
        ts.registerNamespace("xsd", "http://www.w3.org/2001/XMLSchema#");
        
        // Create a URI using a namespace and show it
        URI a = (URI)ts.addPart("!ex:a");
        AGUtils.showURI(a);
        
        // Create a Literal using a namespace
        Literal lit = (Literal)ts.addPart("!\"42\"^^xsd:integer");
        
        // Add some triples to the store using namespaces
        ts.addStatement(a,"!ex:p", lit);
        ts.addStatement("!ex:b","!ex:p", "!ex:c");
        ts.addStatement("!ex:p","!rdf:type", "!owl:TransitiveProperty");
        
        // Retrieve some triples without using namespaces
        Cursor cc = ts.getStatements(false,null,"<http://example.org/p>",null);
        System.out.println("Triples with predicate http://example.org/p:");
        AGUtils.showTriples(cc);

        // Now using namespaces 
        cc = ts.getStatements(false,null,"!ex:p",null);
        System.out.println("Triples with predicate ex:p");
        AGUtils.showTriples(cc);

        // Close the triple store and disconnect from the server.
        ts.closeTripleStore();
        ags.disable();
    }

}

Up | Next

 

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