AGSailNamespaces.java

package com.franz.agsail.examples;

import com.franz.ag.*;
import com.knowledgereefsystems.agsail.*;

import info.aduna.iteration.CloseableIteration;

import java.io.File;

import org.openrdf.model.Namespace;
import org.openrdf.sail.*;

public class AGSailNamespaces {

    /**
     * Demonstrates basics of using Namespaces with a Sail.
     * 
     * @param args unused
     * @throws AllegroGraphException
     */
    public static void main(String[] args) throws SailException {
        
        // Specify the SAIL, including AllegroGraph server and store parameters
        Sail sail = new AllegroSail("localhost", 4567, false, "store", new File(AGPaths.TRIPLE_STORES), 0, 0, false, false);
        
        // Connect and open the store (create it if necessary)  
        sail.initialize();
        SailConnection sc = sail.getConnection();
       
        // Show default Namespaces for a connection
        CloseableIteration<? extends Namespace, SailException> iter1 = sc.getNamespaces();
        try {
            while (iter1.hasNext()) {
                System.out.println(iter1.next());
            }
        } catch (SailException e) {
            iter1.close();
        }
        
        // Get the namespace associated with each prefix
        System.out.println("Namespace for rdf: " + sc.getNamespace("rdf"));
        System.out.println("Namespace for rdfs: " + sc.getNamespace("rdfs"));
        System.out.println("Namespace for owl: " + sc.getNamespace("owl"));
        
        // Clear all Namespaces, including the defaults.
        sc.clearNamespaces();
        
        // Close the connection and shutdown the Sail
        sc.close();
        sail.shutDown();        
    }
    
}

Up | Next